var MapScriptManager={isScriptLoaded:false,scriptUrl:"http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2",callback:null,tryCount:0,infoBoxWidth:320,getScript:function(callback,mapObj){$.getScript(MapScriptManager.scriptUrl,function(){MapScriptManager.isScriptLoaded=true;if(callback&&mapObj){MapScriptManager.callback=callback.bind(mapObj);window.setTimeout("MapScriptManager.invokeCallBack()",500)}$(document.body).append("<style type='text/css'>.ero .ero-body { width:"+MapScriptManager.infoBoxWidth+"px; }</style>")})},invokeCallBack:function(){if(MapScriptManager.tryCount>5||MapScriptManager.callback==null){alert("Virtual Earth Map is temporarily unavailable.");return }MapScriptManager.tryCount++;if(L_invaliddirections_text){MapScriptManager.callback()}else{window.setTimeout("MapScriptManager.invokeCallBack()",500)}}};var MapResizer={resize:function(mapObj,divId){var mapW=0,mapH=0;var mapDiv=document.getElementById(divId);var mapDivOffset=document.cumulativeOffset(mapDiv);var dimensions=document.viewport.getDimensions();mapW=dimensions.width;if(mapW<500){mapW=500}mapH=dimensions.height-mapDivOffset.top;if(mapH<400){mapH=400}mapDiv.style.width=mapW+"px";mapDiv.style.height=mapH+"px";mapObj.map.Resize(mapW,mapH);return }};function NycVEMap(mc,lat,lon,zm,ppt,ppd,rhId,dbSize){this.map=null;this.mapContainer=mc;this.pinID=1;this.latitude=lat;this.longitude=lon;this.zoom=zm;this.pPTitle=ppt;this.pPDesc=ppd;this.routeHolderId=rhId;this.locsInMap=new Array();this.hasMapInit=false;this.shapesInMap=new Array();this.dashboardSize=dbSize;this.setMapContainer=function(mapContainer){this.mapContainer=mapContainer};this.setLatitude=function(latitude){this.latitude=latitude};this.setLongitude=function(longitude){this.longitude=longitude};this.setZoom=function(zoom){this.zoom=zoom};this.setPPTitle=function(pPTitle){this.pPTitle=pPTitle};this.setPPDesc=function(pPDesc){this.pPDesc=pPDesc};this.setRouteHolderId=function(rHId){this.routeHolderId=rHId};this.setDashboardSize=function(dbSize){this.dashboardSize=dbSize};this.getBrowserScrollBottom=function(){var scrollTop=document.body.scrollTop;if(scrollTop==0){if(window.pageYOffset){scrollTop=window.pageYOffset}else{scrollTop=(document.body.parentElement)?document.body.parentElement.scrollTop:0}}var winH=window.innerHeight;if(winH==null||winH=="undefined"){winH=document.body.clientHeight}var scrollBottom=winH+scrollTop;return scrollBottom};this.getMapScrollTop=function(){var me=this;return document.getElementById(me.mapContainer).offsetTop};this.onscrollGetMap=function(callback){var me=this;if(me.hasMapInit){return }var scrollBottom=me.getBrowserScrollBottom();var mapScrollTop=me.getMapScrollTop();if(mapScrollTop<=scrollBottom){me.getMap(callback)}};this.getMap=function(callback){var me=this;if(MapScriptManager.isScriptLoaded){me._getMap(callback)}else{MapScriptManager.getScript(function(){me._getMap(callback)},me)}};this._getMap=function(callback){var me=this;document.getElementById(me.mapContainer).style.textAlign="left";me.map=new VEMap(me.mapContainer);if(me.dashboardSize==null){me.dashboardSize=VEDashboardSize.Normal}me.map.SetDashboardSize(me.dashboardSize);if(me.latitude==null||me.longitude==null||me.zoom==null){me.map.LoadMap(null,null,VEMapStyle.Road,false,VEMapMode.Mode2D,true);if(me.zoom!=null){me.map.SetZoomLevel(me.zoom)}}else{me.map.LoadMap(new VELatLong(me.latitude,me.longitude),me.zoom,VEMapStyle.Road,false,VEMapMode.Mode2D,true);if(me.pPTitle!=null&&me.pPDesc!=null){me.addPin(me.latitude,me.longitude,me.pPTitle,me.pPDesc,"","","","",me.getCustomIcon("veIconStar"))}}window.onunload=function(){me.map.Dispose()};me.hasMapInit=true;if(callback){callback()}};this.setShowDetail=function(isShown){VEPushpin.ShowDetailOnMouseOver=isShown};this.showControl=function(){this.map.ShowDashboard()};this.hideControl=function(){this.map.HideDashboard()};this.getNextPinID=function(){return this.pinID};this.addPin=function(lat,lng,title,desc,iconPath,iconStyle,titleStyle,detailStyle,customIcon){var latlong=new VELatLong(lat,lng);var shape=new VEShape(VEShapeType.Pushpin,latlong);shape.SetTitle(title);shape.SetDescription(desc+"<!--[if lte IE 6.5]><iframe class='cal-select-free'></iframe><![endif]-->");if(iconPath){var icon="";iconStyle+="";if(iconStyle.match(/pushpin/i)){var iconText=iconStyle.toLowerCase().replace(/pushpin/g,"");if(iconText.match(/solo/i)){icon=this.getCustomIcon("veIconStar")}else{icon=this.getCustomIcon("veIconHotel",iconText,"vepp_"+this.pinID)}shape.SetCustomIcon(icon)}else{var img='<img id="vepp_'+this.pinID+'" src="'+iconPath+'"'+(iconStyle!=null?' class="'+iconStyle+'"':"")+" />";shape.SetCustomIcon(img)}}else{if(customIcon){shape.SetCustomIcon(customIcon)}}this.map.AddShape(shape);this.shapesInMap[this.pinID-1]=shape;this.pinID++;var loc=new VELatLong(lat,lng);this.locsInMap.push(loc)};this.getCustomIcon=function(className,text,iconId){var customIcon="<div "+(iconId?"id='"+iconId+"'":"")+" class='"+className+"' onmouseover='mapIconRollover(this)' onmouseout='mapIconRollover(this)'>"+(text?"<span>"+text+"</span>":"")+"</div>";return customIcon};this.deletePin=function(pId){var shape=this.shapesInMap[pId-1];if(shape!=null){this.map.DeleteShape(shape);this.shapesInMap[pId-1]=null}};this.deleteAllPins=function(){this.map.DeleteAllShapes();this.locsInMap=new Array();this.shapesInMap=new Array();this.pinID=1};this.getRoute=function(start,end,isInMiles,isQuickest,isDriving){var me=this;var routeOptions=new VERouteOptions();routeOptions.DistanceUnit=isInMiles?VERouteDistanceUnit.Mile:VERouteDistanceUnit.Mile.Kilometer;routeOptions.RouteOptimize=isQuickest?VERouteOptimize.MinimizeTime:VERouteOptimize.MinimizeDistance;routeOptions.RouteCallback=function(route){me.printRoute(start,end,routeOptions.DistanceUnit,route)};routeOptions.RouteMode=isDriving?VERouteMode.Driving:VERouteMode.Walking;this.deleteAllPins();me.map.GetDirections([start,end],routeOptions)};this.printRoute=function(start,end,distanceUnit,route){var altColors=new Array("#ffffff","#eeeeee");var routeHolder=document.getElementById(this.routeHolderId);var routeHtml="";if(routeHolder==null||route==null||route.RouteLegs[0]==null){return }routeHtml="<div>";routeHtml+="<b>Found starting address:</b> <i>"+start+"</i></div>";routeHtml+="<div>";routeHtml+="<b>Found destination address:</b> <i>"+end+"</i></div>";routeHtml+="<div><br />";routeHtml+="<b>Total Distance:</b> <i>"+route.Distance.toFixed(2)+" "+(distanceUnit==VERouteDistanceUnit.Mile?"miles":"km")+"</i></div>";routeHtml+="<div>";routeHtml+="<b>Total Time:</b> <i>"+(route.Time<3600?Math.ceil(route.Time/60)+" minutes":parseInt(route.Time/3600)+" hours and "+Math.ceil((route.Time%3600)/60)+" minutes")+"</i></div><br />";routeHtml+="<table cellpadding='4' cellspacing='0' style='width:900px; margin:0 18px 30px 18px'>";routeHtml+="<tr style='color:white;'>";routeHtml+="  <td align='center' style='background-color: #4a4a4a'><b>#</b></td>";routeHtml+="  <td style='background-color: #4a4a4a'><b>Direction</b></td>";routeHtml+="  <td style='background-color: #4a4a4a'><b>"+(distanceUnit==VERouteDistanceUnit.Mile?"miles":"km")+"</b></td>";routeHtml+="  <td style='background-color: #4a4a4a'>&nbsp;</td>";routeHtml+="</tr>";var len=route.RouteLegs[0].Itinerary.Items.length;for(var i=0;i<len;i++){var turn=route.RouteLegs[0].Itinerary.Items[i];routeHtml+="<tr valign='middle'>";routeHtml+="  <td valign='top' align='center' style='background-color: "+altColors[i%2]+"'><img src='http://dev.virtualearth.net/mapcontrol/v6/i/bin/1.0.20070926140324.39/pins/"+(i>0&&i<len-1?"redcircle"+i:(i==0?"mapicon_start":"mapicon_end"))+".gif' /></td>";routeHtml+="  <td valign='top' style='background-color: "+altColors[i%2]+"'>"+turn.Text+"</td>";routeHtml+="  <td valign='top' style='background-color: "+altColors[i%2]+"'>"+(turn.Distance?turn.Distance.toFixed(2):"")+"</td>";routeHtml+="  <td valign='top' style='background-color: "+altColors[i%2]+"'>&nbsp;</td>";routeHtml+="</tr>"}routeHtml+="</table>";routeHolder.innerHTML=routeHtml;routeHolder.style.display=""};this.setZoomLevel=function(zm){this.map.SetZoomLevel(zm)};this.setMapView=function(){this.map.SetMapView(this.locsInMap)};this.setMapCenter=function(pid,zm){if(pid==null&&zm==null){var totalLat=0;var totalLong=0;var numOfLocs=this.locsInMap.length;for(i=0;i<numOfLocs;i++){totalLat+=parseFloat(this.locsInMap[i].Latitude);totalLong+=parseFloat(this.locsInMap[i].Longitude)}this.map.SetCenter(new VELatLong(totalLat/numOfLocs,totalLong/numOfLocs));return }if(zm!=null){this.map.SetCenterAndZoom(this.locsInMap[pid-1],zm)}else{this.map.SetCenter(this.locsInMap[pid-1])}};this.getUpperLeft=function(){var gmv=this.map.GetMapView();return gmv.TopLeftLatLong};this.getLowerRight=function(){var gmv=this.map.GetMapView();return gmv.BottomRightLatLong};this.showPushpinHover=function(id){var ppImg=document.getElementById("vepp_"+id.toString());var offset=new VEPixel(30,5);if(ppImg&&ppImg.className){ppImg.className=ppImg.className+"Select"}this.map.HideInfoBox();this.map.ShowInfoBox(this.shapesInMap[id-1],this.locsInMap[id-1],offset)};this.hidePushpinHover=function(id){var ppImg=document.getElementById("vepp_"+id.toString());if(ppImg&&ppImg.className){ppImg.className=ppImg.className.replace(/Select/g,"")}this.map.HideInfoBox(this.shapesInMap[id-1])};this.attachEvent=function(eventName,callBack){this.map.AttachEvent(eventName,callBack)};this.detachEvent=function(eventName,callBack){this.map.AttachEvent(eventName,callBack)};this.moveMap=function(newLoc,callBack){var location=newLoc;if(location.match("new york","i")==null&&location.match("ny","i")==null&&location.match("nj","i")==null){location+=", new york, NY"}location+=", USA";this.map.Find(null,location,null,null,null,null,null,null,null,null,callBack);return false};this.moveMapGeocodes=function(lat,lon,zoom){if(zoom==null){this.map.SetCenter(new VELatLong(lat,lon))}else{this.map.SetCenterAndZoom(new VELatLong(lat,lon),zoom)}};this.getCenterLat=function(){return this.map.GetCenter().Latitude};this.getCenterLon=function(){return this.map.GetCenter().Longitude};this.getZoomLevel=function(){return this.map.GetZoomLevel()};this.getMapStyle=function(){return this.map.GetMapStyle()};this.setMapStyle=function(s){var style;switch(s.toLowerCase()){case"a":style=VEMapStyle.Aerial;break;case"h":style=VEMapStyle.Hybrid;break;case"o":style=VEMapStyle.Birdseye;break;default:style=VEMapStyle.Road;break}this.map.SetMapStyle(style);return false}}function minMaxDashboard(){var dash=document.getElementById("lowerContainer");if(dash==null){return }if(dash.style.display!="none"){dash.style.display="none"}else{dash.style.display=""}}function mapIconRollover(icon){var className=icon.className;if(className.match(/select/i)){className=className.replace(/Select/g,"")}else{className+="Select"}icon.className=className}var regex=new RegExp("firefox/3","i");if(navigator.userAgent.match(regex)){var mouseEvt;if(typeof document.createEvent!=="undefined"){mouseEvt=document.createEvent("MouseEvents")}if(mouseEvt&&mouseEvt.__proto__&&mouseEvt.__proto__.__defineGetter__){mouseEvt.__proto__.__defineGetter__("pageX",function(){return this.clientX+window.pageXOffset});mouseEvt.__proto__.__defineGetter__("pageY",function(){return this.clientY+window.pageYOffset})}};﻿var NycMapSearch =  {
    schTxtID : "schTxt", 
	addressTxtID : "addressTxt",
	neighborhoodSelID : "neighborhoodSel",
	areaTxtID : "areaTxt",
	pnlCatSch : "catSch",
	pnlCatSchTop : "catSchTop",
	pnlCatSchTopPath : "catSchTopPath",
	pnlCatSchOrg : "catSchOrg",
	pnlCatSchNav : "catSchNav",
	pnlSchPath : "catSchPath",
	pnlResultSec : "resultSec",
	pnlResults : "results",
	pnlResultPath : "resultPath",
	pnlResultLoc : "resultLoc",
	nfoTotalCount : "totalcount",
	pnlResultsNav : "resultsNav",
	pnlLocSch : "locSch",
	pnlDateSch : "dateSch",
	locSchErrorID : "locSchError",
	locSchErrorBtmID : "locSchErrorBtm",
	moveMapText : "moveMapText",
	topTitleText : "topTitleText",
	
	mapCallBack : "",
	mapObj : null,
	pageSize : 20,
	catPageSize : 10,
	timeSqLat : 40.7558504573403,
	timeSqLon : -73.9864455393433,
	defaultZoom : 12,
	lastLat : 0,
	lastLon : 0,
	lastLocName : "",
	isDefaultMapped : false,
	lastSchPage : 1,
	
	curCats : null,
	curCatID : 0,
	curCatName : "",
	curCenterLat : 0,
	curCenterLon : 0,
	curUpperLeftLat : 0,
	curUpperLeftLon : 0,
	curLowerRightLat : 0,
	curLowerRightLon : 0,
	curZoom : 12,
	curBirdseyeZoom : 1,
	curMapStyle : null,
	
	curAddress : "",
	curAddressLat : 0,
	curAddressLon : 0,
	
	searchFor : function(name,pagenum,isACallBack) {
		NycMapSearch.lastLat = 0;
		NycMapSearch.lastLon = 0;		
		
		if ( isACallBack == null ) isACallBack = false;
		if ( name == null ) name = document.getElementById(NycMapSearch.schTxtID).value;
		if ( pagenum == null ) pagenum = 1;
		
		name = unescape(name);
		NycMapSearch.lastSchPage = pagenum;
		
		if (NycMapSearch.isDefaultMapped)
		    NycMapSearch.isDefaultMapped = false;
		else
		{
		    $("#" + NycMapSearch.locSchErrorID).empty();
		    $("#" + NycMapSearch.locSchErrorBtmID).empty();
		}
	
		document.getElementById(NycMapSearch.moveMapText).style.display = "";
		document.getElementById(NycMapSearch.topTitleText).style.display = "none";
		
		$.post("post.nyc",{_ns:"MapSearch",_a:1,_m:"SearchFor",n:name,p:pagenum,ps:NycMapSearch.pageSize,fla:NycMapSearch.curUpperLeftLat,
		    flg:NycMapSearch.curUpperLeftLon,tla:NycMapSearch.curLowerRightLat,tlg:NycMapSearch.curLowerRightLon},
		    function(res) { 
			    var div = $("#" + NycMapSearch.pnlResults);
			    div.empty();
			    var divPath = $("#" + NycMapSearch.pnlResultPath);
			    divPath.empty();    
			    $("#" + NycMapSearch.pnlResultSec).show();
			    
			    NycMapSearch.showResultLoc();
			    NycMapSearch.mapObj.deleteAllPins();
			    
			    divPath.html("Search for: <b>" + name + "</b>");
			    
				if ( res != null && res.TotalCount > 0 ) {
					$("#" + NycMapSearch.nfoTotalCount).html("(" + res.TotalCount + " found)");
					
					div.empty();
					
					var resultsList = "<table cellpadding='2' cellspacing='0'>";
								
					for( var i = 0; i < res.Records.length; i++ ) {
						var rec = res.Records[i];
						resultsList += "<tr valign='top'><td>" + (i+1) + ".</td><td><a target='_blank' href='" + rec.NycUrl 
						              + "' onmouseout='map.hidePushpinHover(" + (i + 1) + ")' onmouseover='map.showPushpinHover(" + (i + 1) + ")'>" 
						              + rec.Name + "</a>"
						              + (Math.floor(rec.ERating) > 0 ? "<br />rating: <img src='/image/hotels/stars/" + Math.floor(rec.ERating) + ".gif' />" : ""); 
						resultsList += "</td></tr>";
						
						// add pushpin to the map
					    NycMapSearch.addMapPushpin(rec, i);
					}
					
					resultsList += "</table>";
					div.html(resultsList);
					
					NycMapSearch.showResultsNav(res.TotalCount, res.PageNum, ".searchFor(\"" + escape(name) + "\",");
				} else {
					$("#" + NycMapSearch.nfoTotalCount).empty();
				    $("#" + NycMapSearch.pnlResultsNav).empty();
				    $("#" + NycMapSearch.pnlLocSch).empty();
				    
				    div.html("<p style='color:Red; margin: 10px 0 10px 0;'>No matching results</p>");
				    
				    // zoom out and center back to Time Square when no result found after search by location.
				    if (parseFloat(NycMapSearch.lastLat) == parseFloat(NycMapSearch.mapObj.getCenterLat()) 
				    && parseFloat(NycMapSearch.lastLon) == parseFloat(NycMapSearch.mapObj.getCenterLon()))
				    {
				        NycMapSearch.defaultMap();
				    }
				}	
				
				if (NycMapSearch.lastLocName != "")
				    NycMapSearch.getLandmarkRecord(NycMapSearch.lastLocName);
				if (NycMapSearch.curAddress != "")
				    NycMapSearch.mapObj.addPin( NycMapSearch.curAddressLat, NycMapSearch.curAddressLon, "Address Search:", 
				                    NycMapSearch.curAddress + '<br /><br />' +  
	                                '<div class=\'reverseRollOverLink\' style=\'line-height:20px;\'>' + 
	                                '<a href=\'\' onclick=\'map.setMapCenter(' 
	                                    + NycMapSearch.mapObj.pinID + ', 17);  return false;\'>zoom to street level</a> | ' + 
	                                '<a href=\'\' onclick=\'map.setMapCenter(' 
	                                    + NycMapSearch.mapObj.pinID + ', 12); return false;\'>zoom out</a></div><br />', 
	                                "/image/spacer.gif", "pushpinSolo");
				    
				// show location list
	            NycMapSearch.showLocations();		
			}, "json");
		
		// record this function call
		NycMapSearch.mapCallBack = "NycMapSearch.searchFor(\"" + escape(name) + "\", null, true)";
		
		return false;
	},
	
	searchForSection : function(secid,catid,catname,bitnum,pagenum,isACallBack) {
		var fromLatLong = NycMapSearch.mapObj.getUpperLeft();
		var toLatLong = NycMapSearch.mapObj.getLowerRight();
	
	    if (NycMapSearch.isDefaultMapped == true)
		    NycMapSearch.isDefaultMapped = false;
		else
		{
		    $("#" + NycMapSearch.locSchErrorID).empty();
		    $("#" + NycMapSearch.locSchErrorBtmID).empty();
		}
		    
		if ( catid == null ) catid = -1;
		if ( pagenum == null ) pagenum = 1;
		if ( catname == null ) catname = "";
		if ( bitnum == null ) bitnum = 0;
	    
	    NycMapSearch.lastSchPage = pagenum;
	    
		document.getElementById(NycMapSearch.moveMapText).style.display = "";
		document.getElementById(NycMapSearch.topTitleText).style.display = "none";
			
		jQuery.post("post.nyc",{_ns:"MapSearch",_a:1,_m:"SearchForSection",sid:secid,cid:catid,sbn:bitnum,edf:"",edt:"",p:pagenum,
		    ps:NycMapSearch.pageSize,fla:NycMapSearch.curUpperLeftLat,flg:NycMapSearch.curUpperLeftLon,tla:NycMapSearch.curLowerRightLat,
		    tlg:NycMapSearch.curLowerRightLon},
		    function(res) { 
			    var div = $("#" + NycMapSearch.pnlResults);
			    div.empty();    
			    var divPath = $("#" + NycMapSearch.pnlResultPath);
			    divPath.empty();    
				$("#" + NycMapSearch.pnlResultSec).show();
				
				NycMapSearch.showResultLoc();
				NycMapSearch.mapObj.deleteAllPins();
				
		        var dateName = "";
		        	
		        if ((secid == 4 && catid == -2) || (catid > -1 && catname != ""))
		            NycMapSearch.showCatsPath(0,NycMapSearch.curCats.SectionID,NycMapSearch.curCats.SectionName,catname);	
		
				if (secid == 28)
				    divPath.html("Movie Theaters : Top Rated");
				else if (secid == 1)
				    divPath.html("Restaurants : Top Rated");
			    else if (NycMapSearch.curCats != null)
			        divPath.html( NycMapSearch.curCats.SectionName + (catname != "" ? " : " + unescape(catname) : "") 
			                            + (dateName != "" ? " : " +  dateName : "")
			                            + (catname == "" && dateName == "" ? " : Top Rated" : "") );
			        
				if ( res != null && res.TotalCount > 0 ) {
					$("#" + NycMapSearch.pnlResultSec).show();
					
					$("#" + NycMapSearch.nfoTotalCount).html("(" + res.TotalCount + " found)");
					
					div.empty();
					
					var resultsList = "<table cellpadding='4' cellspacing='0' id='thisTableId'><tr valign='top'>";
					for( var i = 0; i < res.Records.length; i++ ) {
						var rec = res.Records[i];
						
						
						resultsList += "<td>" + (i+1) + ".</td><td><a target='_blank' href='" + rec.NycUrl 
						              + "' onmouseout='map.hidePushpinHover(" + (i + 1) + ")' onmouseover='map.showPushpinHover(" + (i + 1) + ")'>" 
						              + rec.Name + "</a>" 
						              + (Math.floor(rec.ERating) > 0 ? "<br />rating: <img src='/image/hotels/stars/" + Math.floor(rec.ERating) + ".gif' />" : ""); 
						resultsList += "</td>";
						
						for(var c=1; c < res.Records.length; c++)
						{
						    if(i+1 == c*5)
						    {
						        resultsList +="</tr><tr valign='top'>"
						    }
						}
						// add pushpin to the map
					    NycMapSearch.addMapPushpin(rec, i);
					}
					
					resultsList += "</tr></table>";
					div.html(resultsList);
					
					NycMapSearch.showResultsNav(res.TotalCount, res.PageNum, ".searchForSection(" + secid + "," + catid 
					                    + ",\"" + catname + "\"," + bitnum + ",");
				} else {
				    $("#" + NycMapSearch.nfoTotalCount).empty();
				    $("#" + NycMapSearch.pnlResultsNav).empty();
				    $("#" + NycMapSearch.pnlLocSch).empty();
				    
				    div.html("<p style='color:Red; margin: 10px 0 10px 0;'>No matching results</p>");
				    
				    // zoom out and center back to Time Square when no result found after search by location.
				    if (parseFloat(NycMapSearch.lastLat) == parseFloat(NycMapSearch.mapObj.getCenterLat()) 
				    && parseFloat(NycMapSearch.lastLon) == parseFloat(NycMapSearch.mapObj.getCenterLon()))
				    {
				        NycMapSearch.defaultMap();
				    }
				}	
				
				if (NycMapSearch.lastLocName != "")
				    NycMapSearch.getLandmarkRecord(NycMapSearch.lastLocName);
				if (NycMapSearch.curAddress != "")
				    NycMapSearch.mapObj.addPin( NycMapSearch.curAddressLat, NycMapSearch.curAddressLon, "Address Search:", 
				                    NycMapSearch.curAddress + '<br /><br />' +  
	                                '<div class=\'reverseRollOverLink\' style=\'line-height:20px;\'>' + 
	                                '<a href=\'\' onclick=\'map.setMapCenter(' 
	                                    + NycMapSearch.mapObj.pinID + ', 17);  return false;\'>zoom to street level</a> | ' + 
	                                '<a href=\'\' onclick=\'map.setMapCenter(' 
	                                    + NycMapSearch.mapObj.pinID + ', 12); return false;\'>zoom out</a></div><br />', 
	                                "/image/spacer.gif", "pushpinSolo");
				    
				// rewrite category list when it's event
				if (secid == 30)
				    NycMapSearch.showCats(1);
					                    
				// show location list
	            NycMapSearch.showLocations();		
			}, "json");
		
		// save the current search for for map callback
		NycMapSearch.mapCallBack = "NycMapSearch.searchForSection(" + secid + "," + catid + ",\"" + catname + "\"," + bitnum + ",null,true)";
		NycMapSearch.curCatID = catid;
		NycMapSearch.curCatName = catname;
		
		return false;
	},
	
	showResultsNav : function(total,pagenum,schfunc) {
		var div = document.getElementById(NycMapSearch.pnlResultsNav);
		$(div).empty();
		var numOfPage = Math.ceil( total / NycMapSearch.pageSize );
		var navPageSize = 7;
		var start = 0;
		var end = 0;
			
		if ( numOfPage <= 1 ) {
			$(div).empty();
			return;
		}
		
		// page nav will only show 8 pages at a tiNycMapSearch...
		if ( numOfPage > navPageSize) {
		    if (pagenum <= (navPageSize + 1) / 2) {
		        start = 1;
		        end = navPageSize + 1;
		    }
		    else {
		        start = pagenum - 4;
		        end = (start + navPageSize < numOfPage  + 1 ? start + navPageSize : numOfPage + 1);
		    }
		}
		else {
		    start = 1;
		    end = numOfPage + 1;
		}
	    
	    var navHTML = "";
		navHTML = "Page:";
		if (pagenum > 1) { 
			navHTML += "&nbsp;<a href='' onclick='return " + "NycMapSearch" + schfunc + (pagenum-1) + ");'><</a>";
		}
		
		if (start > 1) {
	        navHTML += "&nbsp;...";
	    }
		    
		var i = 1;
		for (i = start; i < end; i++) {
			if ( i == pagenum ) {
				navHTML += "&nbsp;<b>" + i + "</b>";
			} else {
				navHTML += "&nbsp;<a href='' onclick='return " + "NycMapSearch" + schfunc + i + ");'>" + (i) + "</a>";
			}
		}
		
		if (end - 1 < numOfPage) {
		    navHTML += "&nbsp;...";
		} 
		
		if ( pagenum < numOfPage ) { 
			navHTML += "&nbsp;<a href='' onclick='return " + "NycMapSearch" + schfunc + (pagenum+1) + ");'>></a>";
		}
		
		div.innerHTML = navHTML;
	},

	getCats : function(secid) {
		$("#" + NycMapSearch.pnlCatSch).empty();
		$("#" + NycMapSearch.pnlCatSchTopPath).empty();	
		$("#" + NycMapSearch.pnlCatSchTop).empty();	
		
		if ( secid == null ) return;
		jQuery.post("post.nyc",{_ns:"MapSearch",_a:1,_m:"GetCategoriesFor",sid:secid},
			function(res) { 
				if (res != null && res.TotalCount > 0) {
					NycMapSearch.curCats = res;
					NycMapSearch.showCats(1);
				} else {
					NycMapSearch.curCat = null;
				}
			},"json");
		
		NycMapSearch.searchForSection(secid);
		
		return false;
	},
	
	showCats : function(page) {
	    $("#" + NycMapSearch.pnlCatSchTopPath).empty();	
		$("#" + NycMapSearch.pnlCatSchTop).empty();	
		
		if (page == 0 || NycMapSearch.curCats == null ) {    
			NycMapSearch.showCatsPath(1);
			NycMapSearch.searchForSection(1,null,1);
			return false;
		}

		$("#" + NycMapSearch.pnlCatSch).show();
		$("#" + NycMapSearch.pnlCatSchOrg).show();
		NycMapSearch.showCatsPath(0,NycMapSearch.curCats.SectionID,NycMapSearch.curCats.SectionName);		
		
        $("#" + NycMapSearch.pnlCatSchNav).hide();

        var showMoreLink = false;
		var div = document.getElementById(NycMapSearch.pnlCatSch);
		$(div).empty();		
		var divTop = document.getElementById(NycMapSearch.pnlCatSchTop);
		$(divTop).empty();		
		var resultsList = "<table cellpadding='2' cellspacing='0'>";
		
		var count = 1;
		var restoPriceIdx = 0;
		var lastCatName = "";
			
		divTop.innerHTML = "<p style='margin-top:4px;'><b>Search By Category</b></p>";
		
        for (var i = 0; i < NycMapSearch.curCats.TotalCount; i++) 
        {
			var cat = NycMapSearch.curCats.Cats[i];
			
			if (cat.subcatid == NycMapSearch.curCatID)
			    curCatName = cat.name;
			
			if (i == 0)
			{
			    // add search by star rating title to hotel
			    if (NycMapSearch.curCats.SectionID == 4)
			        resultsList += "<tr><td colspan='2'><b>Search By Star Rating</b></td></tr>";
			    else if (NycMapSearch.curCats.SectionID == 6)
			        resultsList += "<tr><td colspan='2'><b>Search By Top Cuisines</b></td></tr>";
			}
		    
			// found first price category, store the index and exits loop
			if (NycMapSearch.curCats.SectionID == 6 && cat.name == "$")
			{
			    restoPriceIdx = i;
			    break;
			}
			    
			if (count - 1 == NycMapSearch.catPageSize) 
			{
			    if (NycMapSearch.curCats.SectionID == 6 && i < 40)
			    {
			        resultsList += "</table><table id='tblMoreTopRestoCat' cellpadding='2' cellspacing='0' "
			                    + "class='regularLighterGrey' style='display:none;'>";
			    }
			    else
			    {
			        resultsList += "</table><table id='tblMoreCat' cellpadding='2' cellspacing='0' "
			                    + "class='regularLighterGrey' style='display:none;'>";
		            showMoreLink = true;
		        }
			}
			
			if (i > 0 && NycMapSearch.curCats.SectionID == 6 && cat.name.substr(0,1) < lastCatName.substr(0,1))
			{
			    resultsList += "</table><table cellpadding='2' cellspacing='0'>";
			    resultsList += "<tr><td colspan='2' align='right'>"
                    + "<a href='' id='restoTopCatShowLink' onclick='$(&quot;#tblMoreTopRestoCat, #restoTopCatShowLink, #restoTopCatHideLink&quot;).toggle(); return false;'>more...</a>"
                    + "<a href='' id='restoTopCatHideLink' style='display:none;' onclick='$(&quot;#tblMoreTopRestoCat, #restoTopCatShowLink, #restoTopCatHideLink&quot;).toggle(); return false;'>[ x ] close</a>"
                    + "</td></tr>"
                    + "<tr><td>&nbsp;</td></tr>"
                    + "<tr><td colspan='2'><b>Search By Other Cuisines</b></td></tr>";
			    
			    count = 1;
			}
			
			resultsList += "<tr><td style='width:" + (NycMapSearch.curCats.TotalCount >= 100 ? "23" : "15") + "px;'>" 
			            + count + ".</td><td><a href='' onclick='return " 
			            + "NycMapSearch.searchForSection(" + NycMapSearch.curCats.SectionID + "," 
			            + cat.subcatid + ",\"" + escape(cat.name) + "\"," 
			            + (cat.field.toLowerCase().indexOf("bit") > -1 ? cat.field.substring(cat.field.indexOf("_") + 1) : "null") 
			            + ",1);'>" + cat.name + "</a></td></tr>";
		    
		    count++;
		    
		    // for hotel category, add a header "Search By Amenity" after "4 stars or higher"
		    if (NycMapSearch.curCats.SectionID == 4 && cat.subcatid == 1445)
		    {
		        resultsList += "<tr><td colspan='2'><p style='margin-top:15px;'><b>Search By Amenity</b></p></td></tr>";
		        count = 1;
		    }
		    
		    // for hotel category, add a header "Search By Brand" after "Wheelchair Accessible"
		    if (NycMapSearch.curCats.SectionID == 4 && cat.subcatid == 8)
		    {
		        resultsList += "<tr><td colspan='2'><p style='margin-top:15px;'><b>Search By Brand</b></p></td></tr>";
		        count = 1;
		    }
		    
		    lastCatName = cat.name;
		}
		
		resultsList += "</table>";
		
		if (showMoreLink)
        {    
            resultsList += "<div style='margin-left:110px;'>"
                    + "<a href='' id='catShowLink' onclick='$(&quot;#tblMoreCat, #catShowLink, #catHideLink&quot;).toggle(); return false;'>more...</a>"
                    + "<a href='' id='catHideLink' style='display:none;' onclick='$(&quot;#tblMoreCat, #catShowLink, #catHideLink&quot;).toggle(); return false;'>[ x ] close</a>"
                    + "</div>";
        }
        
        // list resto price and feature categoies
        if (NycMapSearch.curCats.SectionID == 6 && restoPriceIdx > 0)
        {
            count = 1;
            
            resultsList += "<br /><p style='margin-top:4px;'>Search By Price</p>"
                        + "<table cellpadding='2' cellspacing='0'>";
			
			for (var i = restoPriceIdx; i < NycMapSearch.curCats.TotalCount; i++) 
            {
                var cat = NycMapSearch.curCats.Cats[i];
            
                resultsList += "<tr><td style='width:15px;'>" 
			            + count + ".</td><td><a href='' onclick='return " 
			            + "NycMapSearch.searchForSection(" + NycMapSearch.curCats.SectionID + "," 
			            + cat.subcatid + ",\"" + escape(cat.name) + "\"," 
			            + (cat.field.toLowerCase().indexOf("bit") > -1 ? cat.field.substring(cat.field.indexOf("_") + 1) : "null") + ",1);'>" + cat.name + "</a></td></tr>";
		  
		        count++;
		        
		        // at the end of price, write header for feature...
		        if (cat.name == "$$$$")
		        {
		            resultsList += "<tr><td colspan='2'><p style='margin-top:15px;'>Search By Feature</p></td></tr>";
		            count = 1;
		        }   
            }
            
            resultsList += "</table>";
        }
        
		div.innerHTML = resultsList;
		
		return false;
	},
	
	showLocations : function()
	{
	    jQuery.post("post.nyc",{_ns:"MapSearch",_a:1,_m:"GetGeocodes"},
	    	function(res) 
			{ 
			    var div = document.getElementById(NycMapSearch.pnlLocSch);
			    $(div).empty();
	            var divHTML = "<br /><p><b>Search By Neighborhood</b></p><table cellpadding='2' cellspacing='0'>";
	            var sel = document.getElementById(NycMapSearch.neighborhoodSelID);
	            
				if (res != null && res.TotalCount > 0) 
				{
				    var curBoro = "";
				    var selCount = 0;
				    
				    for ( j = sel.options.length - 1; j >= 0; j--)
				    {
				        sel.options[j] = null;
				    }
				    
					for( var i = 0; i < res.Geocodes.length; i++ ) 
					{
					    if (i == NycMapSearch.catPageSize) 
					        divHTML += "</table><table id='tblMoreLoc' cellpadding='2' cellspacing='0' style='display:none;'>";
					
					    if (res.Geocodes[i].IsBorough)
					    {
					        curBoro = res.Geocodes[i].Neighborhood;
					        
					        if (res.Geocodes[i].Latitude == 0 && res.Geocodes[i].Longitude == 0)
					        {
					            divHTML += "<tr><td colspan='2'>" + res.Geocodes[i].Neighborhood + "</td></tr>";
					        
					            sel.options[selCount] = new Option(res.Geocodes[i].Neighborhood, "//landmarks");
					            selCount++;
					        }
					        else
					        {
					            divHTML += "<tr><td colspan='2'><a href='' onclick='return " 
	                                + "NycMapSearch.moveMap(\"" + escape(res.Geocodes[i].Neighborhood) + "\"," 
	                                + res.Geocodes[i].Latitude + "," 
	                                + res.Geocodes[i].Longitude + ",12);'>" 
	                                + res.Geocodes[i].Neighborhood + "</a></td></tr>";
	                                
	                            sel.options[selCount] = new Option(res.Geocodes[i].Neighborhood, 
	                                    "NycMapSearch.moveMap(\"" + escape(res.Geocodes[i].Neighborhood) + "\"," 
	                                    + res.Geocodes[i].Latitude + "," 
	                                    + res.Geocodes[i].Longitude + ",12)"); 
	                            selCount++;
	                        }
					    }
					    else
					    {
					        divHTML += "<tr valign='top'><td>&nbsp;&nbsp;-</td><td><a href='' onclick='return " 
	                                + "NycMapSearch.moveMap(\"" + escape(res.Geocodes[i].Neighborhood) + "\"," 
	                                + res.Geocodes[i].Latitude + "," 
	                                + res.Geocodes[i].Longitude + ",14);'>" 
	                                + res.Geocodes[i].Neighborhood + "</a></td></tr>";
	                        
	                        if (curBoro.toLowerCase().match("manhattan") != null || curBoro.toLowerCase().match("landmarks") != null)         
	                        {
	                            sel.options[selCount] = new Option("- " + res.Geocodes[i].Neighborhood, 
	                                        "NycMapSearch.moveMap(\"" + escape(res.Geocodes[i].Neighborhood) + "\"," 
	                                        + res.Geocodes[i].Latitude + "," 
	                                        + res.Geocodes[i].Longitude + ",14)");
	                            selCount++;
	                        }
	                    }
					}
				}
				else
				{
				    divHTML += "<tr><td>" + res.TotalCount + "</td></tr>";
				}
				
				divHTML += "</table>";
	    
	            if (res.TotalCount > NycMapSearch.catPageSize)
	            {    
	                divHTML += "<div style='margin-left:100px;'>"
	                        + "<a href='' id='locShowLink' onclick='$(&quot;#tblMoreLoc, #locShowLink, #locHideLink&quot;).toggle(); return false;'>more...</a>"
	                        + "<a href='' id='locHideLink' style='display:none;' onclick='$(&quot;#tblMoreLoc, #locShowLink, #locHideLink&quot;).togggle(); return false;'>[ x ] close</a>"
	                        + "</div>";
		        }
		        
		        div.innerHTML = divHTML;
			}, "json");

	    return false;
	},
	
	showCatsNav : function(pagenum,numOfPage) {
		$("#" + NycMapSearch.pnlCatSchNav).show();
		var div = document.getElementById(NycMapSearch.pnlCatSchNav);
		$(div).empty();
		var navPageSize = 8;
		var start = 0;
		var end = 0;
		
		// page nav will only show 10 pages at a tiNycMapSearch...
		if ( numOfPage > navPageSize) {
		    if (pagenum <= navPageSize / 2) {
		        start = 1;
		        end = navPageSize + 1;
		    }
		    else {
		        start = pagenum - 4;
		        end = (start + navPageSize < numOfPage  + 1 ? start + navPageSize : numOfPage + 1);
		    }
		}
		else {
		    start = 1;
		    end = numOfPage + 1;
		}
		
		div.innerHTML = "Page: ";
		if (pagenum > 1) { 
			div.innerHTML += " <a href='' onclick='return NycMapSearch.showCats(" + (pagenum-1) + ");'><</a>";
		}
		
		var i = 1;
		for (i = start; i < end; i++) {
			if ( i == pagenum ) {
				div.innerHTML += " <b>" + i + "</b>";
			} else {
				div.innerHTML += " <a href='' onclick='return NycMapSearch.showCats(" + i + ");'>" + (i) + "</a>";
			}
		}
		
		if ( pagenum < numOfPage ) { 
			div.innerHTML += " <a href='' onclick='return NycMapSearch.showCats(" + (pagenum+1) + ");'>></a>";
		}
	},

	showCatsPath : function(all,cat,catname,subcatname) {
		var div = document.getElementById(NycMapSearch.pnlSchPath);
		$(div).empty();
		var divCat = document.getElementById(NycMapSearch.pnlCatSchTopPath);
		$(divCat).empty();
		
        var pathHtml = "";
		if ( all ) {
			pathHtml = "All";
			$("#" + NycMapSearch.pnlCatSchOrg).show();
			$("#" + NycMapSearch.pnlCatSch).hide();
			$("#" + NycMapSearch.pnlCatSchNav).hide();
			return false;
		} else {
			pathHtml = "<a href='' onclick='return NycMapSearch.showCats(0)'>All</a>";
		}
		if ( cat && !subcatname ) {
			pathHtml += " > " + unescape(catname);
		} else {
			pathHtml += " > <a href='' onclick='return NycMapSearch.getCats(" + cat + ")'>" + unescape(catname) + "</a>";
		}
		
		if ( subcatname ) {
			pathHtml += " > " + unescape(subcatname);
		}
		
		div.innerHTML = pathHtml;
		divCat.innerHTML = pathHtml;
		
		return false;
	},
	
	showResultLoc : function() {   
	    var div = document.getElementById(NycMapSearch.pnlResultLoc);
	    $(div).empty();
	    
	    if (parseFloat(NycMapSearch.lastLat) == parseFloat(NycMapSearch.mapObj.getCenterLat()) 
		&& parseFloat(NycMapSearch.lastLon) == parseFloat(NycMapSearch.mapObj.getCenterLon()))
		{
		    div.innerHTML = "<i>Near <b>" + NycMapSearch.lastLocName + "</b></i>";
		}
	},
	
	addMapPushpin : function(record, ppIdx, isLandmark) {
	    if (isLandmark == null) isLandmark = false;
	   
	    // add pushpin to the map
	    NycMapSearch.mapObj.addPin(record.Latitude, record.Longitude, 
	    (isLandmark ? '' : (ppIdx + 1) + '. ') + '<a href=\'' + record.NycUrl + '\' target=\'_blank\'>' + record.Name + '</a>', 
	    "<div class='mppDetail'>" + 
		(record.Editorial != null && (record.Editorial + '').strip() != '' ? record.Editorial 
		    + ' <b><a href=\'' + record.NycUrl + '\' target=\'_blank\'>more</a></b>' + '<br /><br />' : '') + 
	    (record.SectionID == 30 && record.Venue + '' != '' ? 'Venue: <b>' + record.Venue + '</b><br />' : '') +
	    
	    '<table cellpadding=\'0\' cellspacing=\'0\'><tr valign=\'top\'><td>' + 
	    (record.SectionID == 4 && record.Thumbnail != "" ? '<img src=\'' + record.Thumbnail 
	        + '\' style=\'margin-right:6px;\' width=\'64px\' /></td><td>' : '') +
	    (record.Neighborhood != '' ? 'Neighborhood: ' + record.Neighborhood + '<br />' : '') +
	    (record.Address + "" != "" ? record.Address.replace(/\n/g, '<br />') + '<br />' : '') + 
	    (record.Phone != '' ? '<b>' + record.Phone + '</b><br />' : '') + 
	    '</td></tr></table><br />' + 
	    (record.ERating > 0 ? '<img src=\'/image/hotels/stars/' + Math.floor(record.ERating) + '.gif\' /> <i>editorial review</i><br /><br />' : '') +
	    
	    // hotel reservation button
	    (record.SectionID == 4 ? '<a class=\'sellButton\' target=\'_blank\' href=\'' + 
	        record.NycUrl + '\'>&nbsp;&nbsp;MAKE RESERVATION&nbsp;&nbsp;</a><br /><br />' : '') +
	    // restuarant reservation button
	    (record.BookingUrl != '' && record.SectionID == 6 ? '<a class=\'sellButton\' target=\'_blank\' href=\'' + 
	        record.BookingUrl + '\'>&nbsp;&nbsp;MAKE RESERVATION&nbsp;&nbsp;</a><br /><br />' : '') +
	    // ticket button
	    (record.BookingUrl != '' && record.SectionID != 6 ? '<a class=\'sellButton\' target=\'_blank\' href=\'' + 
	        record.BookingUrl + '\'>&nbsp;&nbsp;BUY TICKETS&nbsp;&nbsp;</a><br /><br />' : '') +
	    '<div style=\'line-height:20px;\'>' + 
	    '<a href=\'' + record.NycUrl.replace(/editorial.aspx/g, "map_location.aspx") 
	        + '\' target=\'_blank\'>Get Directions</a> | ' +   
	    '<a href=\'\' onclick=\'return emailThisPage(&quot;' 
	        + record.NycPageTitle  + '&quot;, &quot;' + record.NycUrl + '&quot;);\'>Send to Friend</a><br />' +   
	    '<a href=\'\' onclick=\'NycMapSearch.mapObj.setMapCenter(' 
	        + (ppIdx + 1) + ', 17);  return false;\'>zoom to street level</a> | ' + 
	    '<a href=\'\' onclick=\'NycMapSearch.mapObj.setMapCenter(' 
	        + (ppIdx + 1) + ', 12); return false;\'>zoom out</a></div></div><br />' , 
	    '/image/spacer.gif', 'pushpin' + (isLandmark ? 'Solo' : (ppIdx + 1)));
	},
	
	moveMap : function(neighborhood, lat, lon, zm) {
	    if ( lat == null ) lat = 0;
		if ( lon == null ) lon = 0;
	    if ( zm == null ) zm = 12;
	    if (lat != 0 && lon != 0) 
		{
		    NycMapSearch.mapObj.moveMapGeocodes(lat,lon,zm);
		    
		    // keep track of latest neighborhood jump
		    NycMapSearch.lastLat = NycMapSearch.mapObj.getCenterLat();
		    NycMapSearch.lastLon = NycMapSearch.mapObj.getCenterLon();
		    NycMapSearch.lastLocName = unescape(neighborhood);
		    
		    NycMapSearch.curAddress = "";
	        NycMapSearch.curAddressLat = 0;
	        NycMapSearch.curAddressLon = 0;
		}
		
		NycMapSearch.getLandmarkRecord(NycMapSearch.lastLocName);
		
		return false;
	}, 
	
	// this function moves map back to original lat lon and zoom
	defaultMap : function() {
	    var errorMsg = document.getElementById(NycMapSearch.locSchErrorID);
	    $(errorMsg).empty();
	    var errorMsgBtm = document.getElementById(NycMapSearch.locSchErrorBtmID);
	    $(errorMsgBtm).empty();
	    NycMapSearch.isDefaultMapped = true;
	    
	    NycMapSearch.resetMap();
	    
	    errorMsg.innerHTML = "(No Results found in " + NycMapSearch.lastLocName + ")";
	    errorMsgBtm.innerHTML = "(No Results found in " + NycMapSearch.lastLocName + ")";
	    
	    // clear last location info
	    NycMapSearch.lastLat = 0;
		NycMapSearch.lastLon = 0;
		NycMapSearch.lastLocName = "";
		
	    return false;
	},
	
	// reset map to original state
	resetMap : function() {
	    NycMapSearch.mapObj.moveMapGeocodes(NycMapSearch.timeSqLat, NycMapSearch.timeSqLon, NycMapSearch.defaultZoom);
	    NycMapSearch.curAddress = "";
        NycMapSearch.curAddressLat = 0;
        NycMapSearch.curAddressLon = 0;
    	    
	    return false;
	},
	
	// record the current Map Info
	saveMapInfo : function() {
	    NycMapSearch.curMapStyle = NycMapSearch.mapObj.getMapStyle();
        
	    if (NycMapSearch.curMapStyle != VEMapStyle.Birdseye)
	    {
	        NycMapSearch.curZoom = NycMapSearch.mapObj.getZoomLevel();
	        NycMapSearch.curCenterLat = NycMapSearch.mapObj.getCenterLat();
            NycMapSearch.curCenterLon = NycMapSearch.mapObj.getCenterLon();
            
            var upperLeft = NycMapSearch.mapObj.getUpperLeft();
            var lowerRight = NycMapSearch.mapObj.getLowerRight();
            NycMapSearch.curUpperLeftLat = upperLeft.Latitude;
            NycMapSearch.curUpperLeftLon = upperLeft.Longitude;
            NycMapSearch.curLowerRightLat = lowerRight.Latitude;
            NycMapSearch.curLowerRightLon = lowerRight.Longitude;
        }
        else
            NycMapSearch.curBirdseyeZoom = NycMapSearch.mapObj.getZoomLevel();
        
        return false;
	},
	
	// this function construct current map search querystring and pop up email page
	emailThisMap : function() {
	    var url = "/mapsearch.aspx";
	    var isTextSearch = false;
	    
	    // map position and zoom level
	    url += "?lat=" + NycMapSearch.curCenterLat;
	    url += "&lon=" + NycMapSearch.curCenterLon;
	    url += "&z=" + NycMapSearch.curZoom;
	    url += "&ms=" + NycMapSearch.curMapStyle.toString();
	    url += "&bz=" + NycMapSearch.curBirdseyeZoom;
	    
	    
	    if (NycMapSearch.mapCallBack.indexOf("searchFor") > -1)
	    {
	        isTextSearch = (NycMapSearch.mapCallBack.indexOf("searchFor(") > -1);
	        
	        if (isTextSearch) // text search
	        {
	            var param = NycMapSearch.mapCallBack.replace(/NycMapSearch.searchFor\(/g, "").replace(/\)/g, "").split(',');
	            
	            url += "&st=" + escape(unescape(param[0].replace(/\"/g, "").replace(/'/g, "")));
	            
	            url += "&p=" + NycMapSearch.lastSchPage;
	        }
	        else // category search
	        {
	            var param = NycMapSearch.mapCallBack.replace(/NycMapSearch.searchForSection\(/g, "").replace(/\)/g, "").split(',');
	            var secid = 0;
	            
	            secid = parseInt(param[0]);
	            url += "&sid=" + param[0].strip();
	            
	            if (param.length > 1 && parseInt(param[1]) > 0)
	                url += "&cid=" + param[1].strip();
	            
	            if (param.length > 2 && parseInt(param[1]) > 0)
	                url += "&cn=" + escape(unescape(param[2].replace(/\"/g, "").replace(/'/g, ""))).strip();
	                
	            if (param.length > 3 && parseInt(param[3]) > 0)
	                url += "&b=" + param[3].strip();
	                
	            url += "&p=" + NycMapSearch.lastSchPage;
	        }
	    }
	    
	    // pop up email page
	    window.open("/emailthispage.aspx?title=" + escape("NYC.Com - Map Search") + "&url=" + escape(url) + "&titlesubject=1", "email", "height=650,width=550");
	    
	    return false;
	},
	
	getLandmarkRecord : function(name) {
	    jQuery.post("post.nyc",{_ns:"MapSearch",_a:1,_m:"GetLandmarkRecord","name":name}, 
	        function(res) {
	            if (res != null && res.Name != null)
                {
                    NycMapSearch.addMapPushpin(res,0,true);
                }
	        }, "json");
	},
	
	searchAddress : function(address) {
	    if (address == null) address = $("#" + NycMapSearch.addressTxtID);
	    
	    if (address.val().strip() != "")
	    {
	        NycMapSearch.mapObj.moveMap(address.val(), 
	            function(e) {	        
	                NycMapSearch.curAddress = address.val();
	                NycMapSearch.curAddressLat = NycMapSearch.mapObj.getCenterLat();
	                NycMapSearch.curAddressLon = NycMapSearch.mapObj.getCenterLon();
	                NycMapSearch.mapObj.addPin( NycMapSearch.mapObj.getCenterLat(), NycMapSearch.mapObj.getCenterLon(), "Address Search:", 
                                    address.val() + '<br /><br />' +  
	                                '<div class=\'reverseRollOverLink\' style=\'line-height:20px;\'>' + 
	                                '<a href=\'\' onclick=\'NycMapSearch.mapObj.setMapCenter(' 
	                                    + NycMapSearch.mapObj.pinID + ', 17);  return false;\'>zoom to street level</a> | ' + 
	                                '<a href=\'\' onclick=\'NycMapSearch.mapObj.setMapCenter(' 
	                                    + NycMapSearch.mapObj.pinID + ', 12); return false;\'>zoom out</a></div><br />', 
                                    "/image/spacer.gif", "pushpinSolo");
	            }
	        );
	        
	        NycMapSearch.lastLat = 0;
		    NycMapSearch.lastLon = 0;
		    NycMapSearch.lastLocName = "";
	    }
	    
	    return false;
	},
	
	callBackSearch : function(e) {
	    if (NycMapSearch.mapCallBack) {
	        NycMapSearch.mapObj.deleteAllPins(); 
	        eval(NycMapSearch.mapCallBack); 
	    }
	},
	
	callBackSaveMap : function(e) {
	    NycMapSearch.saveMapInfo();
	},
	
	init : function(secid,catid,catname,mappedbitID,searchtext,page,mapStyle,birdseyeZoom) {
	    NycMapSearch.curMapStyle = VEMapStyle.Road;
	    NycMapSearch.mapObj.attachEvent('onchangeview', NycMapSearch.callBackSaveMap);
	    NycMapSearch.mapObj.attachEvent('onchangeview', NycMapSearch.callBackSearch);
	    NycMapSearch.showLocations(); 
	    NycMapSearch.saveMapInfo();
	    
	    if ((searchtext + "").strip() != "") {
	        NycMapSearch.searchFor(searchtext, ( page > 0 ? page : 1 ));
	        $("#browseTabOn,#browseTabOff,#searchTabOn,#searchTabOff,#searchDiv,#browseDiv").toggle();
	        $('#schTxt').val( unescape(searchtext) );
	    } else if (secid > 0) {
	        NycMapSearch.getCats(secid);
	        
	        if (catid > 0) {
	            NycMapSearch.searchForSection(secid,catid,catname,mappedbitID,( page > 0 ? page : 1 ));
	        }
	    }  
	    
	    if (mapStyle != "") {
	        NycMapSearch.mapObj.setMapStyle(mapStyle);
	        if (mapStyle == VEMapStyle.Birdseye)
	        NycMapSearch.mapObj.setZoomLevel(birdseyeZoom);
	    }
	}
}
