// Force SVG on also on Linux and BSD machines
	 
	
	
	 if(navigator.platform.match(/linux|bsd/i)) {
	  _mSvgEnabled = _mSvgForced = true;
	 }
	
	var ne = -1;
	var sw;
	var s = 0;
	var last;
	var lstart;
	var lend;
	//Icons
	var normal;
	var ia;
	var iam = [];
	var ci;
	var cim = [];
	var tooltip=document.createElement("div");
	var url = document.createElement("div");
	
	var om;
	var myToggle=1;
	var setCenter = 1;
	
	var customMarker = [];
	var customHash = [];
	var customMarkerCounter=0;
	var po = 0;
	var currentType= '';
	var zListener =0;
	var mysptd=0;
	
	 //takes latlng for the specific property location.
	 function initialize(lat, lng) {
      if (GBrowserIsCompatible()) {
		om = new OverlayMessage(document.getElementById('map_canvas'));      
        m3 = new GMap2(document.getElementById("map_canvas"));
        m3.setCenter(new GLatLng(lat,lng), 11);
		m3.addControl(new GSmallMapControl());
		//m3.addControl(new doappZoom());
		m3.enableScrollWheelZoom();
		//searchLocationsNear();
		initIcons();
		
		/*
		var zoomPlus = document.getElementById('zoomPlus');
		var zoomMinus = document.getElementById('zoomMinus');
		
		GEvent.addDomListener(zoomPlus, "click", function() {zoomIn();});
		GEvent.addDomListener(zoomMinus, "click", function() { zoomOut(); });
		GEvent.addListener(m3, "zoomend", function() { setZoom(this.getZoom()) });		*/
		// tooltip
		
		m3.getPane(G_MAP_FLOAT_PANE).appendChild(tooltip);
		tooltip.style.visibility="hidden";
		clearmessage();
		
	  }
    } 
	
	
	
	
	
  	function zoomIn(){
		if(zListener==0){
			m3.zoomIn(); zListener=1;
		}		
	}
	
	function zoomOut(){
		if(zListener==0){
			m3.zoomOut(); 
			zListener=1;
		}
	}
  
	// remove the loading message when the page has finished loading
	function clearmessage() {
		om.Clear();
	}
	
	
	
	function initIcons(){
		normal = new GIcon();
		normal.image = "House.png";
		normal.iconSize = new GSize(25,28);
		normal.iconAnchor = new GPoint(5, 24);
		ia = new GIcon();
		ci = new GIcon();
		sh = new GIcon();
		sc = new GIcon();
		ba = new GIcon();
		co = new GIcon();
		en = new GIcon();
		fr = new GIcon();
		ga = new GIcon();
		gr = new GIcon();
		ho = new GIcon();
		ht = new GIcon();
		li = new GIcon();
		of = new GIcon(); // HERE
		po = new GIcon();
		re = new GIcon();
		rs = new GIcon();
		tr = new GIcon();
		wo = new GIcon();
		sh.image = "images/searchMap/PointedIcons/shopping.png";
		sc.image = "images/searchMap/PointedIcons/schools.png";
		ba.image = "images/searchMap/PointedIcons/bank.png";		
		ci.image = "images/searchMap/PointedIcons/child_care.png";
		co.image = "images/searchMap/PointedIcons/coffee.png";
		en.image = "images/searchMap/PointedIcons/entertainment.png";
		fr.image = "images/searchMap/PointedIcons/fire_rescue.png";
		ga.image = "images/searchMap/PointedIcons/gas.png";
		gr.image = "images/searchMap/PointedIcons/grocery.png";
		ho.image = "images/searchMap/PointedIcons/hospital.png";
		ht.image = "images/searchMap/PointedIcons/hotel.png";
		li.image = "images/searchMap/PointedIcons/library.png";
		of.image = 'images/searchMap/PointedIcons/offender.png'; // HERE
		po.image = "images/searchMap/PointedIcons/police.png";
		ia.image = "images/searchMap/PointedIcons/postoffice.png";		
		re.image = "images/searchMap/PointedIcons/recreation.png";
		rs.image = "images/searchMap/PointedIcons/restaurant.png";
		tr.image = "images/searchMap/PointedIcons/transportation.png";
		wo.image = "images/searchMap/PointedIcons/worship.png";
		ia.iconSize = new GSize(31,38);
		ci.iconSize = new GSize(31,38);
		sh.iconSize = new GSize(31,38);
		sc.iconSize = new GSize(31,38);
		gr.iconSize = new GSize(31,38);
		ba.iconSize = new GSize(31,38);
		co.iconSize = new GSize(31,38);
		en.iconSize = new GSize(31,38);
		fr.iconSize = new GSize(31,38);
		ga.iconSize = new GSize(31,38);		
		ho.iconSize = new GSize(31,38);
		ht.iconSize = new GSize(31,38);	
		li.iconSize = new GSize(31,38);	
		of.iconSize = new GSize(31,38);	
		po.iconSize = new GSize(31,38);
		re.iconSize = new GSize(31,38);
		rs.iconSize = new GSize(31,38);
		tr.iconSize = new GSize(31,38);
		wo.iconSize = new GSize(31,38);
		ia.iconAnchor = new GPoint(5, 38);
		ci.iconAnchor = new GPoint(5, 38);
		sh.iconAnchor = new GPoint(5, 38);
		sc.iconAnchor = new GPoint(5, 38);
		gr.iconAnchor = new GPoint(5, 38);
		ba.iconAnchor = new GPoint(5, 38);
		co.iconAnchor = new GPoint(5, 38);
		en.iconAnchor = new GPoint(5, 38);
		fr.iconAnchor = new GPoint(5, 38);
		ga.iconAnchor = new GPoint(5, 38);
		ho.iconAnchor = new GPoint(5, 38);
		ht.iconAnchor = new GPoint(5, 38);
		li.iconAnchor = new GPoint(5, 38);
		of.iconAnchor = new GPoint(5, 38);
		po.iconAnchor = new GPoint(5, 38);
		re.iconAnchor = new GPoint(5, 38);
		rs.iconAnchor = new GPoint(5, 38);
		tr.iconAnchor = new GPoint(5, 38);
		wo.iconAnchor = new GPoint(5, 38);
		
		
	}

	
	
	
	function showTooltip(marker) {
		var point=m3.getCurrentMapType().getProjection().fromLatLngToPixel(m3.fromDivPixelToLatLng(new GPoint(4,-17),true),m3.getZoom());
		var offset=m3.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),m3.getZoom());
		var anchor=marker.getIcon().iconAnchor;
		var width=marker.getIcon().iconSize.width;
		var height=39;
		var pos = '';
		var mh = -17;
		var mw = 4;
		var ml = marker.len;
		var mll = marker.getLatLng();
		var pp = m3.fromLatLngToDivPixel(mll);
		pp.x = pp.x - mw;
		pp.y = pp.y - mh;
		var mb = m3.getBounds();
		var lcLL = new GLatLng(mb.getSouthWest().lat(), mb.getNorthEast().lng());
		var lcp = m3.fromLatLngToDivPixel(lcLL);
		var pfse = myPs(pp, lcp);
		var fas = Math.abs(parseInt(pfse.x));
		var direction_horizontal = 'right';
		if ((fas-18) < ml){
			direction_horizontal = 'left';
		}
		if (direction_horizontal == 'right'){ 
			pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height));
			tooltip.innerHTML = marker.tooltip;
		}
		else {
			pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize((offset.x - point.x - anchor.x - ml + 13), offset.y - point.y -anchor.y -height));
			tooltip.innerHTML = marker.leftTip;
		}
		pos.apply(tooltip);
		tooltip.style.visibility="visible";
	}
	
	function myPs(a, b) {
   	 return new GPoint(a.x - b.x, a.y - b.y);
	}
	
	
   
	
	function setZoom(zoomLevel){
		var zl = 1;
		var i=3;
		while(i<zoomLevel){
			document.getElementById('zoom' + zl).style.backgroundImage='url(images/zoomBar/overlay_' + zl+'.png)';
			zl+=1;
			i+=2;
		}
		zl = 8;
		i=19;
		while(i>zoomLevel){
			document.getElementById('zoom' + zl).style.backgroundImage='url(images/zoomBar/zoom_' + zl+'.png)';
			zl-=1;
			i-=2;
		}
	}
	//For Searching m3.lick on the next point.

	
	
	



