$(document).ready(function(){

	//$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
	//$("ul.topnav li span").click(function() { //When trigger is clicked...	
	var trg = 0;
	$("ul.topnav li a").eq(0).click(function(e) { //When trigger is clicked...
		trg++;
		e.preventDefault();
		$(this).css({ background: "url(./client/images/change_location_bg_hover.jpg) no-repeat center center" });

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown(150).show(); //Drop down the subnav on click
		

		$(this).parent().hover(function() {
			//$("ul.topnav li a").eq(0).css({ background: "url(./client/images/change_location_bg_hover.jpg) no-repeat center center" });
		}, function(){
			$(this).parent().find("ul.subnav").slideUp(120); //When the mouse hovers out of the subnav, move it back up
			$("ul.topnav li a").eq(0).css({ background: "url(./client/images/change_location_bg.jpg) no-repeat center center" });
		});
		
		
		//Following events are applied to the trigger (Hover events for the trigger)
	}).hover(function() {
		$(this).addClass("subhover"); //On hover over, add class "subhover"
		$("ul.topnav li a").eq(0).css({ background: "url(./client/images/change_location_bg_hover.jpg) no-repeat center center" });
	}, function(){	//On Hover Out
		$(this).removeClass("subhover"); //On hover out, remove class "subhover"
		if( trg == 0 ) {
			$("ul.topnav li a").eq(0).css({ background: "url(./client/images/change_location_bg.jpg) no-repeat center center" });
		}
	});

});

