// Author: 	Sandipan Aich
// FileName:	maps99.js
// ClassName:	Maps99
//Description:	This class contains all the utility functions related to the Display of the map 
//		in the various areas in our site like Search Results Page,Property Description Page. etc.


function Maps99(latitude,longitude,zoomLevel,markerType)
{
	this.latitude 	= latitude;
	this.longitude	= longitude;
	this.zoomLevel	= zoomLevel;
	this.width	=500;
	this.height	=500;
	this.icon;
	this.markerType = markerType;
	this.readyToMark = 0;
	this.marked	= 0;
	this.divid = "";
	this.marker;
	this.mapTypeControl;
	this.largeMapControl
	this.marker_user_default_type;
	this.infowindowcontent;
	this.showInfoWin = false;
}
Maps99.prototype.setInfoWinDisplay = function(flag)
{
	this.showInfoWin = true;
}
Maps99.prototype.setSize = function(width,height)
{
	this.width = width;
	this.height = height;
}
Maps99.prototype.addLargeMapControl = function()
{
	this.largeMapControl = new GLargeMapControl();
	this.map.addControl(this.largeMapControl);
}
Maps99.prototype.setInfoWindowContent = function(str)
{
	if(str == '')
		return false;
	this.infowindowcontent = str;
}
Maps99.prototype.addMapTypeControl = function()
{
        this.mapTypeControl = new GMapTypeControl();
        this.map.addControl(this.mapTypeControl);
}

Maps99.prototype.showInfoWindow = function()
{
	if(this.showInfoWin)
	this.marker.openExtInfoWindow(this.map,"google_map_window",this.infowindowcontent,{beakOffset: 3});
}

Maps99.prototype.showMap=function(divid)
{
	if(typeof GMap2 != 'function') {
		return js.setTimeout(this,this.showMap,200,divid);
	}
	this.divid = divid;
	this.map = new GMap2(document.getElementById(this.divid),{size:new GSize(this.width,this.height)});
	this.map.addControl(new GScaleControl()); 
	this.mapLatLong =new GLatLng(this.latitude,this.longitude);
	this.map.setCenter(this.mapLatLong,this.zoomLevel);
	this.icon = new GIcon(G_DEFAULT_ICON);
	this.icon.image = "/images/pointer_maps.gif";
	if(this.markerType == 'draggable')
	this.map.addOverlay(this.marker = new GMarker(new GLatLng(this.latitude,this.longitude),{icon:this.icon, draggable:true}));
	else
	this.map.addOverlay(this.marker = new GMarker(new GLatLng(this.latitude,this.longitude),{icon:this.icon}));
	var This = this;
	/*GEvent.addListener(this.map,"tilesloaded", function()
	{
		if(document.getElementById("copyright"))
		document.getElementById("copyright").innerHTML = "";
	});*/

	GEvent.addListener(this.map,"click", function(overlay,latlng){
	if (latlng) {
		This.latitude = latlng.lat();
		This.longitude = latlng.lng();
		This.zoomLevel = This.map.getZoom()
          }
	if(This.readyToMark == 1)
		{
		This.map.clearOverlays();
		if(This.markerType == 'draggable')
		This.map.addOverlay(This.marker = new GMarker(new GLatLng(This.latitude,This.longitude),{draggable:true,icon:This.icon}));
		else
		This.map.addOverlay(This.marker = new GMarker(new GLatLng(This.latitude,This.longitude),{icon:This.icon}));
		}
        });
	GEvent.addListener(this.marker, "click", function(latlng) {
		This.showInfoWindow();
		//This.marker.openExtInfoWindow(This.map,"google_map_window",str,{beakOffset: 3});
		});

	if(this.markerType = 'draggable')
	{
	GEvent.addListener(this.marker, "dragend", function(latlng) {
		This.latitude = latlng.lat();
		This.longitude = latlng.lng();
		This.zoomLevel = This.map.getZoom();
        });
	}	
}
Maps99.prototype.setLat = function(latitude)
{
	if(!isNum(latitude) || (latitude < -90) || (latitude > 90))
	return false;
	else
	{
		this.latidude = latitude;
		return true;
	}
}
Maps99.prototype.setLng = function(longitude)
{
	if(!isNum(longitude) || (longitude < -180) || (longitude > 180))
	return false;
	else
	{
		this.longitude = longitude;
		return true;
	}
}
Maps99.prototype.setReadyToMark = function()
{
	this.readyToMark = 1;
}
Maps99.prototype.removeAllMarker = function()
{
	this.map.clearOverlays();
}

Maps99.prototype.getLat = function()
{
	return this.latitude;
}
Maps99.prototype.getLng = function()
{
	return this.longitude;
}

Maps99.prototype.disableGoogleBar = function()
{
	this.map.disableGoogleBar();
}
Maps99.prototype.removeAllControls = function()
{
	this.map.removeControl(this.mapTypeControl);
	this.map.removeControl(this.largeMapControl);
}
Maps99.prototype.disableMap = function()
{
	this.removeAllControls();
	this.map.disableDragging();
	this.map.disableInfoWindow();
	this.map.disableDoubleClickZoom();
	this.map.disableScrollWheelZoom();
	this.showInfoWin = false;
}
Maps99.prototype.getZoomLevel = function()
{
	return this.zoomLevel;
}

Maps99.prototype.setMarker_user_default_type = function(type) {
	this.marker_user_default = type;
}

Maps99.prototype.getMarker_user_default_type = function () {
	 return this.marker_user_default;
}
