// JavaScript Document
//łśćłżź
var DebugQueryMode=false; //Show Alerts
//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] ===================================== */
/* =============================== .SliderMVA [START] =============================== */
function jSliderMVA_Set(event){
	try{
		var IDlink=event.data.IDlink;
		var IDslide=event.data.IDslide;
		
		if(jQuery.data(document.body,IDslide).PERM!=true){ return false; }
		else{ jQuery.data(document.body,IDslide,{PERM:false}); }
		
		
		$JQ('#'+IDlink+' li').attr('class','');
		$JQ('#'+IDlink+' li').eq(event.data.LINKindex).attr('class','active');
		var c_fullwidth=parseInt($JQ('#'+IDslide+' ul').css('width'));
		var c_width=parseInt($JQ('#'+IDslide+' li').eq(0).attr('offsetWidth'));
		var c_left=parseInt($JQ('#'+IDslide+' ul').css('left'));
		
		var c_newlt=event.data.LINKindex*c_width*(-1);
		var c_newheight=$JQ('#'+IDslide+' li').eq(event.data.LINKindex).attr('offsetHeight');
		//$JQ('#'+IDslide+' ul').animate({ left:c_newlt },{easing:"easeOutElastic",duration:1500, queue:false, complete:function(){ jQuery.data(document.body,IDslide,{PERM:true});  }}); 
		//$JQ('#'+IDslide).animate({ height:c_newheight },{easing:"swing",duration:750, queue:false, complete:function(){     }}); //setHeight
		
		$JQ('#'+IDslide+' ul').animate({ left:c_newlt },{easing:"easeInOutExpo",duration:1000, queue:false, complete:function(){ jQuery.data(document.body,IDslide,{PERM:true});  }}); 
		$JQ('#'+IDslide).animate({ height:c_newheight },{easing:"swing",duration:750, queue:false, complete:function(){     }}); //setHeight
		//easeInOutExpo
		//alert(c_active);
		return false;
	}catch(err){ if(jDebugMode==true){ alert('jSliderMVA_Set: ' + err); }}
}

function jSliderMVA_Direction(event){
	try{
		var IDlink=event.data.IDlink;
		var c_direction=event.data.Direction;
		
		var elements=$JQ('#'+IDlink+' li');
		var c_active=-1;
		
		for(var i=0;i<elements.length;i++){
			if($JQ(elements).eq(i).attr('class')=='active'){  c_active=i; break; }
		}
		if(c_active==-1){ alert('MVA Error: #50'); return false;  }
		
		switch(c_direction) {
			case 'next': if(c_active<elements.length-1){ c_active+=1; }else{ c_active=0; }  break;
			case 'prev': if(c_active>=1){ c_active-=1; }else{ c_active=elements.length-1; }  break;
			default: return false;
		}
		//alert('ter:'+c_active+' - direction:'+c_direction); 
		if(c_active>=0 && c_active<elements.length){ $JQ(elements).eq(c_active).click(); }
		return false;
	}catch(err){ if(jDebugMode==true){ alert('jSliderMVA_Direction: ' + err); }}
}
			
			
function jSliderMVA(IDprev, IDnext, IDlink, IDslide, Num){
	try{ 
		if(!IDprev || IDprev==''){ return false; }
		if(!IDnext || IDnext==''){ return false; }
		if(!IDlink || IDlink==''){ return false; }
		if(!IDslide || IDslide==''){ return false; }
		if(!Num || Num==''){ Num=-1; }else{ Num=parseInt(Num); }
		
		//alert('test');
		//
		var c_total=$JQ('#'+IDslide+' li').length; //setWidth
		var c_width=parseInt($JQ('#'+IDslide).find('li').eq(0).attr('offsetWidth'));
		var c_height=parseInt($JQ('#'+IDslide).find('li').eq(0).attr('offsetHeight'));
		if(c_total<=0 || c_width<=0){ return false; }

		$JQ('#'+IDslide).animate({ height:c_height },{easing:"swing",duration:750, queue:false, complete:function(){     }}); //setHeight
		$JQ('#'+IDslide+' ul').css('width',parseInt(c_total*c_width));
		$JQ('#'+IDslide+' ul').css('left',0);
		
		
		
		var elements=$JQ('#'+IDlink+' li');
		$JQ(elements).attr('class','');
		if((Num>0 && Num<elements.length) && (c_total==elements.length)){ 
			$JQ(elements).eq(Num).attr('class','active');
			$JQ('#'+IDslide+' ul').css('left',parseInt((-1)*Num*c_width));
			
		}else{ $JQ(elements).eq(0).attr('class','active'); }
		
		jQuery.data(document.body,IDslide,{PERM:true});
		for(var i=0; i<elements.length; i++){
			$JQ(elements).eq(i).bind("click", {IDprev:IDprev, IDnext:IDnext, IDlink:IDlink, IDslide:IDslide, LINKindex:i}, jSliderMVA_Set);
		}
		
		$JQ('#'+IDprev).bind("click", {IDprev:IDprev, IDnext:IDnext, IDlink:IDlink, IDslide:IDslide, Direction:'prev'}, jSliderMVA_Direction);
		$JQ('#'+IDnext).bind("click", {IDprev:IDprev, IDnext:IDnext, IDlink:IDlink, IDslide:IDslide, Direction:'next'}, jSliderMVA_Direction);
		
		jItemHoverAnimation(IDprev);
		jItemHoverAnimation(IDnext);
		//alert($JQ('#'+IDslide+' ul').css('width'));
		//for(var i=0;i<elements.length;i++){
			
		//}
		
		
	}catch(err){ if(jDebugMode==true){ alert('jSliderMVA: ' + err); }}
}

