$(document).ready(function() {

	$('#select-language').change(function(){
		var thecountry = $('#select-language :selected').text()
		$('#languages div').css('display', 'none');
		$('#languages #' + thecountry + '-SScontent').css('display', 'block');
		
	})
	
	$("#footerboxes > li:last, #homeboxes > li:last").addClass('last');

	$(".iFrame").colorbox({iframe:true, innerWidth:700, innerHeight:400}); 

    //form validation
    $("#mc-embedded-subscribe-form").validate();
    $("#contactform").validate(); 
    
    $('#col2 div.breadcrumbs a:last-child').addClass('lastchild');
        
    
    //hide state box if not USA
    $('#form-country').change(function(){
    	var selected = $("#form-country option:selected");
    	if(selected.val() !="US"){
    		$('#form-state-province').css('display', 'none');
    		$('#areabox').css('display', 'inline');    		
    	}else if(selected.val() =="US"){
    		$('#areabox').css('display', 'none');    		
    		$('#form-state-province').css('display', 'inline');    		
    	}
    });


	//shows contact fields & makes required if selected
	$('#YesSendNewsletter, #YesSendCourses, #YesSendCatalog').change(function(){	
		var sendValue1 = $('#YesSendNewsletter').val();
		var sendValue2 = $('#YesSendCourses').val();
		var sendValue3 = $('#YesSendCatalog').val();
		if((sendValue1 == "on") || (sendValue2 == "on") || (sendValue3 == "on" )){
			$('#contactinfo').show('fast');
			$('#form-country, #form-state-province, #Address1, #city, #zip').addClass('required');
		}else{ 
			$('#contactinfo').hide('fast');
			$('#form-country, #form-state-province, #Address1, #city, #zip').removeClass('required');
		}
	});

	//clears search box
	$('#keywords').focus(function(){
		if(this.value=='Enter Keywords'){
			this.value='';
		}
	});
	
	$('#emailHeader').focus(function(){
		if(this.value=='Enter Email Address'){
			this.value='';
		}
	});
	
	//	Put's message back if no data...
	$('#keywords').blur(function(){
		if ( this.value == '' || this.value == null )
			this.value = 'Enter Keywords';
	});
	
	$('#emailHeader').blur(function(){
		if ( this.value == '' || this.value == null )
			this.value = 'Enter Email Address';
	});
	
	//hover state for active menu items
	$('li.item57 ul li, li.item59 ul li').hover(function(){
		$(this).parent().parent().addClass('active');
	}, function(){
		$(this).parent().parent().removeClass('active');
	})
	
	$('#nav li ul li ul li').hover(function(){
		$(this).parent().parent().addClass('thirdhover');
	}, function(){
		$(this).parent().parent().removeClass('thirdhover');
	})
	
	//get height of home boxes so we can align them
	function sortASC(a, b){ return (a-b); }
	function sortDESC(a, b){ return (b-a); }
	
	var firstbox = $("#homeboxes > li:nth-child(1)").height();
	var secondbox = $("#homeboxes > li:nth-child(2)").height();
	var thirdbox = $("#homeboxes > li:nth-child(3)").height();
	var fourthbox = $("#homeboxes > li:nth-child(4)").height();
	var boxarray = [firstbox, secondbox, thirdbox, fourthbox];
	boxarray.sort(sortDESC);
	theheight = boxarray[0];
	$('#homeboxes>li').css('height', theheight);
	$('#homeboxes li .homeboxbottom').css('top', theheight);
	
	//active tab display on product detail page
	$('#more-tabs a').click(function(){
		var thetab = $(this).attr('id');
		thetabnum = parseFloat(thetab.substr(10));
		$('#more-tabs a').removeClass('active');
		$('#more-content #more-content-1, #more-content #more-content-2').css('display', 'none');
		$(this).addClass('active');
		$('#more-content-'+thetabnum).css('display', 'block');
		return false;
	})
	
});

//new accordion

function initMenu() {
	var myTimer
	var opened = false
	var myHoverIntent = 333;
	
	if($('#col1 li#current')){ //show 3rd level if active
		$('#col1 .active ul ul').hide();		
		$('#col1 li#current').parent().css('display', 'block');
	}else{
		$('#col1 .active ul ul').hide();	
	}
	
	//$('#col1 .active ul ul').hide();
  
    $('#col1 .active li a').mouseover(function(){
		var acc = $(this)								
		myTimer = setTimeout(function(){acc.next().slideDown('normal')}, myHoverIntent);
	});
	
	$('#col1 .active li a').mouseout(function(){
		clearTimeout(myTimer);
	});
	
	$('#col1 .active li:has(li)').each(function(i){
		$(this).addClass('has-children');	
	});
  }
  
$(document).ready(function() {initMenu();});
