// JavaScript Document

jQuery(function($){
	$.translate(function(){ 

    });
	
	$('.faqCont .row h3').css('cursor','pointer');
	$('.faqCont .row div').hide();
		$('.faqCont .row h3').click(function(){
				if($(this).siblings('div').is(':hidden')){						  
					$('.faqCont .row div').slideUp();
					$(this).siblings('div').slideDown();
				}
		});
	
	
})


$.fn.equalHeight = function () {
		var height		= 0;
		var maxHeight	= 0;
	
		// Store the tallest element's height
		this.each(function () {
			height		= $(this).outerHeight();
			maxHeight	= (height > maxHeight) ? height : maxHeight;
		});
	
		// Set element's min-height to tallest element's height
		return this.each(function () {
			var t			= $(this);
			var minHeight	= maxHeight - (t.outerHeight() - t.height());
			var property	= $.browser.msie && $.browser.version < 7 ? 'height' : 'min-height';
	
			t.css(property, minHeight + 'px');
		});
};


function heightFixer(){
	var contentWrap =  $('.contentWrap').height() - 5; // height - padding
	var testimonial =  $('.testimonial').height();
	
	var colOne = $('.contentWrap .col1').height();
	var colTwo = $('.contentWrap .col2').height();
	var colThree = $('.contentWrap .col3').height();
	
	var openDays =  $('.openDays').height();
	var newsHome =  $('.newsHome .greyBorder .newsBlock').height(colThree - openDays + 6 - 89);
	var faqHook =  $('.faqHook').height();
	
	var epsHook = $('.eps').height();
	var nearest = $('.col3 .global').height();
//	var main =  $('.main .greyBorder').height(contentWrap - testimonial - 7 - 28 - 10 + 6 - 1);
	var main =  $('.main .greyBorder').height(epsHook - testimonial + faqHook + nearest - 8 -10  );
	
	
	var defaultLeftCol = $('.defaultLeft').height();
	var defaultRightCol = $('.defaultRight').height();
	
	if(defaultLeftCol > defaultRightCol){
	//	$('.defaultRight').height(defaultLeftCol - 40);
	} else {
		$('.defaultLeft').height(defaultRightCol + 40);
	}
	
	$('#container #navigationContainer .navigation ul li').hover(
		function() {
			//alert('test');
			$('.megaMenu .level1').equalHeight();
		}
	);
};


$(window).load(function() {
	//Homepage JS Height Equalizer!
	heightFixer();
});


