var mainMenus={
	animateDuration: {over: 150, out: 100}, //duration of slide in/ out animation, in milliseconds
	buildMenus:function(){
		//jQuery(document).ready(function($){
			var $mainMenu=$(".main_menu")
			var $headers=$mainMenu.find("ul").parent()
			$headers.each(function(i){
                //$currentLI=$(this)
				$(this).addClass("has_submenu")
				$(this).hover(
					function(e){
						$(this).addClass("active")
						var $subMenu=$(this).children("ul")
						if ($subMenu.queue().length<=1) { //if 1 or less queued animations
							//$subMenu.slideDown(mainMenus.animateDuration.over)
							$subMenu.css({display:'block'})
						} //end if ($subMenu.queue().length<=1)
					},
					function(e){
						$(this).removeClass("active")
						var $subMenu=$(this).children("ul")
						//$subMenu.slideUp(mainMenus.animateDuration.out)
						$subMenu.css({display:'none'})
					}
				) //end $(this).hover
			}) //end $headers.each()
			$mainMenu.find("ul").css({display:'none', visibility:'visible'})
		//}) //end document.ready
	} //end buildMenus:function()
} //end var mainMenus

//if the document is ready, apply all functions
$(document).ready(function() {
	//set up animations for drop down menus
	mainMenus.buildMenus();
	//loop through all links and set external ones to target="_blank"
	$('a[rel*=external]').attr("target","_blank");
	$('a[rel*=external]').attr("title","(opens in new window)");
	$('a[rel*=nofollow]').attr("target","_blank");
	$('a[rel*=nofollow]').attr("title","(opens in new window)");
	//$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank");
	//$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("title","(opens in new window)");
	//set items per page form autosubmission
	$("#items_per_page").bind("change", function() { this.form.submit(); });
	//show/hide text in postcode search in header
	$("#nearest_store_postcode").attr("value","nearest store");
	$("#nearest_store_postcode").click( function() { if ($(this).attr("value")=="nearest store") { $(this).attr("value",""); } });
	$("#nearest_store_postcode").blur( function() { if ($(this).attr("value")=="") { $(this).attr("value","nearest store"); } });
	//show/hide text in product search in header
	$("#search_products_keywords").attr("value","search products");
	$("#search_products_keywords").click( function() { if ($(this).attr("value")=="search products") { $(this).attr("value",""); } });
	$("#search_products_keywords").blur( function() { if ($(this).attr("value")=="") { $(this).attr("value","search products"); } });
	//apply lightbox to links
	$('a[rel*=lightbox]').lightBox();
	//autosubmission for shopping basket updates
	$("select[name*=quantity]").bind("change", function() { this.form.submit(); }); //change quantity
	$("input[name*=add_homeserve]").click( function() { this.form.submit(); }); //add homeserve
	//$("select[name*=delivery_option]").bind("change", function() { this.form.submit(); }); //change delivery option
	$("input[name*=delivery_option]").click( function() { this.form.submit(); }); //change delivery option
	//checkout form show/hide delivery details
	$("#delivery_same_as_billing").click( function() { if ($(this).attr('checked')) { $("#delivery_details").slideUp(200); } else { $("#delivery_details").slideDown(200); } });
    if ($("#delivery_same_as_billing").attr('checked')) { $("#delivery_details").css({display:'none', visibility:'visible'}); }
});