$(document).ready(function(){
	
	//Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
	$("ul.subNavigation").parent().append("<span class='trigger'></span>"); 	
	
	$('ul.topNavigation').each(function(e) {
		
		var bindType = "";
		
		if( $(this).hasClass("click") ) {
			bindType = "click";
		} else if ( $(this).hasClass("mouseover") ) {
			bindType = "mouseover";
		}
		
		if(bindType != "") {
			//When trigger is clicked...
			$(this).find("li a").bind(bindType, function(e) {
				e.preventDefault();
	
				//Following events are applied to the subnav itself (moving subnav up and down)
				//Drop down the subnav on click
				$(this).parent().find("ul.subNavigation").slideDown('fast').show();
				
				$(this).parent().hover(function() {
					//Do nothing
				}, function(){
					//When the mouse hovers out of the subnav, move it back up
					$(this).parent().find("ul.subNavigation").hide();
				});
	
			//Following events are applied to the trigger (Hover events for the trigger)
			}).hover(function() {
					//On hover over, add class "subhover"
					$(this).addClass("subhover");
				}, function(){	
					//On hover out, remove class "subhover"
					$(this).removeClass("subhover");
			});
		}
	});	
});