var menuExpanded = false;

$(document).ready(function () {
	$("#dd_body div").bind("mouseenter", function () { inout(this.id, 1); });
	$("#dd_body div").bind("mouseleave", function () { inout(this.id, 0); });
	$("#el0").bind("mouseenter", function () { inoutHeader(1); }).bind("mouseleave", function () { inoutHeader(0); });
	$("#el1").bind("click", function () { changeType(0); });
	$("#el2").bind("click", function () { changeType(1); });
	$("#el3").bind("click", function () { changeType(2); });
	$("#dd_body").hide();
	$("#dd_header").click(function () { if (!menuExpanded) expand(); else unexpand(1); });
});

function expand() {
	$("#dd_body").slideDown("fast");
	$("#el0").css("background-image", "url('/files/images/gmap/middle_blue_up.png')");
	$("#gm_dropdown .bottom").css("background-image", "url('/files/images/gmap/bottom.gif')");
	menuExpanded = true;
}

function unexpand(fromSelf) {
	$("#dd_body").slideUp("fast");
	$("#el0").css("background-image", "url('/files/images/gmap/middle" + (fromSelf ? "_blue" : "") + ".png')");
	$("#gm_dropdown .bottom").css("background-image", "url('/files/images/gmap/bottom" + (fromSelf ? "_blue" : "") + ".gif')");
	menuExpanded = false;
}

function inoutHeader(dir) {
	if (!menuExpanded) {
		var bg = new Array(), vert = ["top", "middle", "bottom"];
		for (i = 0; i < 3; i++) {
			bg[i] = "url('/files/images/gmap/" + vert[i];
			if (dir)
				bg[i] += "_blue";
			if (i == 1)
				bg[i] += ".png')";
			else
				bg[i] += ".gif')";
		}
		$("#gm_dropdown .top").css("background-image", bg[0]);
		$("#el0").css("background-image", bg[1]);
		$("#gm_dropdown .bottom").css("background-image", bg[2]);
	}
}

function inout(id, dir) {
	var bg = "url('/files/images/gmap/middle"
	if (dir == 1) bg += "_yellow";
	else bg += "_noarrow"
	bg += ".png')";
	document.getElementById(id).style.backgroundImage = bg;
}

function changeType(maptype) {
	var type = [G_NORMAL_MAP, G_SATELLITE_MAP, G_HYBRID_MAP];
	$("#el0").html($("#el" + (maptype + 1)).html());
	map.setMapType(type[maptype]);
	$("#gm_dropdown .top").css("background-image", "url('/files/images/gmap/top.gif')");
	$("#gm_dropdown .bottom").css("background-image", "url('/files/images/gmap/bottom.gif')");
	unexpand(0);
}