var GlobalSliderMVA_TimerPerm=false;
function jSliderMVA_TimerSet(IDprev, IDnext, IDlink, Duration){
	try{
		if(!IDprev || IDprev==''){ return false; }
		if(!IDnext || IDnext==''){ return false; }
		if(!IDlink || IDlink==''){ return false; }
		if(!Duration || Duration==''){ return false; }
		if(Duration<=0){ return false; }
	
		$JQ('#'+IDprev).bind("mouseover", {IDprev:IDprev, IDnext:IDnext, Duration:Duration}, jSliderMVA_TimerOver);
		$JQ('#'+IDprev).bind("mouseout", {IDprev:IDprev, IDnext:IDnext, Duration:Duration}, jSliderMVA_TimerOut);
		
		$JQ('#'+IDnext).bind("mouseover", {IDprev:IDprev, IDnext:IDnext, Duration:Duration}, jSliderMVA_TimerOver);
		$JQ('#'+IDnext).bind("mouseout", {IDprev:IDprev, IDnext:IDnext, Duration:Duration}, jSliderMVA_TimerOut);
		
		$JQ('#'+IDlink).find('a').bind("mouseover", {IDprev:IDprev, IDnext:IDnext, Duration:Duration}, jSliderMVA_TimerOver);
		$JQ('#'+IDlink).find('a').bind("mouseout", {IDprev:IDprev, IDnext:IDnext, Duration:Duration}, jSliderMVA_TimerOut);
		
		GlobalSliderMVA_TimerPerm=true;
		jSliderMVA_Timer(IDprev, IDnext, Duration, 'firstrun');
		return true;
	}catch(err){ if(jDebugMode==true){ alert('jSliderMVA_TimerSet: ' + err); }}
}

function jSliderMVA_TimerOver(event){
	try{
		GlobalSliderMVA_TimerPerm=false;
	}catch(err){ if(jDebugMode==true){ alert('jSliderMVA_TimerOver: ' + err); }}
}

function jSliderMVA_TimerOut(event){
	try{
		GlobalSliderMVA_TimerPerm=true;
	}catch(err){ if(jDebugMode==true){ alert('jSliderMVA_TimerOut: ' + err); }}
}

function jSliderMVA_Timer(IDprev, IDnext, Duration, Status){
	try{
		if(!IDprev || IDprev==''){ return false; }
		if(!IDnext || IDnext==''){ return false; }
		if(!Duration || Duration==''){ return false; }
		if(Duration<=0){ return false; }
		if(!Status || Status==''){ Status=''; }
		
		if((GlobalSliderMVA_TimerPerm==true) && (Status!='firstrun')){
			$JQ('#'+IDnext).click();
			self.setTimeout("jSliderMVA_Timer('"+IDprev+"','"+IDnext+"',"+Duration+")",  Duration);
			return;
		}else{ self.setTimeout("jSliderMVA_Timer('"+IDprev+"','"+IDnext+"',"+Duration+")",  Duration); }
		//self.setTimeout("jSliderMVA_Timer('"+IDprev+"','"+IDnext+"',"+Duration+")", 3000);
		
	}catch(err){ if(jDebugMode==true){ alert('jSliderMVA_Timer: ' + err); }}
}
/* =============================== .SliderMVA [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){
	try{ 
		if(!Name || Name=='' || Name.length<2){ return false; }
		if(!Duration || Duration==''){ Duration=300; }
		
		switch(Name.charAt(0)){
			case '.': break;
			case '#': break;
			default: Name='#'+Name;
		}
		
		$JQ(Name+' img').css('opacity',0);
		$JQ(Name+' img').css('visibility','visible');
		
		$JQ(Name).hover(function(){
			$JQ(this).find('img').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(){    }});
		});
		
	}catch(err){ if(jDebugQueryMode==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=$JQ(Name);
		var c_height;
		
		for(var i=0; i<elements.length;i++){
			//c_height=parseInt($JQ(Name).eq(i).css('height'));
			c_height=parseInt($JQ(Name).eq(i).height()); //IE6 Path;
			if(c_height<Height){ $JQ(Name).eq(i).css('height',Height); }
		}
		return true;
	}catch(err){ if(jDebugQueryMode==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] =============================== */
/* ================================================================================== */
