jQuery(function (){
	
	// detect dropdown
	if ($('div#mainNav ul').hasClass('topnav'))
	{
		
		$("#mainNav").height($("ul.topnav").height());
		
		$("ul.topnav > li").hover(function() {
			$(this).addClass('tophover');
			
			//Following events are applied to the subnav itself (moving subnav up and down)
			$(this).find("ul.subnav").stop(true, true).slideDown('fast').show(); //Drop down the subnav on click	
			
			$(this).hover(function() {
				
			}, function(){
				$(this).find("ul.subnav").stop(true, true).slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
				$(this).removeClass('tophover')
			});
		});
		$("ul.topnav > li > ul > li").hover(function() {
				$(this).addClass("subhover"); //On hover over, add class "subhover"
			}, function(){	//On Hover Out
				$(this).removeClass("subhover"); //On hover out, remove class "subhover"
		});
	}
});
