// JavaScript Document
//łśćłżź
var DebugQueryMode=true; //Show Alerts
var jDebugMode=true;
//var IE=false;


var GlobIE8=false;
if(jQuery.browser.msie && jQuery.browser.version == 8){ GlobIE8=true; }


/* ================================================================================== */
/* =============================== jquery.ready [START] ============================= */
/* ================================================================================== */
/* =============================== .jAjax [START] =================================== */
// Important, required function getScrollXY;
var Global_jAjaxPerm=true;
function jAjax(){
	try{
		if(Global_jAjaxPerm==false){ self.setTimeout("jAjax('"+'test'+"')", 300); }
		elements=$JQ('.jAjax');
		
		var glob=0;
		for(i=0;i<elements.length;i++){
			c_href='';
			single=$JQ(elements).eq(i).find('.jAjax_link');
			//alert(single.length);
			if(single.length==1){ c_href=$JQ(single).eq(0).attr('href'); }
			if(c_href!='' && c_href !='#'){
				$JQ(elements).eq(i).attr('class','.jAjaxDone');
				
				$JQ(elements).eq(i).bind("ajaxSend", function(){
					Global_jAjaxPerm=false;
					$JQ(this).unbind('ajaxSend');
					$JQ(this).hide();
					
				}).bind("ajaxComplete", function(){
					$JQ(this).unbind('ajaxError');
					$JQ(this).unbind('ajaxComplete');
					$JQ(this).show(800, function(){ Global_jAjaxPerm=true; });					
					
				}).bind("ajaxError", function(){
					$JQ(this).unbind('ajaxError');
					$JQ(this).unbind('ajaxComplete');
					$JQ(this).html('<div class="loading"><img src="graph/shared/empty.gif" alt="" width="18" height="18" /></div>');
					$JQ(this).show(800, function(){ Global_jAjaxPerm=true; });
				});
				Global_jAjaxPerm=false;
				$JQ(elements).eq(i).load(c_href);
				self.setTimeout("jAjax('"+'test'+"')", 300);
				return false;
			}//if
			
		}//for
	}catch(err){ if(DebugQueryMode==true){ alert(' jAjax: '+err); }}
}


function jAjaxSliderSet(){
	try{
		var elements = $JQ('a');
		for(i=0;i<=elements.length;i++){
			if($JQ(elements).eq(i).attr('rev')=='jslider'){
				$JQ(elements).eq(i).click(function () {
					var new_href=$JQ(this).attr('href');
					if(new_href=='' || new_href=='#'){ return false; }
					//var new_href='https://myhealthangel01.worldsecuresystems.com/mini/help/programs_faq/my_weight.html';
					//cmsSlideShow(new_href);
					jAjaxSlider(new_href);
					return false;
				});
				
				$JQ(elements).eq(i).bind("ajaxError", function(){
					//$JQ(this).unbind('ajaxError');
					//$JQ(this).unbind('ajaxComplete');
					
					$JQ('#layer_slider').html('<a class="layer_slider_close" href="#"><img src="graph/shared/empty.gif" alt="" /></a><div class="loading_error" style="display:none">Unable to load page</div>');
					$JQ(".layer_slider_close").click(function () { 
						$JQ('#layer_main').remove();
						return false;
					});
					$JQ('#layer_slider .loading_error').show(100);
					
					//$JQ('#layer_opacity').animate({opacity:0}, 4000,"swing",function() {  });  
					//$JQ('#layer_slider').animate({opacity:0.9}, 2000,"linear",function() {  $JQ('#layer_main').remove(); });  
					return true;
				}).bind("ajaxComplete", function(){
					//$JQ(this).unbind('ajaxError');
					//$JQ(this).unbind('ajaxComplete');
					$JQ('#layer_slider .layer_slider_close').css('opacity',0);	
					$JQ('#layer_slider .layer_slider_close').animate({opacity:1}, 800,"swing");
					return false;
				});
				
				
			}
		}	
		
		
			
	}catch(err){ if(DebugQueryMode==true){ alert(' jAjaxSliderSet: '+err); }}
}

