// JavaScript Document
function normalized()
{
	 if($("#am").hasClass("na_action")){
		 $("#am").removeClass("na_action");
		 $("#am").addClass("action");
	 }
	 if($("#pm").hasClass("na_new_product")){
		 $("#pm").removeClass("na_new_product");
		 $("#pm").addClass("new_product");
	 }
	 $(".new_product_submenu").hide();
	 $(".action_submenu").hide();
}

function normalizea()
{
	if($("#dm").hasClass("na_discount")){
		$("#dm").removeClass("na_discount");
		$("#dm").addClass("discount");
	}
	if($("#pm").hasClass("na_new_product")){
	    $("#pm").removeClass("na_new_product");
		$("#pm").addClass("new_product");
	}
	 $(".new_product_submenu").hide();
	 $(".discount_submenu").hide();
}

function normalizep()
{
	if($("#am").hasClass("na_action")){
	    $("#am").removeClass("na_action");
		$("#am").addClass("action");
	}
	if($("#dm").hasClass("na_discount")){
		$("#dm").removeClass("na_discount");
		$("#dm").addClass("discount");
	}
	 $(".action_submenu").hide();
	 $(".discount_submenu").hide();
}

//action
$(document).ready(function(){

	$("ul.action_submenu").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	$("ul.shop_promo_menu li.action").click(function() { //When trigger is clicked...
		normalizea();
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.action_submenu").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.action_submenu").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			 if($("#am").hasClass("na_action"))
			 {
			   $("#am").removeClass("na_action");
			   $("#am").addClass("action");
			 }
		});

		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	var id = "#am";
	var current = "action";
	var change = "na_action";
	$(id).click(
	function(){
	 if($(id).hasClass(current))
	 {
	   $(id).removeClass(current);
	   $(id).addClass(change);
	 }
	 else
	 {
	 $("ul.shop_promo_menu > li > ul:visible").slideUp('slow');		 
	   $(id).removeClass(change);
	   $(id).addClass(current);
	   $(id+" > action_submenu").hide();
	 }
	});
	  
});

//discount
$(document).ready(function(){

	$("ul.discount_submenu").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	$("ul.shop_promo_menu li.discount").click(function() { //When trigger is clicked...
		normalized();
		//$("ul.shop_promo_menu > li > ul:visible").slideUp('slow');
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.discount_submenu").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.discount_submenu").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			 if($("#dm").hasClass("na_discount"))
			 {
			   $("#dm").removeClass("na_discount");
			   $("#dm").addClass("discount");
			 }
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	var id = "#dm";
	var current = "discount";
	var change = "na_discount";
	$(id).click(
	function(){
	 if($(id).hasClass(current))
	 {
	   $(id).removeClass(current);
	   $(id).addClass(change);
	 }
	 else
	 {
	 $("ul.shop_promo_menu > li > ul:visible").slideUp('slow');		 
	   $(id).removeClass(change);
	   $(id).addClass(current);
	   $(id+" > discount_submenu").hide();
	 }
	});

});

//new_product
$(document).ready(function(){

	$("ul.new_product_submenu").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	$("ul.shop_promo_menu li.new_product").click(function() { //When trigger is clicked...
		normalizep();
		//$("ul.shop_promo_menu > li > ul:visible").slideUp('slow');
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.new_product_submenu").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.new_product_submenu").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			 if($("#pm").hasClass("na_new_product"))
			 {
			   $("#pm").removeClass("na_new_product");
			   $("#pm").addClass("new_product");
			 }
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	var id = "#pm";
	var current = "new_product";
	var change = "na_new_product";
	$(id).click(
	function(){
	 if($(id).hasClass(current))
	 {
	   $(id).removeClass(current);
	   $(id).addClass(change);
	 }
	 else
	 {
	 $("ul.shop_promo_menu > li > ul:visible").slideUp('slow');		 
	   $(id).removeClass(change);
	   $(id).addClass(current);
	   $(id+" > new_product_submenu").hide();
	 }
	});

});
