var geoAddress;
var useGif = false;

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	var ieversion=new Number(RegExp.$1)
	if (ieversion==6)
	{
		useGif = true;
	}
}

var geoAddress;

function createEmptyMarker(latLng)
{
	var wifiIcon = new GIcon();
	if(useGif)
	{
		wifiIcon.image = "img/map/wifiSingleIcon.gif";
	} else
	{
		wifiIcon.image = "img/map/wifiSingleIcon.png";
	}
	//wifiIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	wifiIcon.iconSize = new GSize(22, 22);
	//wifiIcon.shadowSize = new GSize(22, 20);
	wifiIcon.iconAnchor = new GPoint(11, 11);
	wifiIcon.infoWindowAnchor = new GPoint(16, 6);
	
	// Set up our GMarkerOptions object literal
	markerOptions = {icon:wifiIcon};
	
	var point = latLng;
	var marker = new GMarker(point, markerOptions);
			
	return marker;
}

function createSingleMarker(id, lat, lng)
{
	var wifiIcon = new GIcon();
	if(useGif)
	{
		wifiIcon.image = "img/map/wifiSingleIcon.gif";
	} else
	{
		wifiIcon.image = "img/map/wifiSingleIcon.png";
	}
	//wifiIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	wifiIcon.iconSize = new GSize(22, 22);
	//wifiIcon.shadowSize = new GSize(22, 20);
	wifiIcon.iconAnchor = new GPoint(11, 11);
	wifiIcon.infoWindowAnchor = new GPoint(16, 6);
	
	// Set up our GMarkerOptions object literal
	markerOptions = {icon:wifiIcon};

	var point = new GLatLng(lat, lng);
	var marker = new GMarker(point, markerOptions);
	
	// Click listener
	GEvent.addListener(marker, "click", function()
	{
		marker.openInfoWindowHtml(infoWindowsList[id]);
	});
	
	return marker;
}

function createMultipleMarker(id, lat, lng, zoom)
{
	var wifiIcon = new GIcon();
	if(useGif)
	{
		wifiIcon.image = "img/map/wifiMultipleIcon.gif";
	} else
	{
		wifiIcon.image = "img/map/wifiMultipleIcon.png";
	}
	//wifiIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	wifiIcon.iconSize = new GSize(39, 36);
	//wifiIcon.shadowSize = new GSize(22, 20);
	wifiIcon.iconAnchor = new GPoint(19, 18);
	wifiIcon.infoWindowAnchor = new GPoint(16, 6);
	
	// Set up our GMarkerOptions object literal
	markerOptions = {icon:wifiIcon};

	var point = new GLatLng(lat, lng);
	var marker = new GMarker(point, markerOptions);
	
	// Click listener
	GEvent.addListener(marker, "click", function()
	{
		moveToZoom(lat, lng, zoom);
	});
	
	return marker;
}

function moveToZoom(lat, lng, zoom)
{
	map.setZoom(parseFloat(zoom));
	map.panTo(new GLatLng(lat, lng));
}

function resizeMap()
{
	h = $(window).height();
	h = h - 145;
	$("div#map").css({'height' : h+'px' });
	
	w = $(window).width();
	if (w < 945) 
	{
		$("div#footer").css({'width' : '945px' });
		$("div#map").css({'width' : '945px' });		
	} else {
		$("div#footer").css({'width' : '100%' });				
		$("div#map").css({'width' : '100%' });		
	}	

	if (map != undefined)
	{
		map.checkResize();
	}
	
	return false;
}

function geoCodeAddress(lt, ln)
{
	var latLng;
	var geocoder;
	geocoder = new GClientGeocoder();
	latLng = new GLatLng(lt, ln);
	
	geocoder.getLocations(latLng, getAddress);
}

function getAddress(response)
{
	if (!response || response.Status.code != 200) 
	{
		//wrong
	} else 
	{
    	place = response.Placemark[0];
		geoAddress = place.AddressDetails.Country.AdministrativeArea.Locality.LocalityName;
		
		document.getElementById("geoAddress").value = geoAddress;
		
		submitAddress();
	}
}