/*TODO: 
- calculate route (partially in the API!) */
google.load("maps", "2.x");
//console.log(google.loader.ClientLocation.latitude+","+google.loader.ClientLocation.longitude);
var width, height;

$(document).ready(function() {
	$("body").append("<div id=\"map_container\"><p class='close'><b onclick='$(\"#map_container\").fadeOut();'>x&nbsp;</b></p><div id=\"mapdiv\"></div></div>");
	if(window.innerWidth) {
		width=window.innerWidth;
		height=window.innerHeight;
	}
	else {
		width=document.documentElement.clientWidth;
		height=document.documentElement.clientHeight;
	}
	height=Math.round(height/1.5);
	width=Math.round(width/2);
	/*$(".close").bind("mousedown", function() {
		$(document).bind("mousemove", function(event) {
			$("#map_container").css({left: event.clientX, top: event.clientY});
		});
	});
	$(document).bind("mouseup", function() {
		$(document).unbind("mousemove");
		$(document).unbind("mousedown");
	});*/
});


//Shows the map at a point Lat,Long with a marker at this point containing desc
function gotoPoint(Lat, Long, desc) {
	if(window.pageYOffset) {
		scrollpos=window.pageYOffset;
	}
	else {
		scrollpos=document.documentElement.scrollTop;
	}
	$("#map_container").css({top: scrollpos+100+"px", width: width, height: height+20});
	var map = new google.maps.Map2(document.getElementById("mapdiv"), {size: new google.maps.Size(width,height)});
	map.setCenter(new google.maps.LatLng(Lat, Long), 15);
	map.addControl(new google.maps.LargeMapControl());
	map.enableScrollWheelZoom();
	var marker = new google.maps.Marker(new google.maps.LatLng(Lat, Long));
	map.addOverlay(marker);
	marker.openInfoWindowHtml(desc);
	google.maps.Event.addListener(marker, "click", function() {marker.openInfoWindowHtml(desc);});
	$("#map_container").fadeIn();
}