function jAjaxSlider(c_href){
	try{
		var elements=$JQ('#layer_main');
		if(elements.length>0){ return false; }
		$JQ('body').prepend('<div class="layer_main" id="layer_main"></div>');
		$JQ('#layer_main').append('<div class="layer_opacity" id="layer_opacity"></div>');
		$JQ('#layer_main').append('<div class="layer_slider" id="layer_slider" align="center"><a class="layer_slider_close" href="#"><img src="graph/shared/empty.gif" alt="" /></a></div>');
		
		$JQ('#layer_slider').append('<div class="layer_slider_ajax"><div class="jAjax"><a class="jAjax_link" href="'+c_href+'"></a></div></div>');
		
		$JQ('#layer_slider .layer_slider_close').css('opacity',0);
		$JQ('#layer_main').css('height', $JQ('body').attr('scrollHeight'));
		$JQ('#layer_opacity').css('height', $JQ('body').attr('scrollHeight'));
		
		var scrolls=getScrollXY();
		var c_top=scrolls[1]+150;
		$JQ('#layer_slider').animate({top:c_top}, 60, "linear");
		
		$JQ(".layer_opacity").click(function () { 
		  	$JQ('#layer_main').remove();
		  	return false;
		});
		
		$JQ(".layer_slider_close").click(function () { 
		  	$JQ('#layer_main').remove();
		  	return false;
		});
		
		$JQ('#layer_opacity').css('opacity',0);
		$JQ('#layer_main').show();
		jAjaxSliderPosition();
		$JQ('#layer_opacity').animate({opacity:0.6}, 1000,"swing",function() { jAjax();  });
		
		
		//$JQ('#layer_main').show(1000, );
		
		
		
	}catch(err){ if(DebugQueryMode==true){ alert(' jAjaxSlider: '+err); }}
}

function jAjaxSliderPosition(){
	try{
		var elements=$JQ('#layer_main');
		if(elements.length!=1){ return false; }
		
		c_bodywidth=parseInt($JQ('body').attr('offsetWidth'));
		if(c_bodywidth<1000){ c_bodywidth=1000; }
		
		$JQ('#layer_main').css('width',c_bodywidth);
		$JQ('#layer_opacity').css('width',c_bodywidth);
		
		if(parseInt($JQ('.layer_slider_ajax').attr('offsetHeight'))>=430){ 
			$JQ('.layer_slider_ajax').css('padding-right','18px');
		}
		
		var c_left=parseInt((c_bodywidth/2)- ($JQ('#layer_slider').attr('offsetWidth')/2 ));
		//var scrolls=getScrollXY();
		//var c_top=scrolls[1]+150;
		
		//$JQ('#layer_slider').css('left',c_left);
		//$JQ('#layer_slider').css('top',c_top);
		$JQ('#layer_slider').animate({left:c_left}, 60, "linear");
		//$JQ('#layer_slider').animate({top:c_top}, 60, "linear");
		self.setTimeout("jAjaxSliderPosition('"+'test'+"')", 400);
		
	}catch(err){ if(DebugQueryMode==true){ alert('jAjaxSliderPosition: '+err); }}
}
/* =============================== .jAjax [END] ===================================== */
/* =============================== .nForm [START] =================================== */
function jnFormRadioClick(This){
	try{
		ID=$JQ(This).attr('id');
		var unique_name='';
		for(i=0;i<glob_nFormRadio.length;i++){
			if(glob_nFormRadio[i].idgraph==ID){
				//$JQ('#'+glob_nFormRadio[i].idgraph).attr('class','nform_check2');
				//$JQ('#'+glob_nFormRadio[i].idradio).attr('checked','checked');
				unique_name=glob_nFormRadio[i].name;
				break;				
			}
		}
		if(unique_name==''){ return false; }
		for(i=0;i<glob_nFormRadio.length;i++){
			if(glob_nFormRadio[i].name==unique_name){
				$JQ('#'+glob_nFormRadio[i].idgraph).attr('class','nform_check1');
				if(glob_nFormRadio[i].idgraph==ID){
					$JQ('#'+glob_nFormRadio[i].idgraph).attr('class','nform_check2');
					$JQ('#'+glob_nFormRadio[i].idradio).attr('checked','checked');
					$JQ('#'+glob_nFormRadio[i].idradio).change(); /*Added*/
				}
			}
		}//for
	}catch(err){ if(DebugQueryMode==true){ alert('jnFormRadioClick: '+err); }}
}

