// JavaScript Document
//łśćłżź
var DebugQueryMode=true; //Show Alerts
//var IE=false;

/* ================================================================================== */
/* =============================== 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] ===================================== */
/*
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); }}
}*/

/* =============================== .single [START] ================================== */
function jTopAnimation(ID, c_left1, c_left2, c_left3){
	try{ 
	
		if(!ID || ID==''){
			var c_top=parseInt($JQ('#top_logo').css('top'));
			$JQ('#top_logo').css('top',-82);
			$JQ('#top_logo').css('visibility','visible');
			$JQ('#top_logo').animate({top:c_top},{easing:"easeOutBounce",duration:2000} );
			
			var c_left1=parseInt($JQ('#top_text').css('left'));
			var c_left2=parseInt($JQ('#top_link').css('left'));
			//var c_left3=parseInt($JQ('#top_text3').css('left'));
			
			$JQ('#top_text').css('left',c_left1+1500);
			$JQ('#top_link').css('left',c_left2+1500);
			//$JQ('#top_text3').css('left',c_left3+1500);
			
			$JQ('#top_text').css('visibility','visible');
			$JQ('#top_link').css('visibility','visible');
			//$JQ('#top_text3').css('visibility','visible');
		}
		
		switch(ID){
			case 'top_text': ID='top_link'; c_left=c_left2; break;
			case 'top_link': ID='top_text3'; c_left=c_left3; break;
			//case 'top_text3': return true; break;
			default: ID='top_text'; c_left=c_left1;
		}
		$JQ('#'+ID).css('left',c_left+2000);
		$JQ('#'+ID).animate({left:c_left},{easing:"easeInOutQuad",duration:400, complete:function(){ jTopAnimation($JQ(this).attr('id'), c_left1, c_left2, c_left3);  }});
		return true;
	}catch(err){ if(jDebugMode==true){ alert('jTopAnimation: ' + err); }}
}

function jMenuAnimation(ID){
	if(!ID || ID==''){ return false; }
	if(!IE60 || IE60==''){ var IE60=false; }
	var c_duration=600;
	var elements=$JQ('#'+ID+' li');
	$JQ(elements).css('opacity','0'); //css
	
	var c_pdleft=parseInt($JQ(elements).find('a').eq(0).css('paddingLeft'));
	var c_pdright=parseInt($JQ(elements).find('a').eq(0).css('paddingRight'));

	$JQ(elements).find('a').css('paddingLeft',0);
	$JQ(elements).find('a').css('paddingRight',0);
	for(var i=0;i<elements.length;i++){
		$JQ(elements).eq(i).animate({opacity:1},{easing:"easeInOutElastic",duration:c_duration, complete:function(){ /**/  }});
		if(i==elements.length-1){
			$JQ(elements).eq(i).find('a').animate({paddingLeft:15, paddingRight:15},{easing:"easeInOutQuart",duration:c_duration, complete:function(){ 
				$JQ('#excavator_sub').animate({opacity:1},{easing:"swing",duration:2000, complete:function(){ /**/ }});
				$JQ('#excavator_home').animate({opacity:1},{easing:"swing",duration:2000, complete:function(){ /**/ }});   
			}});
		}else{
			$JQ(elements).eq(i).find('a').animate({paddingLeft:15, paddingRight:15},{easing:"easeInOutQuart",duration:c_duration, complete:function(){ /**/  }});
		}
		c_duration=c_duration+300;
	}
	
	$JQ(elements).find('a').hover(function(){
		$JQ(this).css('paddingTop',13)
		$JQ(this).css('paddingBottom',11);
        $JQ(this).animate({ paddingTop:19, paddingBottom:14},{easing:"swing",duration:300, queue:false, complete:function(){ /**/  }});
      },function(){
	  	$JQ(this).animate({ paddingTop:13, paddingBottom:11},{easing:"swing",duration:300, queue:false, complete:function(){ /**/  }});
      });
}




function jTabsClick(This,IDul){
	try{ 
		if(!IDul || IDul==''){ return false; }
		if($JQ(This).parent().attr('class')){ return false; }
		
		/*var elements=$JQ(This).parent().parent().find('li');
		$JQ(elements).attr('class','');*/
		
		$JQ(This).parent().parent().find('li').attr('class','');
		
		var elements=$JQ(This).parent().parent().find('a');
		var c_href;
		
		var c_hrefold=$JQ(This).attr('href');
		
		for(var i=0;i<elements.length;i++){
			c_href=$JQ(elements).eq(i).attr('href');
			if(c_href==c_hrefold){
				$JQ(c_href).css('z-index',10);
				$JQ(c_href).animate({ opacity:1 },{easing:"swing",duration:1000, queue:false, complete:function(){ /**/ }});
			}else{
				$JQ(c_href).css('z-index',1);
				$JQ(c_href).animate({ opacity:0 },{easing:"swing",duration:1000, queue:false, complete:function(){ /**/ }});
			}
			
		}
		$JQ(This).parent().attr('class','active');
		//alert(elements.length); 
		
		
	}catch(err){ if(jDebugMode==true){ alert('jTabsClick: ' + err); }}
}

function jTabs(IDul){
try{ 
		if(!IDul || IDul==''){ return false; }
		
		var elements=$JQ('#'+IDul).find('li');
		var c_found=false;
		var c_href;
		var c_hreffirst=0;
		for(var i=0;i<elements.length;i++){
			//if($JQ(elements).eq(i).attr('class')=='active'){ $JQ(c_href).css('z-index',10); c_found=true; }
			c_href=$JQ(elements).eq(i).children().attr('href');
			$JQ(c_href).css('opacity',0);
			$JQ(c_href).css('z-index',1);
			if(i==0){ c_hreffirst=c_href; }
		}
		
		if(c_found==false){
			$JQ(elements).eq(0).attr('class','active');
			$JQ(c_hreffirst).css('z-index',10);
			$JQ(c_hreffirst).animate({ opacity:1 },{easing:"swing",duration:1000, queue:false, complete:function(){ /**/ }});
		}
		//alert(c_found);
	}catch(err){ if(jDebugMode==true){ alert('jTabs: ' + err); }}
}


$JQ(document).ready(function(){
	jTopAnimation();
	
	var IE6=false;
	if(jQuery.browser.msie && jQuery.browser.version == 6){ IE6=true; }
	if(IE6==true){
		$JQ('#excavator_sub').css('opacity',0);
		$JQ('#excavator_home').css('opacity',0);
		$JQ('#excavator_sub').animate({opacity:1},{easing:"swing",duration:2000, complete:function(){ /**/ }});
		$JQ('#excavator_home').animate({opacity:1},{easing:"swing",duration:2000, complete:function(){ /**/ }});   
	}else{ jMenuAnimation('menul'); }
});
/* =============================== .single [END] ==================================== */
/* ================================================================================== */
/* =============================== jquery.ready [END] =============================== */
/* ================================================================================== */

