var map;
var marks = [];
var loc;

function GetWindowWidthHeight () {
	var myWidth = 0, myHeight = 0;
	if(typeof(window.innerWidth) == 'number')
	{
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	return {'width' : myWidth, 'height' : myHeight};
}

function sizeMap (s) {
	var w = GetWindowWidthHeight().width;
	var h = GetWindowWidthHeight().height;
	
	center_w = w/2;
	$('map').style.top = 20+'px'; 
	$('map').style.left = 0+'px';  
	$('map').style.width=w+'px'; 
	$('map').style.height=(h-20)+'px';
}

window.onresize = function() { sizeMap() };

window.onload = addCodeToFunction(window.onload,function() {
	
	if (GBrowserIsCompatible()) {    
		sizeMap('normal');
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.enableScrollWheelZoom();
		window.setTimeout(doMarkers, 0);
	} else {
		alert("Sorry, your browser isn't compatible with Jaikuvision!")
	}
});

function doMarkers(){
	if(loc){
		Element.show('msg'); Element.show('loading');
		new Ajax.Request('/backend/find-markers.php', 
			{method:'post',postBody:'loc='+loc, onSuccess : function(response) {
				eval(response.responseText);
			}}
		);
	}else{
		Element.show('msg');
		Element.show('search');
	}
}