// This scripts includes the common google map api functions
// Author: beesheer
// Created: June 21, 2007
// You can use this script freely. Just leave beesheer there, thanks


// Declare the global vars
var map;			// The Map
var geoXml;			// The Kml which will be loaded
var geoCoder;		// The Geo Information from  Google Geocoder
var baseIcon = new GIcon();
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);
var markerArray = []; //This is the marker array
var centerPoint; //This is the center point of the map



function createMarker(i, point) {
	var marker;
	var icon = new GIcon(baseIcon);
	//var letter = String.fromCharCode("A".charCodeAt(0) + i);
	icon.image = "http://www.google.com/mapfiles/marker.png";

	if (false) // i == 0)
		marker = new PdMarker(point);
	else
		marker = new PdMarker(point, icon);

	if (pointTitle[i].length > 0)
		marker.setTooltip(pointTitle[i]);
	
	var rowId = 'row'+ i;
	//record the marker
	markerArray[i] = marker;
	//standard marker
	marker.setHoverImage("http://www.google.com/mapfiles/dd-start.png");
	GEvent.addListener(marker, "click", function() {window.location = pointLink[i];});
	//GEvent.addListener(marker, "mouseover", function() {document.getElementById(rowId).style.border = '2px solid red';});
	//GEvent.addListener(marker, "mouseout", function() {document.getElementById(rowId).style.border = 'none';});
	return marker;
}


function loadSearchMap ()
{
	map = new GMap2(document.getElementById("googleMap"));
	map.setCenter(new GLatLng(0,0),1);
	map.addControl(new GSmallMapControl());
	for (i=0; i<pointTitle.length; i++)
	{
		if(pointLon[i] != 0 && pointLat[i] !=0)
		{
		var imageHTML = (pointImage[i]=='')?'':('<br />' + '<a href="'+ pointLink[i] + '">' + '<img src="'+pointImage[i]+'" style="height: 100px; border:0;" /></a>');
		var htmlString = '<h2><a href="'+pointLink[i]+'"><b>' + pointTitle[i] + '</b></a></h2>' + pointDetail[i] + imageHTML + '<br />'+'<a href="'+pointLink[i]+'" style="color:green;">I am living here! Check it out &gt;&gt;</a>'; 
		var marker = createMarker(i, new GPoint(pointLon[i],pointLat[i]), htmlString );
		//alert(i);
		map.addOverlay(marker);
		}
	}
	if(markerArray.length == 0)
	{toggleMap();}
	else
	{map.zoomToMarkers(10);}
	//alert("finished loading markers");
}