
Citysearch.MapsProfile={Id:{mapContainerDivId:"mapContainer",directionFormId:"mapDirection",selectDirectionId:"direction",inputAddressFieldId:"addr",directionResultDivId:"mapDirectionResult",mapActionsDivId:"mapActions",printDirectionLinkId:"printDir",reverseDirectionLinkId:"reverseDir",mapControlScreenClass:".map-controls-bg",printButtonDivId:"mapPrintButton",printProfileInfoId:"mapPrintInfo",printProfileNameId:"mapInfoTitle",printProfileAddrId:"profileAddr",printMapContainerId:"mapsPrintContainer",printMapWindowId:"staticMap",printMapDrivingId:"printDirections"},mapHeight:410,selectFromValue:"from",selectToValue:"to",directionLoadingClass:"ajaxLoading",directionLoadingDelay:1000,init:function(){if((!$defined(Citysearch.CoreInfo.latitude)||!$defined(Citysearch.CoreInfo.longitude))||(Citysearch.CoreInfo.latitude===0&&Citysearch.CoreInfo.longitude===-1)||(Citysearch.CoreInfo.latitude===0&&Citysearch.CoreInfo.longitude===0)){if(Citysearch.CoreInfo.street&&Citysearch.CoreInfo.city&&Citysearch.CoreInfo.state&&Citysearch.CoreInfo.postalCode){this.profileGeoAddr=Citysearch.Map.geocode(Citysearch.CoreInfo.street,Citysearch.CoreInfo.city,Citysearch.CoreInfo.state,Citysearch.CoreInfo.postalCode);var latLng=Citysearch.Map.getLatLng(this.profileGeoAddr);Citysearch.CoreInfo.latitude=latLng.latitude;Citysearch.CoreInfo.longitude=latLng.longitude;}
else{return;}}
$extend(this,Citysearch.TempConfig.MapsProfile);Citysearch.TempConfig.MapsProfile=null;this.latitude=Citysearch.CoreInfo.latitude;this.longitude=Citysearch.CoreInfo.longitude;this.mapContainerDiv=$(this.Id.mapContainerDivId);this.selectDirection=$(this.Id.selectDirectionId);this.directionResultDiv=$(this.Id.directionResultDivId);this.mapActionsDiv=$(this.Id.mapActionsDivId);this.printButtonDiv=$(this.Id.printButtonDivId);this.profileAddress=Citysearch.CoreInfo.street+'<br />'+Citysearch.CoreInfo.city+', '+Citysearch.CoreInfo.state+' '+Citysearch.CoreInfo.postalCode;this.drawMap();this.addDirection();this.addPrint('map');this.resizeControls();},drawMap:function(){var availableWidth=Citysearch.Utils.getDimensions(this.mapContainerDiv).x;var mapDiv=new Element('div');mapDiv.setStyles({'width':availableWidth,'height':this.mapHeight});this.map=Citysearch.Map.draw(mapDiv,{'lat':this.latitude,'lon':this.longitude,'zoom':Citysearch.Map.Zoom.neighborhood,'type':Citysearch.Map.Type.street});Citysearch.Map.addControl.zoom(this.map);Citysearch.Map.addControl.typeSwitcher(this.map);this.mapPoisArray=[];if(this.ads){for(i=0;i<this.ads.length;i++){var target=this.ads[i];var poi=Citysearch.Map.point(target.lat,target.lon,{'icon':Citysearch.Map.icon(Citysearch.imagePath+'/map/icon_sponsor_pin.png'),'hoverIcon':Citysearch.Map.icon(Citysearch.imagePath+'/map/icon_sponsor_pin_hover.png'),'popupTitle':target.name,'popupContent':target.stars+target.address});Citysearch.Map.addListener(poi,'mouseover',function(){Citysearch.Map.hoverOn(this);this.showInfoWindow();});Citysearch.Map.addListener(poi,'mouseout',function(){Citysearch.Map.hoverOff(this);Citysearch.MapsProfile.map.getInfoWindow().hide();});this.mapPoisArray.push(poi);}}
this.profilePoi=Citysearch.Map.point(this.latitude,this.longitude,{'icon':Citysearch.Map.icon(Citysearch.imagePath+'/map/icon_primary.png'),'hoverIcon':Citysearch.Map.icon(Citysearch.imagePath+'/map/icon_primary.png'),'popupTitle':'<a href="#overview">'+this.profileName+'</a>','popupContent':Citysearch.CoreInfo.stars+this.profileAddress});Citysearch.Map.addListener(this.profilePoi,'mouseover',function(){Citysearch.Map.hoverOn(this);this.showInfoWindow();});Citysearch.Map.addListener(this.profilePoi,'mouseout',function(){Citysearch.Map.hoverOff(this);Citysearch.MapsProfile.map.getInfoWindow().hide();});this.mapPoisArray.push(this.profilePoi);Citysearch.Map.populate(this.map,this.mapPoisArray);if(this.ads&&this.ads.length>0){Citysearch.Map.setZoom(this.map,Citysearch.Map.Zoom.neighborhood);}
else{Citysearch.Map.setZoom(this.map,Citysearch.Map.Zoom.street);}
this.mapContainerDiv.grab(mapDiv);Citysearch.Map.resize(this.map,mapDiv,this.mapContainerDiv);var boundResize=Citysearch.Map.resize.pass([this.map,mapDiv,this.mapContainerDiv]);window.addEvent('resize',boundResize);},addDirection:function(){$(this.Id.directionFormId).addEvent('submit',function(e){e.preventDefault();Citysearch.BillableLead.log(Citysearch.MapsProfile.trackingPath);if($(Citysearch.MapsProfile.Id.inputAddressFieldId).value!==''){Citysearch.MapsProfile.directionResultDiv.addClass(Citysearch.MapsProfile.directionLoadingClass);var doRoute=function(){this.inputGeoAddr=Citysearch.Map.geocode($(this.Id.inputAddressFieldId).value);this.inputLatLng=Citysearch.Map.getLatLng(this.inputGeoAddr);if(this.inputLatLng.latitude===0&&this.inputLatLng.longitude===0){this.printDirectionError(2);return;}
this.inputAddress=(this.inputLatLng.street!=='')?this.inputLatLng.street+'<br />':'';this.inputAddress+=this.inputLatLng.city+', '+this.inputLatLng.state+' '+this.inputLatLng.postalCode;this.inputPoi=Citysearch.Map.point(this.inputLatLng.latitude,this.inputLatLng.longitude,{'popupContent':this.inputAddress});this.updateIcons(this.profilePoi,this.inputPoi);Citysearch.Map.populate(this.map,[this.profilePoi,this.inputPoi]);if(!$defined(this.profileGeoAddr)){this.profileGeoAddr=Citysearch.Map.geocode(Citysearch.CoreInfo.street,Citysearch.CoreInfo.city,Citysearch.CoreInfo.state,Citysearch.CoreInfo.postalCode);}
if(this.selectDirection.get('value')===this.selectFromValue){Citysearch.Map.route(this.map,this.inputGeoAddr,this.profileGeoAddr,this.directionResultDiv);}
else{Citysearch.Map.route(this.map,this.profileGeoAddr,this.inputGeoAddr,this.directionResultDiv);}
if(!$defined($(this.Id.reverseDirectionLinkId))){var reverseButton=Citysearch.ButtonFactory.createButton(Citysearch.Text.MapsProfile.reverseDirections,'action',{'id':this.Id.reverseDirectionLinkId,'name':'listing_profile/maps_directions/reverse_directions','actionSprite':'reverseDirectionsIcon'});var reverseEvent=function(e){e.preventDefault();var mpObj=Citysearch.MapsProfile;if(mpObj.selectDirection.get('value')===mpObj.selectFromValue){mpObj.selectDirection.set('value',mpObj.selectToValue);mpObj.directionResultDiv.addClass(mpObj.directionLoadingClass);var doRoute=function(){Citysearch.Map.route(mpObj.map,mpObj.profileGeoAddr,mpObj.inputGeoAddr,mpObj.directionResultDiv);mpObj.directionResultDiv.removeClass(mpObj.directionLoadingClass);};doRoute.delay(mpObj.directionLoadingDelay);}
else{mpObj.selectDirection.set('value',mpObj.selectFromValue);mpObj.directionResultDiv.addClass(mpObj.directionLoadingClass);var doRoute=function(){Citysearch.Map.route(mpObj.map,mpObj.inputGeoAddr,mpObj.profileGeoAddr,mpObj.directionResultDiv);mpObj.directionResultDiv.removeClass(mpObj.directionLoadingClass);};doRoute.delay(mpObj.directionLoadingDelay);}
mpObj.updateIcons(mpObj.profilePoi,mpObj.inputPoi);};reverseButton.addEvent('click',reverseEvent);this.mapActionsDiv.grab(reverseButton);}
this.directionResultDiv.removeClass(this.directionLoadingClass);};var boundDoRoute=doRoute.bind(Citysearch.MapsProfile);boundDoRoute.delay(Citysearch.MapsProfile.directionLoadingDelay);}
else{Citysearch.MapsProfile.printDirectionError(1);}});},updateIcons:function(profilePoi,inputPoi){if(this.selectDirection.get('value')===this.selectFromValue){Citysearch.Map.changeIcon(profilePoi,Citysearch.imagePath+'map/icon_number002_hover.png');Citysearch.Map.changeIcon(inputPoi,Citysearch.imagePath+'map/icon_number001_hover.png');Citysearch.Map.setPoiProperties(inputPoi,{'popupTitle':Citysearch.Text.MapsProfile.startAddress});}
else{Citysearch.Map.changeIcon(profilePoi,Citysearch.imagePath+'map/icon_number001_hover.png');Citysearch.Map.changeIcon(inputPoi,Citysearch.imagePath+'map/icon_number002_hover.png');Citysearch.Map.setPoiProperties(inputPoi,{'popupTitle':Citysearch.Text.MapsProfile.endAddress});}},addPrint:function(type){if(type==='map'){var printButton=Citysearch.ButtonFactory.createButton(Citysearch.Text.MapsProfile.printMap,'action print',{'id':this.Id.printDirectionLinkId,'name':'listing_profile/map_directions/print_map_directions','actionSprite':'printIcon'});this.mapActionsDiv.grab(printButton);}
else if(type==='direction'){var printButton=Citysearch.ButtonFactory.createButton(Citysearch.Text.MapsProfile.printDirections,'action print',{'id':this.Id.printDirectionLinkId,'name':'listing_profile/maps_directions/print_map_directions','actionSprite':'printIcon'});this.mapActionsDiv.grab(printButton);}
printButton.addEvent('click',function(e){e.preventDefault();Citysearch.ModalWindow.fireNewModal(Citysearch.MapsProfile.printPath,Citysearch.Text.MapsProfile.popupTitle);Citysearch.TempConfig.printNow=true;});},goPrint:function(){this.printMapContainer=$(this.Id.printMapContainerId);this.printMapWindow=$(this.Id.printMapWindowId);this.printMap=Citysearch.Map.draw(this.printMapWindow,{'lat':this.latitude,'lon':this.longitude});this.printProfilePoi=Citysearch.Map.point(this.latitude,this.longitude,{'icon':Citysearch.Map.icon(Citysearch.imagePath+'/map/icon_primary.png')});if(Citysearch.CoreInfo.listingTitle!=null){var listingTitle=new Element('div',{'id':this.Id.printProfileNameId,'text':Citysearch.CoreInfo.listingTitle});$(this.Id.printProfileInfoId).grab(listingTitle);}
var profileAddress=Citysearch.Map.addressFormat(Citysearch.CoreInfo.street,Citysearch.CoreInfo.city,Citysearch.CoreInfo.state,Citysearch.CoreInfo.postalCode);var addressInfo=new Element('div',{'id':this.Id.printProfileAddrId,'text':'Address: '+profileAddress});$(this.Id.printProfileInfoId).grab(addressInfo);if(!$defined(this.routeResults)){Citysearch.Map.populate(this.printMap,[this.printProfilePoi]);}
else{this.printMapDriving=$(this.Id.printMapDrivingId);this.printInputPoi=Citysearch.Map.point(this.inputLatLng.latitude,this.inputLatLng.longitude);this.updateIcons(this.printProfilePoi,this.printInputPoi);Citysearch.Map.populate(this.printMap,[this.printProfilePoi,this.printInputPoi]);this.printMap.addRouteHighlight(this.boundBox,"http://map.access.mapquest.com",this.sessId,true);if(this.selectDirection.get('value')===this.selectFromValue){Citysearch.Map.drivingDirections(this.inputGeoAddr,this.profileGeoAddr,this.printMapDriving);}
else{Citysearch.Map.drivingDirections(this.profileGeoAddr,this.inputGeoAddr,this.printMapDriving);}
$(this.Id.printMapDrivingId).setStyle('display','block');Citysearch.ModalWindow.reset();}
var printLink=new Element('a',{'text':Citysearch.Text.MapsProfile.printLink,'name':'listing_profile/map_directions/print','href':'#','events':{'click':function(e){e.preventDefault();window.print();}}});var printIcon=new Element('span',{'class':'actionSprite printIcon'});printLink.grab(printIcon,'top');$(this.Id.printButtonDivId).grab(printLink);Citysearch.Map.resize(this.printMap,this.printMapWindow,this.printMapContainer);this.printMap.showStaticMap();this.printMap.grab(this.printMapWindow,'top');var printLater=function(){window.print();};printLater.delay(Citysearch.ModalWindow.animationDuration+1000);},printDirectionError:function(errorCode){if(errorCode===1){var errorMsg=Citysearch.Text.MapsProfile.noAddress;}
else if(errorCode===2){var errorMsg=Citysearch.Text.MapsProfile.invalidAddress;}
var errorSpan=new Element('span',{'id':'directionError','text':errorMsg});Citysearch.MapsProfile.directionResultDiv.empty();Citysearch.MapsProfile.directionResultDiv.grab(errorSpan);},resizeControls:function(){if($(this.Id.mapContainerDivId).getElement('.map-controls-bg')){var backgroundDivs=$(this.Id.mapContainerDivId).getElement(this.Id.mapControlScreenClass).getElements('div');backgroundDivs[1].setStyle('height',186);}}};window.addEvent('domready',function(){Citysearch.MapsProfile.init();});