
function BaseMapControl(opt_opts){this.defaultOptions={zoom:13,zoomToBounds:false,markerType:'hotel',polyStyle:{strokeColor:"#FF6600",strokeWidth:2,strokeOpacity:0.8,bgColor:"#000000",bgOpacity:0.0,bgOpacityFilled:0.25},googleBarEnabled:false,streetview:false,mapSettingsCookieTimeout:3600000,hotelPhotoOptions:{baseDir:'http://koi.hotelicopter.com',noPhotoImg:'/images/hotelicopter/hotel-with-no-photo-67x67.png'}};this.markers=new Array();this.markerOptions=new Array();this.infoWindows=new Array();this.options={}
if(opt_opts){for(var o in opt_opts){this.options[o]=opt_opts[o];}}
if(this.defaultOptions){for(var d in this.defaultOptions){if(!this.options[d]){this.options[d]=this.defaultOptions[d];}}}};BaseMapControl.prototype=new GControl();BaseMapControl.prototype.initialize=function(){if(GBrowserIsCompatible()){initOptions={};if(this.options.googlebar){initOptions.googleBarOptions={showOnLoad:true,suppressZoomToBounds:true,onSearchCompleteCallback:doSearchCompleteCallback,onGenerateMarkerHtmlCallback:doGenerateMarkerHtmlCallback}}
this.map=new GMap2(document.getElementById(this.options.container),initOptions);return true;}else{return false;}};BaseMapControl.prototype.setCenter=function(latitude,longitude,zoom){if(!zoom){zoom=this.options.zoom;}
this.map.setCenter(new GLatLng(latitude,longitude),this.options.zoom);};BaseMapControl.prototype.setScrollWheelZoom=function(scrollenabled){if(scrollenabled){this.map.enableScrollWheelZoom();}
else{this.map.disableScrollWheelZoom();}};BaseMapControl.prototype.addMapTypeControls=function(options){if(!options){options={};}
var customUI=this.map.getDefaultUI();customUI.maptypes.satellite=false;customUI.maptypes.physical=false;if(options.standardMap){customUI.controls.maptypecontrol=false;customUI.controls.menumaptypecontrol=true;this.map.setUI(customUI);}else{customUI.controls.maptypecontrol=false;this.map.setUI(customUI);this.map.addControl(new ExtMapTypeControl({posRight:106,showTraffic:false,showMore:true,useMapTypes:true,showStreetView:true}));}};BaseMapControl.prototype.checkResize=function(){this.map.checkResize();};BaseMapControl.prototype.makeSmall=function(){$('mapImg').src=$F('smallMapUrl');$('mapImg').style.display='block';$('large_map_nav').style.display='none';$('searchResultsMapContainer').removeClassName('map-large');$('sr-map-container').removeClassName('large');$('searchResultsMapContainer').addClassName('map-small');$('sr-map-container').addClassName('small');$(this.options.container).style.display='none';$('mapType').value='small';this.setMapCookie();$('toggleMapLink').removeClassName('open');}
BaseMapControl.prototype.makeLarge=function(){$('mapImg').style.display='none';$('searchResultsMapContainer').removeClassName('map-small');$('sr-map-container').removeClassName('small');$('searchResultsMapContainer').addClassName('map-large');$('sr-map-container').addClassName('large');$(this.options.container).style.display='block';$('large_map_nav').style.display='block';$('mapType').value='large';this.setMapCookie();$('toggleMapLink').addClassName('open');};BaseMapControl.prototype.setMapCookie=function(){var today=new Date();var expire=new Date();var cookieName="search_map_settings_"+$F('sid');var cookieValue=$F('mapType')+'|'+$F('mapFilterView')+'|'+$F('mapView');expire.setTime(today.getTime()+this.options.mapSettingsCookieTimeout);document.cookie=cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString();}
BaseMapControl.prototype.addMarkers=function(type,options){if(type=='hotel'){if(!serializedHotelJson){return;}
serializedMarkers=serializedHotelJson.evalJSON();}else if(type=='airport'){if(!serializedAirportJson){return;}
serializedMarkers=serializedAirportJson.evalJSON();}else if(type=='event'){if(!serializedEventJson){return;}
serializedMarkers=serializedEventJson.evalJSON();}
if(!options){options={};}
if(!this.markers[type]){this.markers[type]=new Array();}
if(!this.markerOptions[type]){this.markerOptions[type]=options;}
var bounds=new GLatLngBounds();for(var i=0;i<serializedMarkers.length;i++){if(serializedMarkers[i].noShowOnMap){continue;}
pinNumber=(serializedMarkers[i].hotelNumCounter==null)?(i+1):(serializedMarkers[i].hotelNumCounter);point=new GLatLng(serializedMarkers[i].latitude,serializedMarkers[i].longitude);this.markers[type][i]=this.createMarker(point,serializedMarkers[i],type,pinNumber);bounds.extend(point);this.map.addOverlay(this.markers[type][i]);}
if(this.options.zoomToBounds===true||options.zoomToBounds===true){this.map.setZoom(this.map.getBoundsZoomLevel(bounds));this.map.setCenter(bounds.getCenter());}else if(options.zoom){this.map.setZoom(zoom);}};BaseMapControl.prototype.addMarker=function(type,options){if(!this.markers[type]){this.markers[type]=new Array();}
if(options){if(!this.markerOptions[type]){this.markerOptions[type]=options;}}else{options={};}
point=new GLatLng(options.latitude,options.longitude);this.markers[type][options.index]=this.createMarker(point,options,type,options.index);this.map.addOverlay(this.markers[type][options.index]);};BaseMapControl.prototype.removeAllMarkers=function(type){if(!this.markers[type]){return;}
for(var s in this.markers[type]){if(typeof this.markers[type][s]=='function')continue;if(this.markers[type][s]){this.map.removeOverlay(this.markers[type][s]);}}
this.closeInfoWindow(null,type);};BaseMapControl.prototype.createMarker=function(point,info,type,number){var iconOptions={};if(info.favoriteStatus=='preferred'){iconOptions.preferred=true;}
markerOptions={icon:this.makeIcon(type,number,iconOptions)}
if(this.markerOptions[type]&&this.markerOptions[type].nameHover){markerOptions.title=info.name;}
var marker=new GMarker(point,markerOptions);if(this.markerOptions[type]&&this.markerOptions[type].drawHover||this.markerOptions[type].drawClick){var me=this;var map=this.map;if(this.markerOptions[type].drawClick){GEvent.addListener(marker,'click',function(){me.addInfoWindow(type,marker,info);});}
if(this.markerOptions[type].drawHover){GEvent.addListener(marker,'mouseover',function(){marker.openCustomInfoWindow(map,'hover',info);});GEvent.addListener(marker,'mouseout',function(){marker.closeCustomInfoWindow(map,'hover');});}}
if(info.clickCallback){var numClickParams=0;if(info.clickCallbackParams){numClickParams=info.clickCallbackParams.length;}
GEvent.addListener(marker,"click",function(){toggle_neighborhood_polygon(info.clickCallbackParams[0]);});}
if(this.markerOptions[type]&&this.markerOptions[type].scrollToHotelCallback){GEvent.addListener(marker,"click",function(){new Effect.ScrollTo('hotelCard-'+info.hotelId);});}
return marker;};BaseMapControl.prototype.makeIcon=function(type,number,options){var icon=new GIcon(G_DEFAULT_ICON);if(type=='neighborhood'){icon.image='/images/hotelicopter/map/map-pin-neighborhood.png';icon.shadow="/images/hotelicopter/map/square-pin-shadow.png";icon.shadowSize=new GSize(20,34);}else if(type=='airport'){icon.image='/images/hotelicopter/map/map-airport-icon.png';icon.iconSize=new GSize(32,32);icon.iconAnchor=new GPoint(16,16);}else if(type=='event'){icon.image='/images/hotelicopter/map/map-pin-orange-wdot.png';}else if(this.markerOptions[type]&&this.markerOptions[type].noNumbers){icon.image="/images/hotelicopter/map/map-pin-grey.png";}else{if((parseInt(this.markerOptions[type]&&this.markerOptions[type].offset)>=100)||number>100){if(options.preferred){icon.image="/images/hotelicopter/map/map-pin-orange.png";}else{icon.image="/images/hotelicopter/map/map-pin-grey.png";}}else{var topPos=(number-1)*34;var imgsuffix;if(number<=25){imgsuffix='1-25';}
else if(number<=50){imgsuffix='26-50';}
else if(number<=50){imgsuffix='51-75';}
else if(number<=50){imgsuffix='76-100';}
if(options.preferred){icon.sprite={image:'/images/hotelicopter/map/map-pins-orange-'+imgsuffix+'.png',width:20,height:34,top:topPos}}else{icon.sprite={image:'/images/hotelicopter/map/map-pins-gry-'+imgsuffix+'.png',width:20,height:34,top:topPos}}}}
if(!icon.sprite){if(!icon.iconSize){icon.iconSize=new GSize(20,34);}
if(!icon.iconAnchor){icon.iconAnchor=new GPoint(9,34);}}
if(type=='hotel'){icon.shadow="/images/hotelicopter/map/map-pin-shadow.png";icon.shadowSize=new GSize(37,34);}
return icon;};BaseMapControl.prototype.addInfoWindow=function(type,marker,info){var me=this;var map=this.map;var closingExistingCard=false;if(this.infoWindows[type]){var lastInfoWindow=this.infoWindows[type];var lastMarker=lastInfoWindow.marker;if(marker.CustomInfoWindowInstanceClick){closingExistingCard=true;}
me.closeInfoWindow(lastMarker,type);}
if(!closingExistingCard){marker.openCustomInfoWindow(map,'click',info,this.options.hotelPhotoOptions);this.infoWindows[type]={marker:marker,info:info}
this.hotelCardListener=GEvent.addListener(map,'zoomend',function(){me.closeInfoWindow(marker,type);me.addInfoWindow('hotel',marker,info);});}};BaseMapControl.prototype.closeInfoWindow=function(marker,type){if(!marker){if(this.infoWindows[type]){var lastInfoWindow=this.infoWindows[type];if(lastInfoWindow){marker=lastInfoWindow.marker;}else{return;}}else{return;}}
marker.closeCustomInfoWindow(this.map,'click')
this.infoWindows[type]=null;GEvent.removeListener(this.hotelCardListener);};BaseMapControl.prototype.addFilterByBounds=function(filterOnInit){map=this.map;me=this;if(filterOnInit==true){me.doFilterByBounds();}
this.filterByBoundsPanHandler=GEvent.addListener(map,"moveend",function(){me.doFilterByBounds();});};BaseMapControl.prototype.doFilterByBounds=function(){if($F('mapView')!='default'){return;}else{if(!this.filteringByBounds){this.filteringByBounds=true;bounds=this.map.getBounds();$('mapFilterBounds').value=[bounds.getSouthWest().lat(),bounds.getSouthWest().lng(),bounds.getNorthEast().lat(),bounds.getNorthEast().lng()].join(',');goToHResultOffset(0,$F('limitinput'));refineSearch();this.filteringByBounds=false;}}};BaseMapControl.prototype.removeFilterByBounds=function(){if(this.filterByBoundsPanHandler){GEvent.removeListener(this.filterByBoundsPanHandler);}
this.options.zoomToBounds=false;};BaseMapControl.prototype.addStreetViewControl=function(){this.streetviewControl=new ExtStreetviewControl();this.map.addControl(this.streetviewControl);};BaseMapControl.prototype.removeStreetViewControl=function(){var streetViewMarker=this.streetviewControl.marker_;streetViewMarker.iconContainer_.parentNode.removeChild(streetViewMarker.iconContainer_);this.map.removeOverlay(streetViewMarker);this.map.removeControl(this.streetviewControl);};BaseMapControl.prototype.toggleNeighborhoodPolygon=function(locationId){locationId=parseInt(locationId);if(this.neighborhoodPolygonStatuses!==false&&this.neighborhoodPolygonStatuses[locationId]!==false){if(this.neighborhoodPolygonStatuses[locationId]==0){this.neighborhoodPolygons[locationId].setFillStyle({opacity:this.options.polyStyle.bgOpacityFilled});this.neighborhoodPolygonStatuses[locationId]=1
$('neighborhood_'+locationId).checked=true;neighborhoodsEnabledStr=$('mapNeighborhoodsEnabled').value;if($F('mapNeighborhoodsEnabled')!=''){neighborhoodsEnabledStr+=',';}
neighborhoodsEnabledStr+=locationId;$('mapNeighborhoodsEnabled').value=neighborhoodsEnabledStr;}else{this.neighborhoodPolygons[locationId].setFillStyle({opacity:this.options.polyStyle.bgOpacity});this.neighborhoodPolygonStatuses[locationId]=0
$('neighborhood_'+locationId).checked=false;neighborhoodArr=$F('mapNeighborhoodsEnabled').split(',');newNeighborhoodArr=new Array();currentIndex=0;for(var s in neighborhoodArr){if(typeof neighborhoodArr[s]=='function')continue;if(neighborhoodArr[s]!=locationId){newNeighborhoodArr[currentIndex]=neighborhoodArr[s];currentIndex++;}}
if(newNeighborhoodArr.length>0){$('mapNeighborhoodsEnabled').value=newNeighborhoodArr.join(',');}else{$('mapNeighborhoodsEnabled').value='';}}}};BaseMapControl.prototype.toggleAllNeighborhoodPolygons=function(type){if(this.neighborhoodPolygonStatuses!==false){for(var locationId in this.neighborhoodPolygonStatuses){if(typeof this.neighborhoodPolygonStatuses[locationId]=='function')continue;var filled=$('neighborhood_'+locationId).checked;if((type=='select'&&!filled)||(type=='unselect'&&filled)){this.toggleNeighborhoodPolygon(locationId);}}}}
BaseMapControl.prototype.drawNeighborhoodPolygons=function(){polygonJson=serializedNeighborhoodJson.evalJSON();this.neighborhoodPolygons=new Array();this.neighborhoodPolygonStatuses=new Array();var counter=0;for(var s in polygonJson){if(typeof polygonJson[s]=='function')continue;counter++;var filled=$('neighborhood_'+polygonJson[s].locationId).checked;var createdPolygon=this.drawPolygon(polygonJson[s].points,filled);this.neighborhoodPolygons[polygonJson[s].locationId]=createdPolygon;if(filled){this.neighborhoodPolygonStatuses[polygonJson[s].locationId]=1;}else{this.neighborhoodPolygonStatuses[polygonJson[s].locationId]=0;}
this.map.addOverlay(createdPolygon);this.addMarker('neighborhood',{index:counter,latitude:polygonJson[s].latitude,longitude:polygonJson[s].longitude,name:polygonJson[s].name,noNumbers:true,nameHover:true,clickCallback:"toggle_neighborhood_polygon",clickCallbackParams:[polygonJson[s].locationId]});}};BaseMapControl.prototype.removeNeighborhoodPolygons=function(){polygonJson=serializedNeighborhoodJson.evalJSON();if(!this.neighborhoodPolygons){return;}
for(var s in this.neighborhoodPolygons){if(typeof this.neighborhoodPolygons[s]=='function')continue;this.map.removeOverlay(this.neighborhoodPolygons[s]);}
this.removeAllMarkers('neighborhood');delete this.neighborhoodPolygons;delete this.neighborhoodPolygonStatuses;};BaseMapControl.prototype.drawPolygon=function(points,filled){var cPoints=[];for(var s in points){value=points[s];if(typeof value=='function')continue;point=new GPoint(value.lng,value.lat);cPoints.push(point)}
var bgOpacity=this.options.polyStyle.bgOpacity;if(filled){bgOpacity=this.options.polyStyle.bgOpacityFilled;}
var polygon=new GPolygon(cPoints,this.options.polyStyle.strokeColor,this.options.polyStyle.strokeWeight,this.options.polyStyle.strokeOpacity,this.options.polyStyle.bgColor,bgOpacity);return polygon;};BaseMapControl.prototype.updateRadiusFilter=function(latitude,longitude,radius){$('mapFilterLatitude').value=latitude;$('mapFilterLongitude').value=longitude;$('mapFilterRadius').value=radius;if(this.radiusFilterPoly){this.map.removeOverlay(this.radiusFilterPoly);}
d2r=Math.PI/180;r2d=180/Math.PI;earthR=3963;cLat=(radius/earthR)*r2d;cLng=cLat/Math.cos(latitude*d2r);var cPoints=[];for(var i=0;i<65;i++){theta=Math.PI*(i/32);cX=longitude+(cLng*Math.cos(theta));cY=latitude+(cLat*Math.sin(theta));point=new GPoint(cX,cY);cPoints.push(point)}
this.radiusFilterPoly=new GPolygon(cPoints,this.options.polyStyle.strokeColor,this.options.polyStyle.strokeWeight,this.options.polyStyle.strokeOpacity,this.options.polyStyle.bgColor,this.options.polyStyle.bgOpacityFilled);this.map.addOverlay(this.radiusFilterPoly);};BaseMapControl.prototype.removeRadiusFilter=function(){if(this.radiusFilterPoly){this.map.removeOverlay(this.radiusFilterPoly);}};BaseMapControl.prototype.setGoogleBar=function(action){if(action=='disable'){if(this.options.googleBarEnabled!==false){this.map.disableGoogleBar();this.options.googleBarEnabled=false;}}else{if(this.options.googleBarEnabled===false){this.map.enableGoogleBar();this.options.googleBarEnabled=true;}}};