var glob_nFormRadio=new Array();

function jnFormRadioSet(IDarray){
	try{
		if(!IDarray || IDarray.length==0){ return false; }
		var unique_name='';
		for(i=0;i<IDarray.length;i++){
			c_id=IDarray[i];
			if(c_id.slice(0,12)=='nform_radio_'){
				c_idradio=c_id.slice(12,c_id.length);
				//alert(glob_nFormRadio.length)
				if(unique_name==''){ 
					unique_name=c_id;
					if(glob_nFormRadio.length){
						for(k=0;k<glob_nFormRadio.length;k++){
							if(glob_nFormRadio[k].name==unique_name){ return false; }
						}
					}
				}
				var air={}
				air.name=unique_name;
				air.idgraph=c_id;
				air.idradio=c_idradio;
				c_count=glob_nFormRadio.length
				
				if($JQ('#'+air.idradio).attr('checked')==true){
					$JQ('#'+air.idgraph).attr('class','nform_check2'); //set at start
				}
				
				if(!c_count){ c_count=0; }
				glob_nFormRadio[c_count]=air;
				
				$JQ('#'+c_id).click(function () { 
				  	jnFormRadioClick(this);
				});
						
			}
		}//for
	}catch(err){ if(DebugQueryMode==true){ alert('jnFormRadioSet: '+err); }}
}
/* =============================== .nForm [END] ===================================== */
/* =============================== .jReboxA [START] ================================= */
function jReboxA_ClickA0(event){
	try{
		var ID=event.data.ID;
		var Duration=event.data.Duration;
		var Num=event.data.Num;
		var LINKindex=event.data.LINKindex;
		
		
		var elements = $JQ('#'+ID+' .li0');
		var c_ul01;
		
		for(var i=0;i<elements.length;i++){
			c_ul01=$JQ(elements).eq(i).find('.ul01').eq(0);
			if(LINKindex==i){
				c_height=$JQ(c_ul01).height();
				if(c_height==0){
					$JQ(c_ul01).css('height','auto');
					c_height=$JQ(c_ul01).height();
					$JQ(c_ul01).css('height',0);
					$JQ(c_ul01).animate({ height:c_height },{easing:"easeInOutSine",duration:Duration, queue:false, complete:function(){    }});
				}
			}else{
			
				//c_height=$JQ(c_ul01).height();
				//if(c_height>0){ alert(c_height+' - '+i); }
				$JQ(c_ul01).animate({ height:0 },{easing:"easeInOutSine",duration:Duration, queue:false, complete:function(){    }});
			}
		}
		return false;
	}catch(err){ if(jDebugMode==true){ alert('jReboxA: ' + err); }}
}