function m3Offenders(json, num){
	for (n=0; n < json.offenders.length; n++ ) {
			var point =  json.offenders[n].point;
			customMarker[currentType][customMarkerCounter] = createCustomMarker(point, json.offenders[n].address, json.offenders[n].name);
			m3.addOverlay(customMarker[currentType][customMarkerCounter]);
			GEvent.addListener(customMarker[currentType][customMarkerCounter],'mouseover',function(){showTooltip(this); });
			GEvent.addListener(customMarker[currentType][customMarkerCounter],'mouseout',function(){tooltip.style.visibility="hidden"; });
			customMarkerCounter++;
	}
	//customMarkerCounter+=8;
	
	customHash[currentType]=customMarker[currentType].length;
	currentType='';
	customMarkerCounter=0;
		
}



function togglePOI(poi, start, text){	
	if(mysptd==0){
		mysptd=1;
		currentType = poi;
		//alert(customHash[poi]);
		if(start==0 && customHash[poi]!=undefined){
			for(ab=0;ab<customHash[poi]; ab++){
				m3.removeOverlay(customMarker[currentType][ab]);
			}
			delete(customHash[poi]);
			var imgsrc=	document.getElementById(text);
			newSrc = imgsrc.src.replace('Color', 'GreyIcon');
			imgsrc.src = newSrc;
			mysptd=0;
		}
		else if(text=='Offender'){
			if(start==0){
				customMarker[currentType] = [];
				var imgsrc=	document.getElementById(text);
				newSrc = imgsrc.src.replace('GreyIcon', 'Color');
				imgsrc.src = newSrc;
			}	
			var newScript = document.createElement('script');
			newScript.type = 'text/javascript';
			var source = 'getOffender.php';	
			//source += '&callback=loadPOI'; // Set our callback function.
			newScript.src = source;
			document.getElementsByTagName('head')[0].appendChild(newScript);
		}
		else {
			if(start==0){
				customMarker[currentType] = [];
				var imgsrc=	document.getElementById(text);
				newSrc = imgsrc.src.replace('GreyIcon', 'Color');
				imgsrc.src = newSrc;
			}		
			var newScript = document.createElement('script');
			newScript.type = 'text/javascript';
			var center = m3.getCenter().toString();
			center = center.replace(/\(|\)| /g,'')
			var sspn = m3.getBounds().toSpan().toUrlValue();
			var source = 'http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q='+poi+'&sll='+center+'&sspn='+sspn+'&rsz=large&start='+start;	
			source += '&callback=loadPOI'; // Set our callback function.
			newScript.src = source;
			document.getElementsByTagName('head')[0].appendChild(newScript);	
		}
	}
}

