/*
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 = 8;		//default zoom level
	
	this.defLat = '42.366662';	//default latitude
	this.defLng = '-71.106262';	//default longitude
	this.defPCode = '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.showCustom = 1;
	
	this.mapDivObj = '';	//the object from the map id
	this.mapObj = '';		//main map object
	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.myDetails = new Array();

	this.pollArr = new Array();
	
	// function to load the map
	this.loadMap = function () {
		if (GBrowserIsCompatible()) {
			this.mapDivObj = document.getElementById(this.mapDivId);
			this.mapObj = new GMap2(this.mapDivObj);
			if (this.showCustom==1) this.customOpt();
			this.mapObj.setMapType(G_PHYSICAL_MAP); 
			if (this.defUseLatLng==1) { 
				this.mapLat = this.defLat;
				this.mapLng = this.defLng;
				this.plotLoc(this.defLat, this.defLng, this.defZoom);
				this.drawMarker(this.defLat, this.defLng);
			}else{
				this.convLatLng_PCode(this.defPCode);
			}
			this.mapBaseIco = new GIcon(G_DEFAULT_ICON);
			this.mapBaseIco.iconSize = new GSize(24, 23);
			this.mapBaseIco.shadowSize = new GSize(0,0);
			this.mapBaseIco.iconAnchor = new GPoint(9, 34);
			this.mapBaseIco.infoWindowAnchor = new GPoint(9, 2);
			if (this.goToFunc) eval(this.goToFunc + '()');
			//alert(this.mapObj.getBounds().toSpan().toUrlValue());
		}		
	};
	
	//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(); 
		}
	};
	
	this.drawMarker = function (lati, lngi) {
		var imgMarker = new GIcon(G_DEFAULT_ICON);
		//imgMarker.image = 'http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png';
		// imgMarker.iconSize = new GSize(24, 23);
		// imgMarker.shadowSize = new GSize(0,0);
		// imgMarker.iconAnchor = new GPoint(9, 34);
		var marker = new GMarker(new GLatLng(lati, lngi), imgMarker);
		marker.mapObj = this;
		marker.extVars = new Array();
		marker.extVars['defTitle'] = this.defTitle;
		marker.extVars['defTxT'] = this.defTxT;
		
		if (this.defDetailsWin==1) {
			this.showLoc(marker);
			GEvent.addListener(marker, "click", function() { 
				marker.mapObj.showLoc(marker);
			});
		}else{
			GEvent.addListener(marker, "click", function() { 
				document.location.href='#myGMAP';
			});
		}
		
		this.mapObj.addOverlay(marker);
		
		
	};
	
	this.plotLoc = function (lati, lngi, zoomLvL) {
		this.mapObj.setCenter(new GLatLng(lati, lngi), zoomLvL);
	};
	
	this.convLatLng_PCode = function (pCode) {
		var srcObj = new GlocalSearch();
		srcObj.mapObj = this;
		srcObj.setSearchCompleteCallback(null, 
			function() {
		      	if (srcObj.results[0]) {
					gMapPlotLoc(srcObj);
				}else{
					if (srcObj.mapObj.defPCodeFail) eval(srcObj.mapObj.defPCodeFail + '()');
				}
			});  
		srcObj.execute(pCode);
	};
	
	this.clearMap = function () {
		this.mapObj.clearOverlays();
		this.latLng = new Array();
		this.drawMarker(this.mapLat, this.mapLng);
	};
	
	this.cleanMap = function () {
		this.mapObj.clearOverlays();
	};
	
	this.cleanWindows = function () {
		this.mapObj.closeExtInfoWindow();
	}
	
	this.showLoc = function (markerObj){
		infoDiv = document.createElement("div");
		infoDiv.style.height = '120px';
		infoDiv.style.width = '300px';
		infoDiv.style.textAlign = 'left';

		infoDiv.innerHTML = "<div style='font-weight:bold;color:#2080b0;font-family:Tahoma,Arial,Helvetica;font-size:13px;'>" + markerObj.extVars['defTitle'] + "</div>";
		infoDiv.innerHTML = infoDiv.innerHTML + "<div style='height:5px;line-height:5px;'>&nbsp;</div>";
		infoDiv.innerHTML = infoDiv.innerHTML + "<div style='font-weight:normal;color:#2080b0;font-family:Tahoma,Arial,Helvetica;font-size:12px;'>" + markerObj.extVars['defTxT'] + "</div>";
		infoDiv.innerHTML = infoDiv.innerHTML + "<div style='height:5px;line-height:5px;'>&nbsp;</div>";
		
		markerObj.openInfoWindow(infoDiv);
	}
	
}
window.onunload = "GUnload()";
