var current = false;
var urls = {
	sul : "http://www.dm9sul.com.br",
	ddb : "http://www.dm9ddb.com.br",
	rio : "http://www.dm9rio.com.br"
};
var marker = "img/marker.jpg"
var marker_selected = "img/marker_selected.jpg"

jQuery(document).ready(function($) {
	$(".menu_item").hover(
		function() {
			var target = $(this).attr("id").split("_").pop();

			if(target != current) {
				$("#logo_" + target).attr("src", "img/logo_dm9" + target + "_over.jpg");
			}
		},
		function() {
			var target = $(this).attr("id").split("_").pop();

			if(target != current) {
				$("#logo_" + target).attr("src", "img/logo_dm9" + target + "_inactive.jpg");
			}	
		}
	);
	
	$(".menu_item").click(function() {
		// First click
		if(!current) {
			$("#menu").css({height : 115});
		}

		var target = $(this).attr("id").split("_").pop();

		if(target != current) {
			// Hide current content
			if(current) {
				$("#logo_" + current).attr("src", "img/logo_dm9" + current + "_inactive.jpg");
				$("." + current + ".active").hide();
				$("." + current + ".inactive").show();
				$("#marker_" + current).attr("src", marker);
				$("#content_" + current).fadeOut("slow");
			}
			
			// Scroll and show next content
			$("." + target + ".inactive").hide();
			$("." + target + ".active").show();
			$("#marker_" + target).attr("src", marker_selected);
			$("#content_" + target).fadeIn("slow", function() {
				$('html, body').animate({scrollTop: $("#footer").offset().top}, "slow");
			});
			current = target;
		} else {
			window.open(urls[current], "_blank");
		}
	});
});