function jReboxA(ID, Duration, Num){
	try{
		if(!ID || ID==''){ return false; } 
		if(!Duration || Duration==''){ Duration=300; }
		if(!Num || Num==''){ Num==-1; } 
		
		var elements = $JQ('#'+ID+' .li0');
		var c_ul01;
		var c_height=0;
		for(var i=0;i<elements.length;i++){
			c_ul01=$JQ(elements).eq(i).find('.ul01').eq(0);
			$JQ(c_ul01).css('height','auto');
			c_height=$JQ(c_ul01).height();
			$JQ(c_ul01).css('height',0);
			if((Num>=0) && (Num==i)){ $JQ(c_ul01).animate({ height:c_height },{easing:"easeInOutSine",duration:Duration, queue:false, complete:function(){    }}); }
		}
		
		var elements = $JQ('#'+ID+' .a0');
		for(var i=0;i<elements.length;i++){
			$JQ(elements).eq(i).bind("click", {ID:ID, Duration:Duration, Num:Num, LINKindex:i}, jReboxA_ClickA0);
		}
	}catch(err){ if(jDebugMode==true){ alert('jReboxA: ' + err); }}
}
/* =============================== .jReboxA [END] =================================== */
/* =============================== .jSwfobjectFinder [START] ======================== */
//Required swfobject
function jSwfobjectFinder(Data){
	try{//[Last Update: 22.listopada.2010]
		if(!Data.Relpart || Data.Relpart==''){ return false; }
		if(!Data.Duration || Data.Duration==''){ Data.Duration=1000; }
		if(!Data.Timer || Data.Timer==''){ Data.Timer=false; }
		
		$JQ('a').each(function(index){
			var c_rel=$JQ(this).attr('rel');
			if(c_rel.length>=Data.Relpart.length){
				if(c_rel.indexOf(Data.Relpart)==0){
					$JQ(this).data('jSwfobjectFinder_status', $JQ(this).data('jSwfobjectFinder_status') ? $JQ(this).data('jSwfobjectFinder_status') : 'start' );
					if($JQ(this).data('jSwfobjectFinder_status')!='start'){ return true; } 
					//$JQ(this).lightBox();
					//alert(c_rel);
					$JQ(this).bind("click", {This:$JQ(this),Data:Data}, function(event){
						var This=event.data.This;
						var c_rel=$JQ(This).attr('rel');
						var c_rev=$JQ(This).attr('rev');
						var c_id=$JQ(This).attr('id');
						var c_href=$JQ(This).attr('href');
						var c_title=$JQ(This).attr('title');
						var c_class=$JQ(This).attr('class');
						if(!c_href || c_href=='' || c_href=='#'){ return false; }
						if($JQ(This).find('img').length==0){return false; }
						var c_imgwidth=$JQ(This).find('img').eq(0).width();
						var c_imgheight=$JQ(This).find('img').eq(0).height();
						var c_imgsrc=$JQ(This).find('img').eq(0).attr('src')
						var c_imgalt=$JQ(This).find('img').eq(0).attr('alt')
						if($JQ(this).parent().hasClass('swfobject')!=true){ return false; }
						if(!c_imgwidth || c_imgwidth==''){ return false; }
						if(!c_imgheight || c_imgheight==''){ return false; }
						if(!c_id || c_id==''){ return false; }
						if(!c_rev || c_rev==''){ c_rev='bc_swf/Corona_Skin_2'; }
						$JQ(this).parent().css({width:c_imgwidth, height:c_imgheight});
						
						$JQ(this).parent().data('jSwfobjectFinder_link-id',c_id);
						$JQ(this).parent().data('jSwfobjectFinder_link-class',c_class);
						$JQ(this).parent().data('jSwfobjectFinder_link-rel',c_rel);
						$JQ(this).parent().data('jSwfobjectFinder_link-rev',c_rev);
						$JQ(this).parent().data('jSwfobjectFinder_link-href',c_href);
						$JQ(this).parent().data('jSwfobjectFinder_link-title',c_title);
						$JQ(this).parent().data('jSwfobjectFinder_img-width',c_imgwidth);
						$JQ(this).parent().data('jSwfobjectFinder_img-height',c_imgheight);
						$JQ(this).parent().data('jSwfobjectFinder_img-src',c_imgsrc);
						$JQ(this).parent().data('jSwfobjectFinder_img-alt',c_imgalt);
						
						if((c_href.indexOf('#')==0) && (c_href.length>1)){ c_href=c_href.slice(1,c_href.length) }
						var flashvars = {
							MM_ComponentVersion: 1,
						  	skinName: c_rev, //"bc_swf/Corona_Skin_2",
						  	streamName: c_href, //"graph/flash/Final_E",
						  	autoPlay: "true",
						  	autoRewind: "false"
						};
						var attributes = { id:'parent-'+c_id };
						var params = {};
						params.wmode = "transparent"; //Added
						
						$JQ(this).wrap('<div id=parent-"'+c_id+'" class="swfobject_wrapper"></div>');
						$JQ(this).parent().parent().append('<a class="swfobject_link jitemhover" href="#"></a>');
						$JQ(this).parent().parent().find('.swfobject_link').eq(0).bind("click", {IDattributes:'parent-'+c_id,Data:Data}, function(event){
							swfobject.removeSWF(event.data.IDattributes);
							
							var c_id=$JQ(this).parent().data('jSwfobjectFinder_link-id');
							var c_class=$JQ(this).parent().data('jSwfobjectFinder_link-class');
							var c_rel=$JQ(this).parent().data('jSwfobjectFinder_link-rel');
							var c_rev=$JQ(this).parent().data('jSwfobjectFinder_link-rev');
							var c_href=$JQ(this).parent().data('jSwfobjectFinder_link-href');
							var c_title=$JQ(this).parent().data('jSwfobjectFinder_link-title');
							var c_imgwidth=$JQ(this).parent().data('jSwfobjectFinder_img-width');
							var c_imgheight=$JQ(this).parent().data('jSwfobjectFinder_img-height');
							var c_imgsrc=$JQ(this).parent().data('jSwfobjectFinder_img-src');
							var c_imgalt=$JQ(this).parent().data('jSwfobjectFinder_img-alt');
							
							//$JQ(this).parent().css({'height':100});
							$JQ(this).parent().find('.swfobject_wrapper').remove();
							$JQ(this).parent().append('<a id="'+c_id+'" title="'+c_title+'" rel="'+c_rel+'" rev="'+c_rev+'" href="'+c_href+'"><img src="'+c_imgsrc+'" alt="" width="'+c_imgwidth+'" height="'+c_imgheight+'"></a>');
							$JQ('#'+c_id).bind("click", {}, function(){ return false; })
							$JQ(this).remove();
							//<a id="swfobject_finale" title="Beautytek Video" rel="swfobject" rev="bc_swf/Corona_Skin_2" href="#graph/flash/Final_E"><img src="graph/images/beautytek_vidimg.jpg" alt="" width="360" height="264"></a>
							return false; 
							
						});//bind*/
						//swfobject.removeSWF('myFlashContent'); return false; 
						swfobject.embedSWF("FLVPlayer_Progressive.swf", c_id, c_imgwidth, c_imgheight, "9.0.0", "bc_swf/expressInstall.swf", flashvars, params, attributes);
						

						return false; 
					});//bind
					$JQ(this).data('jSwfobjectFinder_status','done');
				}
			}
		});
		
		if(Data.Timer==true){
			$JQ(this).oneTime(Data.Duration,function(i){ jSwfobjectFinder(Data); });
		}
		
	}catch(err){ if(jDebugMode==true){ alert('jSwfobjectFinder: ' + err); }}
}
/* =============================== .jSwfobjectFinder [END] ========================== */
/* =============================== .single [START] ================================== */
(function($JQ){
	var _sleeptimer;
	$JQ.sleep = function( time2sleep, callback )
	{
		$JQ.sleep._sleeptimer = time2sleep;
		$JQ.sleep._cback = callback;
		$JQ.sleep.timer = setInterval('$JQ.sleep.count()', 1000);
	}
	$JQ.extend ($JQ.sleep, {
		current_i : 1,
		_sleeptimer : 0,
		_cback : null,
		timer : null,
		count : function()
		{
			if ( $JQ.sleep.current_i === $JQ.sleep._sleeptimer )
			{
				clearInterval($JQ.sleep.timer);
				$JQ.sleep._cback.call(this);
			}
			$JQ.sleep.current_i++;
		}
	});
})(jQuery);

