/*
GOOGLE MAP CLASS
*/
function gMap() {
	this.mapDivId = '';		//div id where the map will be drawn
	this.mapHt = '400px';	//height of the map div
	this.mapWt = '400px';	//width of the map div
	this.defZoom = 15;		//default zoom level
	
	this.defLat = '51.471437';	//default latitude
	this.defLng = '-0.206576';	//default longitude
	this.defAddr = 'B73 5SR';			//default post code
	this.defUseLatLng = 0;			//1 - use default lat long ; 0 - plot default via post code
	this.defPCodeFail = '';
	this.defDetailsWin = 1;
	this.defDetailsWinLoad = false;
	
	this.mapDivObj = '';	//the object from the map id
	this.mapObj = '';		//main map object
	this.mapGeoCoderObj = '';
	this.mapLat = '';		//main map latitude
	this.mapLng = '';		//main map longitude
	this.mapBaseIco = '';	//main map base icon
	
	this.custMType = true;					//show custom controls
	this.custMBtn = 'true||true';			//hybrid, sattelite
	this.custScroll = false;				//scrolling allowed
	
	this.latLng = new Array();				//store all the lat and long to plot [lat, long]
	this.goToFunc = '';
	this.searchMode = 0;
	this.serviceId = 0;
	this.myDetails = new Array();
	
	this.pollArr = new Array();
	
	this.cntFunc = '';	//this is for loading the contacts after the map is plotted
	
	this.gMapLatLng = new Array();
	this.gMapLatLng['latlng'] = new Array();
	
	this.defMarkerObj = '';
	this.contMarker = new Array();
	this.contCnt = 0;
	
	// function to load the map
	this.loadMap = function () {
		if (GBrowserIsCompatible()) {
			this.mapDivObj = document.getElementById(this.mapDivId);
			this.mapObj = new GMap2(this.mapDivObj);
			this.mapGeoCoderObj = new GClientGeocoder();
			this.customOpt();
			if (this.defUseLatLng==1) { 
				this.mapLat = this.defLat;
				this.mapLng = this.defLng;
				this.plotLoc(this.defLat, this.defLng, this.defZoom);
				this.defMarker(this.defLat, this.defLng);
			}else{
				this.defAddr_LatLng(this.defAddr);
			}
			if (this.goToFunc) eval(this.goToFunc + '()');
			var thisObj = this;
		}		
	};
	
	//function to customize the map
	this.customOpt = function () {
		if (this.custMType == true) {
			var xBtn = this.custMBtn.split("||");
			var customUI = this.mapObj.getDefaultUI();
			customUI.maptypes.hybrid = (xBtn[0] == 'false') ? false : true;
			customUI.maptypes.satellite = (xBtn[1] == 'false') ? false : true;
			this.mapObj.setUI(customUI);
			
			if (this.custScroll == false) this.mapObj.disableScrollWheelZoom(); 
		}
	};
	
	//load the default marker
	this.defMarker = function (lati, lngi) {
		var imgMarker = new GIcon(G_DEFAULT_ICON);
		imgMarker.shadow = "http://www.google.com/mapfiles/shadow50.png";
		imgMarker.iconSize = new GSize(20, 34);
		imgMarker.shadowSize = new GSize(37,34);
		imgMarker.iconAnchor = new GPoint(9, 34);
		var marker = new GMarker(new GLatLng(lati, lngi), imgMarker);
		this.defMarkerObj = marker;
		marker.gMapObj = this;
		marker.exVars = new Array();
		marker.exVars['lati'] = lati;
		marker.exVars['lngi'] = lngi;
		
		var thisObj = this;
		
		// if (this.defDetailsWin==1) {
			// var infoDiv = document.createElement('div');
			// var txtObj = document.createTextNode('Fetching location...');
			// infoDiv.appendChild(txtObj);
			// this.mapObj.openInfoWindow(this.mapObj.getCenter(), infoDiv);
		// }
		this.mapObj.addOverlay(marker);
	};
	
	this.loadDefMarker = function () {
		//if (this.defMarkerObj) this.defMarkerObj.openInfoWindow(this.mapObj, 'custom_info_window_red', this.loadTemplate(this.defMarkerObj), {beakOffset: 9});
	};
	
	
	//plot the location given the latitude and longitude
	this.plotLoc = function (lati, lngi, zoomLvL) {
		this.mapObj.setCenter(new GLatLng(lati, lngi), zoomLvL);
	};
	
	// function to clear the map
	this.clearMap = function () {
		this.mapObj.clearOverlays();
		this.latLng = new Array();
		this.defMarker(this.mapLat, this.mapLng);
	};
	
	// function to clean the windows
	this.cleanWindows = function () {
		this.mapObj.closeExtInfoWindow();
	};
	

}

if (document.getElementById('gMap')) {
	var gMapObj = new gMap();
	gMapObj.mapDivId = "gMap";
	gMapObj.mapHt = "380px";
	gMapObj.mapWt = "400px";
	gMapObj.defUseLatLng = 1;
	gMapObj.loadMap();
}

window.onunload = "GUnload()";