function loadPOI(json){
	for (n=0; n < json.responseData.results.length; n++ ) {
			var point = new GLatLng(json.responseData.results[n].lat, json.responseData.results[n].lng);
			customMarker[currentType][customMarkerCounter] = createCustomMarker(point, json.responseData.results[n].streetAddress, json.responseData.results[n].titleNoFormatting);
			m3.addOverlay(customMarker[currentType][customMarkerCounter]);
			GEvent.addListener(customMarker[currentType][customMarkerCounter],'mouseover',function(){showTooltip(this); });
			GEvent.addListener(customMarker[currentType][customMarkerCounter],'mouseout',function(){tooltip.style.visibility="hidden"; });
			customMarkerCounter++;
	}
	//customMarkerCounter+=8;
	if(customMarkerCounter<32){
		mysptd=0;
		togglePOI(currentType, customMarkerCounter);	
	}
	else {
		mysptd=0;
		customHash[currentType]=customMarker[currentType].length;
		currentType='';
		customMarkerCounter=0;
	}
	
	
}

function createCustomMarker(point, addr, name){
	if(currentType=='banks'){
		var marker = new GMarker(point, {icon:ba});
	}
	else if(currentType=='child care'){
		var marker = new GMarker(point, {icon:ci});
	}
	else if(currentType=='coffee'){
		var marker = new GMarker(point, {icon:co});
	}
	else if(currentType=='entertainment'){
		var marker = new GMarker(point, {icon:en});
	}
	else if(currentType=='Fire Department'){
		var marker = new GMarker(point, {icon:fr});
	}
	else if(currentType=='gas station'){
		var marker = new GMarker(point, {icon:ga});
	}
	else if(currentType=='grocery'){
		var marker = new GMarker(point, {icon:gr});
	}
	else if(currentType=='hospitals'){
		var marker = new GMarker(point, {icon:ho});
	}
	else if(currentType=='hotels'){
		var marker = new GMarker(point, {icon:ht});
	}
	else if(currentType=='library'){
		var marker = new GMarker(point, {icon:li});
	}
	else if(currentType=='offender'){
		var marker = new GMarker(point, {icon:of});
	}
	else if(currentType=='police station'){
		var marker = new GMarker(point, {icon:po});
	}
	else if(currentType=='postoffice'){
		var marker = new GMarker(point, {icon:ia});
	}
	else if(currentType=='parks'){
		var marker = new GMarker(point, {icon:re});
	}
	else if(currentType=='restaurant'){
		var marker = new GMarker(point, {icon:rs});
	}
	else if(currentType=='transportation'){
		var marker = new GMarker(point, {icon:tr});
	}
	else if(currentType=='churches'){
		var marker = new GMarker(point, {icon:wo});
	}
	else if(currentType=='schools'){
		var marker = new GMarker(point, {icon:sc});
	}
	else if(currentType=='shopping'){
		var marker = new GMarker(point, {icon:sh});
	}
	name = nameCheck(name);
	var strLength = name.length;
	strLength=(strLength*4)+65;
	marker.len = strLength;
	marker.leftTip = '<div class="ttContainer" style="width:'+strLength+';"><div class="ttConLeft"><div class="ttPriceLeft">&nbsp;<br /><span style="font-size:9px;">'+name+'</span></div></div><div class="ttFroLeft"></div></div>'
	marker.tooltip = '<div class="ttContainer" style="width:'+strLength+';"><div class="ttFro"></div><div class="ttCon"><div class="ttPrice">&nbsp;<br /><span style="font-size:9px;">'+name+'</span></div></div></div>';
	  return marker;
}

function nameCheck(n){
	if(n.length>28){
		n= n.substr(0,28);
		n+='...';
	}
	return n;
}


function next(){
	s=parseInt(s)+10;
	searchLocationsNear();
}
function paging(val){
	s=parseInt(val);
	searchLocationsNear();
}
function prev(){
	s=parseInt(s)-10;
	searchLocationsNear();
}

