jQuery(document).ready(function(){
    
    //search    
    jQuery("#searchtext").keypress(
      function (e)
      {
        if(e.which==13)
        {
          document.location.href = '/search-results.aspx?cx=001653314553456783151:axrnv4j4c3m&cof=FORID:10&q=31&sa=Search&q=' + jQuery("#searchtext").val();
          return false;
        }
      }
      );
      
      jQuery('#searchbutton').click(function(){
        document.location.href = '/search-results.aspx?cx=001653314553456783151:axrnv4j4c3m&cof=FORID:10&q=31&sa=Search&q=' + jQuery("#searchtext").val();
        return false;
    });
      
    

	// Main menu
	jQuery('#topMenu ul li:last a').css({"background-image":"none"});
	jQuery('#topMenu ul li#active').prev().children('a').css({"background-image":"none"});
	jQuery("#topMenu ul li a").hover(
      function () {
		if(jQuery(this).parent().prev("#active")[0]){
			jQuery(this).addClass("hasLeft");
		}
		if(jQuery(this).parent().next("#active")[0]){
			jQuery(this).addClass("hasRight");
		}
        jQuery(this).parent().prev().children('a').addClass('near');
      }, 
      function () {
        jQuery(this).parent().prev().children('a').removeClass('near');
		jQuery(this).removeClass('hasLeft');
		jQuery(this).removeClass('hasRight');
      }
    );
	// Search hint textbox
	jQuery('input[title!=""]').hint();
	// Accordion
	if(jQuery('#accordion')[0]){
		jQuery('#accordion').accordion({ header: "h3" });
	}
	// Left menu
	if(jQuery('.accMenuM')[0]){
		jQuery('#subMenu').accordion({ header: "h3", active: false, alwaysOpen: false,  autoHeight: false,  event: 'mouseover'});
	}
	// Product detail
	if(jQuery('.contactForm')[0]){
		jQuery('.contactForm').accordion({ header: "h3", active: true, alwaysOpen: false,  autoHeight: false });
	}
	// Front page equal columns
	if(jQuery('.leftHome, .rightHome')[0]){
		jQuery('.leftHome, .rightHome').equalHeight();
	}
	// preFooter boxes equal height
	if(jQuery('.preFooter .newsletter, .preFooter .summary')[0]){
		jQuery('.preFooter .newsletter, .preFooter .summary').equalHeight();
	}
	// Staff member
	jQuery(".box .staffMember:last").css({"margin-right":"0"});
	// Image switcher
	
	if(jQuery('.aepanel')[0]){
	    jQuery('.aepanel').equalHeight();
	}
	
	//NEWSLETTER FORM
    populateElement('.newsletter fieldset input.inpTxt');
    
    //CONTACT FORM
    populateElement('.contactUsForm .inpTxt');
    
    //TABS ON HOMEPAGE
    jQuery('.topContact li a').click(function(){
        
        //show tab
        var tab = jQuery(this).attr('href').replace('#','');
        jQuery('.topContact .tab').hide().filter('#'+tab).show();
        
        //Activate tab
        jQuery('.topContact li.active').removeClass('active');
        jQuery(this).parent().addClass('active');
        
        return false;
    });
    
});