function jItemHoverAnimation(Name, Duration, Timer){ 
	try{//[Last Update: 09.listopada.2010]
		if(!Name || Name=='' || Name.length<2){ return false; }
		if(!Duration || Duration==''){ Duration=300; }
		if(!Timer || Timer==''){ Timer=false; }

		switch(Name.charAt(0)){
			case '.': break;
			case '#': break;
			default: Name='#'+Name;
		}
		
		$JQ(Name).each(function(index){
			$JQ(this).data('jItemHoverAnimation_status', $JQ(this).data('jItemHoverAnimation_status') ? $JQ(this).data('jItemHoverAnimation_status') : 'start' );
			if($JQ(this).data('jItemHoverAnimation_status')!='start'){ return true; }
			else{ $JQ(this).data('jItemHoverAnimation_status','end'); }
			if($JQ(this).find('*').length==0){
				$JQ('<img src="graph/shared/empty.gif" alt="" />').appendTo(this);
			}
			
			$JQ(this).find('img').css('opacity',0);
			$JQ(this).find('img').css('visibility','visible');
			$JQ(this).find('input').css('opacity',0);
			$JQ(this).find('input').css('visibility','visible');
			$JQ(this).hover(function(){
				/*$JQ(this).find('img').eq(0).stop(true,false).animate({ opacity:1 },{easing:"swing",duration:Duration, queue:false, complete:function(){    }});
				$JQ(this).find('input').eq(0).stop(true,false).animate({ opacity:1 },{easing:"swing",duration:Duration, queue:false, complete:function(){    }});*/
				$JQ(this).find('img').eq(0).animate({ opacity:1 },{easing:"swing",duration:Duration, queue:false, complete:function(){    }});
				$JQ(this).find('input').eq(0).animate({ opacity:1 },{easing:"swing",duration:Duration, queue:false, complete:function(){    }});
			},function(){
				$JQ(this).find('img').eq(0).animate({ opacity:0 },{easing:"swing",duration:Duration, queue:false, complete:function(){    }});
				$JQ(this).find('input').eq(0).animate({ opacity:0 },{easing:"swing",duration:Duration, queue:false, complete:function(){    }});
				/*$JQ(this).find('img').eq(0).stop(true,false).animate({ opacity:0 },{easing:"swing",duration:Duration, queue:false, complete:function(){    }});
				$JQ(this).find('input').eq(0).stop(true,false).animate({ opacity:0 },{easing:"swing",duration:Duration, queue:false, complete:function(){    }});*/
			});//hover
		});
		
		if(Timer==true){
			$JQ(this).oneTime(1000,function(i){ jItemHoverAnimation(Name, Duration, Timer); });
		}
		
	}catch(err){ if(jDebugMode==true){ alert('jItemHoverAnimation: ' + err); }}
}

