$(document).ready(function(){
	
	$("ul.subnav").parent().append('<span class="dropdown"></span>'); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
	$("ul.subnav").parent().addClass("isdropdown");

	$("#navmenu li a").hover(function() {
		$(this).parent().find("span.dropdown").addClass("dropdownhint");
	}, function(){
		$(this).parent().find("span.dropdown").removeClass("dropdownhint");
	});
	
	$("#navmenu li span.dropdown").click(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		//$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
		//$(this).parent().find("ul.subnav").show(); //Drop down the subnav on click
		$(this).parent().find("ul.subnav").fadeIn("fast"); //Drop down the subnav on click
		$(this).addClass("dropdownactive"); //On click, add class "dropdownhover"
		$(this).parent().find("a").addClass("active");
		
		$(this).parent().hover(function() {
		}, function(){
			//$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			//$(this).parent().find("ul.subnav").hide(); //When the mouse hovers out of the subnav, move it back up
			$(this).parent().find("ul.subnav").fadeOut("fast"); //When the mouse hovers out of the subnav, move it back up
			$("#navmenu li span.dropdown").removeClass("dropdownactive"); //On hover over, remove class "dropdownhover"
			$(this).find("a").removeClass("active");
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("dropdownhover"); //On hover over, add class "subhover"
			$(this).parent().find("a").addClass("subhover");
		}, function(){	//On Hover Out
			$(this).removeClass("dropdownhover"); //On hover out, remove class "subhover"
			$(this).parent().find("a").removeClass("subhover");
	});

});