// JavaScript Document

//The delcarations in capitals are constants available for use by calling programs
//They control various aspects of how the map is displayed

var SHOW_ZOOM_CONTROL=true;
var NO_SHOW_ZOOM_CONTROL=false;

var LARGE_ZOOM=false;
var SMALL_ZOOM=true;

var SHOW_TYPE=true;
var NO_SHOW_TYPE=false;

var SHOW_OVERVIEW=false;
var NO_SHOW_OVERVIEW=true;

var map;
var iconpath='';

window.onunload = unloadmap;  //Specify a function to call when the page unloads

function unloadmap(){         //Call this function when page unloads to ensure no memory leaks affect Google Map
	GUnload();
}

function registericonpath(p){  //Short cut function to regiter the icon path to save repating it in each call to
	iconpath=p;				   //drawicon
}

//This function must be called before any attempt to draw icons on the map

//lat		the latitude as a decimal 
//lng		the longitude as a decimal
//zlevel	the starting zoomlevel for the map 
//showz		whether to show the zoom control (use the constants above to set the value)
//zlarge	the size of the soom control (use constants above)
//showt		whether to show the Map Type control (use constants above)
//showo		whether to show the Overview control (use constants above)

//Example  startmap(51.6516,-1.9046, 13,SHOW_ZOOM_CONTROL,SMALL_ZOOM,SHOW_TYPE,SHOW_OVERVIEW);


function startmap(lat,lng, zlevel,showz,zlarge,showt,showo){
	if (GBrowserIsCompatible())
	{
		var point = new GLatLng(lat,lng);
		map = new GMap2(document.getElementById("map"));
		map.setCenter(point,zlevel);
		
	if (showz)								 		 //Will we show the zoom/pan control
		if (zlarge)										//Large or small zoom/pan control
			map.addControl(new GLargeMapControl());
		else
			map.addControl(new GSmallMapControl());
		
		if (showt)								  	//Will we show the map type control
		map.addControl(new GMapTypeControl());
	
	if (showo)										//Will show the Overview control
		map.addControl(new GOverviewMapControl());
	}
}

//This function places an icon marker on the map

//id	 numeric (the id of the icon - not currently used and I might remove this)
//info	 Popup Info (string) used to set the text displayed when an icon is clicked may be left blank which means the icon will not respond to clicks
//iname	 string - the filename of the icon file ( if registerpath has been used) or the full path name URL to the icon file
//iw	 numeric - the width of the icon in pixels
//ih	 numeric - the height of the icon in pixels
//sname	 string - the filename of the shadow icon file ( if registerpath has been used) or the full path name URL to the shadow icon file (may be left blank)
//sw	 numeric - the width of the shadow icon
//sh	 numeric - the height of the shadow icon
//lat	 numeric - the latitude of the shadow icon
//lng	 numeric - the longitude of the shadow icon


function drawicon(id,info,iname,iw,ih,sname,sw,sh,lat,lng){
	
	var icw=iw/2;		//Calculate the centre of the icon in pixels
	var ich=ih/2;
	var point=new GLatLng(lat,lng); //Create a point object for the position
	
	var img=new GIcon();		//Cretae the icon object
	img.image=iconpath+iname;	//assign it's image pathname URL
	img.iconSize=new GSize(iw,ih);	//Set the icon size
	img.iconAnchor=new GPoint(icw,ich);	//set the icon anchor point
	img.infoWindowAnchor=new GPoint(icw,ich);	//set the info popup anchor point

	if (sname!=""){							//Do we want to display a shadow
		img.shadow = iconpath+sname;
		img.shadowSize =  new GSize(sw, sh);
		}

	var marker = new GMarker(point,img); 	//Create the marker object with the coordinates and icon

	map.addOverlay(marker);		//Add it to the map
	
	if (info!=''){				//Is there text in the info parameter
		GEvent.addListener(marker, "click", function() {	//Yes: Create the info window obkject
    	marker.openInfoWindowHtml(info);
  		});
	}
}