$(document).ready(function() {
	
	heightFixer();
	
	$('.prodSelector').change(function() {
		var linktoVersion = $(this).val();
		$(this).siblings('.coolButtons').children('.request').attr("href", site_uri + "request-a-sample/"+linktoVersion);

	});
	
	$('.prodSelector').change(function() {
		var linktoVersion = $(this).val();
		$(this).siblings('.coolButtons').children('.orderSupplies').attr("href", site_uri + "order-supplies/"+linktoVersion);

	});
	
//	var cookieLang = $.cookie('destLanguage');

	if( sessionLanguage ){  //if it was set then 
		translateTo( sessionLanguage );
		//alert(destLang);
		$('.lineOne span').removeClass('chosen');
		$('.lineOne span#'+sessionLanguage).addClass('chosen');  
	}
	
//	alert(cookieLang);
	
/*	if(cookieLang != ''){
	$('.lineOne span').removeClass('chosen');
	$('#' + cookieLang).addClass('chosen');  
	}
*/
	$("a[rel='example1']").colorbox();
	
	///////////--product version selector--/////////
	$('.coolButtons a').click(function(event) {
		if(!$('.coolButtons a').parent().hasClass('active')) event.preventDefault(); 							   
	});
	
	$('.prodSelector').change(function() {
		var selectVal = $(this).val();	   
	  
	  	if(selectVal > 0) {
		  $(this).siblings('.coolButtons').addClass('active');
		  $(this).siblings('.coolButtons a').click(function() {
				return true;
			});
		} else {
			$(this).siblings('.coolButtons').removeClass('active');
			$(this).siblings('.coolButtons a').click(function(event) {
				event.preventDefault(); 
			});

		}
	});
	
	$('.catSummaryLeft li').click(function() {
		$('.catSummaryLeft li').removeClass('chosen');
		$(this).addClass('chosen');
	});
	
	//alert($('.esel').text());
	$('.extraESE').hide();
	$('.special1').change(function() {
		$('.esel').text('Certificate Number');
		$('.extraESE').show();
	});
	
	$('.special2').change(function() {
		$('.esel').text('NI Number');
		$('.extraESE').show();
	});
	
	$('.normals').change(function() {
		$('.extraESE').hide();
	});
	
	//////////////////////

//$("a.video").colorbox({iframe:true, innerWidth:695, innerHeight:380, opacity:0.5});	

	$('.defaultWrapper .defaultLeft .productsContainer .liner2 .productBox').equalHeight();
	$('.defaultWrapper .defaultLeft .productsContainer .liner4 .productBox').equalHeight();
	$('.defaultWrapper .defaultLeft .productsContainer .liner6 .productBox').equalHeight();
	$('.defaultWrapper .defaultLeft .productsContainer .liner8 .productBox').equalHeight();
	$('.defaultWrapper .defaultLeft .productsContainer .liner10 .productBox').equalHeight();
	$('.defaultWrapper .defaultLeft .productsContainer .liner12 .productBox').equalHeight();
	$('.defaultWrapper .defaultLeft .productsContainer .liner14 .productBox').equalHeight();
	$('.heighter').equalHeight();
	
	
	 //Default Action
            $(".tab_content").hide(); //Hide all content
            $("ul.tabs li:first").addClass("active").show(); //Activate first tab
            $(".tab_content:first").show(); //Show first tab content
            
            //On Click Event
            $("ul.tabs li").click(function() {
                $("ul.tabs li").removeClass("active"); //Remove any "active" class
                $(this).addClass("active"); //Add "active" class to selected tab
                $(".tab_content").hide(); //Hide all tab content
                var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
                $(activeTab).fadeIn(); //Fade in the active content
                return false;
            });
	 
	
	
	$('#search').val('Search...');
	$('#search').click(function(){ $(this).focus().val('');	});
	$('#search').blur(function(){ if($('#search').val() == ''){	$('#search').val('Search...'); } });
	
	//////////////////////////////
		var numberOfSlides = $('ul.slides li').length;
		var slidewidth = 480;
		var sliderWidth = numberOfSlides*slidewidth;
		var lessThanViewPort = sliderWidth-slidewidth;
		
		$('#slider.slider ul.slides').css('width',sliderWidth);
	//	$('#slider.slider ul.slides').css('margin-top',sliderWidth*-1 + slidewidth);
		
		$('img.build').hide();
		
		$('.slideInfo.active').show();
		
		setInterval(function() { moveSlider(slidewidth, sliderWidth, lessThanViewPort) } ,11000);
		
		/////////////////////////////////////////////////////////////////////////////////////////
		
		$(".tab_content").hide(); 

		$("#tabs ul.tabs a:first").addClass("active").show(); 
		$(".tab_content:first").show(); 
	
		
		$("#tabs ul.tabs a").click(function() {
		
			$("#tabs ul.tabs a").removeClass("active"); 
			
			$(this).addClass("active"); 
			
			$(".tab_content").hide();
			
			//var activeTab = $(this).attr("href"); //Find the href attribute value to identify the active tab + content
			var activeTab = '#'+$(this).attr("title");
		
			
			$(activeTab).css('display','block'); 
			
	
			return false;
		});
		
		//**************************************************************************
		
		function translateTo( destLang ){  
				                
			$('body').translate( 'english', destLang, {
			  not: '#jq-translate-ui, #contactus, #ouragents, #lifestyle, #footer, #featured, #search, #flags2, #aboutus, noscript',  //just trans the homepage
			  fromOriginal:true
			  
			 /* ,   //always translate from english (even after the page has been translated)   
									 
				start: function(){ $('#throbber').show() },   // show loading icon
				complete: function(){ $('#throbber').hide() },  // hide loading icon          
				error: function(){ $('#throbber').hide() }  // hide loading icon*/
			}); 
		}
    	  
		$('.lineOne span').click(function(){       
			$('.lineOne span').removeClass('chosen');
			$(this).addClass('chosen');  
			
		
		
		$.post(site_uri+"libs/plugins/languageSelector.php", {username: $(this).attr('id')}, function(data){
		 
			if(data != "0")
			{
		//	$("#container .punchLine").html("<b>SESSION Setup Successfully!</b>");
			translateTo( data ); 
			} else {
	//		$("#container .punchLine").html("<b>Something Broke! HELP!</b>");
			}
			 
		});
		
		
		
		
		/*	var lang = $(this).attr('id');         
			translateTo( lang ); 
				if( destLang ){
			$.cookie('destLanguage', null);
			} 
			
			$.cookie('destLanguage', lang);
	*/
			return false;                            
		});
			 
	//	var destLang = $.cookie('destLanguage'); //get previously translated language      
		//alert(destLang);
		
	
});


function moveSlider(slidewidth, sliderWidth, lessThanViewPort){
			
			var leftVal = $('ul.slides').css('margin-left');
				leftVal = parseInt(leftVal);
				leftVal = (leftVal*-1); 
			
			
			
			if (leftVal<lessThanViewPort){
				$("#slider.slider ul.slides").animate({
						'margin-left': '-=480'								  
				},700)
				$('.slideInfo.active').hide().removeClass('active').next('.slideInfo').fadeIn().addClass('active');
			}else{
				$("#slider.slider ul.slides").animate({
						'margin-left': '0'								  
				},400)
				$('.slideInfo.active').hide().removeClass('active');
				$('.slideInfo:first').fadeIn().addClass('active')
			}
			
}