function jMinHeight(Name, Height){
	try{
		if(!Name || Name=='' || Name.length<2){ return false; }
		if(!Height || Height=='' || Height<=0){ return false; }
		
		switch(Name.charAt(0)){
			case '.': break;
			case '#': break;
			default: Name='#'+Name;
		}
		
		var elements=$(Name);
		var c_height;
		
		for(var i=0; i<elements.length;i++){
			//c_height=parseInt($(Name).eq(i).css('height'));
			c_height=parseInt($(Name).eq(i).height()); //IE6 Path;
			if(c_height<Height){ $(Name).eq(i).css('height',Height); }
		}
		return true;
	}catch(err){ if(jDebugMode==true){ alert('jMinHeight: ' + err); }}
}




$JQ(document).ready(function(){
	//jTopAnimation();
	//jMenuAnimation('menul');
});
/* =============================== .single [END] ==================================== */
/* =============================== .Disabled [START] ================================ */
/*
function jAjaxClearboxCleaner(){
	try{
		var elements=$JQ('.jAjaxDone').find('a');
		for(i=0;i<elements.length;i++){
			c_rev=$JQ(elements).eq(i).attr('rev');
			if(c_rev.toLowerCase()=='clearbox'){
				$JQ(elements).eq(i).click(function () { return false; });
			}
		}
		
		setBlur();
		
	}catch(err){ if(DebugQueryMode==true){ alert('jAjaxClearboxCleaner: '+err); }}
}
*/
/* =============================== .Disabled [END] ================================== */
/* ================================================================================== */
/* =============================== jquery.ready [END] =============================== */
/* ================================================================================== */

