XLI.SearchResultsMapper=function(){var i=false;var f={MODULE_ID:"#map",LISTING_SELECTOR:"#primary h3, #primary .result",SCROLLABLE_SELECTOR:"#primary ."+XLI.Global.C.SCROLLABLE_CLASS,SECONDARY_ID:"#secondary",DEFAULT_STATE:", NY, USA",MARKER_BASE_URL:"/css/exploreli/img/markers/",FAVE_CLASS:"fave",CLICKABLE_CLASS:"clickable",VIEW_ON_MAP_TEXT:"View on Map",MAP_TRIGGER_HTML:'<h2 class="gl" id="hd_mapResults"><span></span>Map Results</h2>',MAP_TRIGGER_FOOTER_HTML:'<div id="ft_mapResults"></div>',MAP_TARGET_CLASS:"mapTarget",INITIALIZED_CLASS:"initialized",SCROLL_SPEED:500,VERTICAL_OFFSET:1,DETACHED_CLASS:"detached",BODY_AD_SELECTOR:"#primary iframe"};var x={htmlBody:null,window:$(window),module:null,nextSibling:null,mapResultsHeader:null,mapResultsFooter:null,mapTarget:null,mapWrapper:null,secondary:null,listings:null,bodyAds:null};var s=f;var c=x;var z;var n;var o=[];var m;var a;var q=function(){var C,A,B={},D=new GClientGeocoder();c.listings=$(s.LISTING_SELECTOR);c.listings.each(function(){var E=this,F=$(this);if(this.tagName.toLowerCase()==="h3"){C=j(this)}else{B.$details=F.find("dl:first");if(B.$details.length){B.$name=B.$details.find("h4:first");B.$address=B.$details.find(".address");this.name=j(B.$name.get(0));this.address=j(B.$address.get(0));this.category=C;this.markerContent="<dl>"+B.$details.html()+"</dl>";if(this.address!==""){B.$name.get(0).listing=this;B.$name.addClass(s.CLICKABLE_CLASS).attr("title",s.VIEW_ON_MAP_TEXT).bind("click",function(){if(this.listing.marker){this.listing.marker.openInfoWindow(this.listing.markerContent);if(k==="closed"){b()}}});XLI.Global.ie6Hover(B.$name);D.getLatLng(this.address+s.DEFAULT_STATE,function(G){if(G){E.latLon=G}})}o.push(this)}}})};var r=function(){c.htmlBody=$("html,body");c.secondary=$(s.SECONDARY_ID);c.nextSibling=c.module.find("+ *");c.nextSibling.data("oMarginTop",parseInt(c.nextSibling.css("margin-top"),10));c.mapResultsHeader=$(s.MAP_TRIGGER_HTML).bind("click",b).appendTo(c.module);c.mapTarget=$("<div></div>").addClass(s.MAP_TARGET_CLASS).css({position:"relative",top:"-1000px"});c.mapWrapper=$("<div></div>").css({position:"relative",overflow:"hidden",height:0}).append(c.mapTarget).appendTo(c.module);c.closeButton=$(XLI.Global.C.FLYOUT_CLOSE_HTML).bind("click",b).appendTo(c.mapWrapper);c.mapResultsFooter=$(s.MAP_TRIGGER_FOOTER_HTML).bind("click",b).appendTo(c.module);XLI.Global.ie6Hover(c.closeButton);c.module.addClass(s.INITIALIZED_CLASS);XLI.Global.ie6Hover(c.mapResultsHeader);m=c.module.offset();a=c.module.outerHeight();v()};var v=function(){z=new GMap2(c.mapTarget.get(0));z.setCenter(new GLatLng(0,0),0);z.setUI({controls:{largemapcontrol3d:true,maptypecontrol:false,scalecontrol:true},keyboard:true,maptypes:{hybrid:false,normal:true,physical:false,satellite:true},zoom:{doubleclick:true,scrollwheel:true}});window.setTimeout(g,500)};var g=function(){$.each(o,function(A,B){if(B.marker||B.icon||B.address===""||!B.address||(typeof B.retryCount==="number"&&B.retryCount===10)){return}if(!B.latLon){B.retryCount=B.retryCount||0;window.setTimeout(function(){B.retryCount++;g()},100);return false}B.icon=new GIcon(G_DEFAULT_ICON,s.MARKER_BASE_URL+p(B.category));B.marker=new GMarker(B.latLon,B.icon);B.marker.bindInfoWindowHtml(B.markerContent);z.addOverlay(B.marker)});h=true};var w=function(){var A=new GLatLngBounds();$.each(o,function(B,C){if(C.latLon&&C.address!==""){A.extend(C.latLon)}});z.setCenter(A.getCenter(),z.getBoundsZoomLevel(A))};var k="closed";var u=false;var h=false;var b=function(C){if(C){C.preventDefault()}if(u){return}u=true;var A=c.mapTarget.outerHeight(true);if(k==="closed"){if(XLI.Global.ie6){}else{c.nextSibling.css("padding-top",a+c.nextSibling.data("oMarginTop"));c.module.css("position","fixed")}c.window.bind("scroll",d);d();y();c.mapTarget.css({top:0-A}).animate({top:0},s.SCROLL_SPEED,"easeOutQuad",function(){k="open";u=false});c.mapWrapper.animate({height:A},s.SCROLL_SPEED,"easeOutQuad");if(!XLI.Global.ie6){c.nextSibling.animate({"padding-top":A+a},s.SCROLL_SPEED,"easeOutQuad")}if(!h){g()}w()}else{var B=c.window.scrollTop();c.module.css({position:(XLI.Global.ie6)?"static":"absolute",top:((B>m.top)?(B-m.top+s.VERTICAL_OFFSET):0)+"px"});c.window.unbind("scroll",d);t();c.mapTarget.css({top:0}).animate({top:0-A},s.SCROLL_SPEED,"easeOutQuad");c.mapWrapper.animate({height:0},s.SCROLL_SPEED,"easeOutQuad",function(){c.mapWrapper.css("overflow","hidden")});if(!XLI.Global.ie6){c.nextSibling.animate({"padding-top":a},s.SCROLL_SPEED,"easeOutQuad")}c.module.animate({top:m.top-c.module.offsetParent().offset().top},s.SCROLL_SPEED,"easeOutQuad",function(){k="closed";u=false;c.module.css({top:"auto",position:"static"});if(!XLI.Global.ie6){c.nextSibling.css({"padding-top":0})}})}};var j=function(B){if(typeof B!=="object"){return""}var A,C;for(A=0;A<B.childNodes.length;A++){C=B.childNodes[A];if(C.nodeType===3&&!!(/[^\t\n\r ]/.test(C.nodeValue))){return $.trim(C.nodeValue)}}return""};var p=function(B){if(typeof B!=="string"){return}B=B.toLowerCase();var A,C={eat:"marker_green.png","do":"marker_blue.png",go:"marker_chili.png",guides:"marker_purlple.png","default":"marker_fuschia.png"};$.each(C,function(D,E){if(B.indexOf(D)>-1){A=E;return false}});return A||C["default"]};var e=function(){c.htmlBody.animate({scrollTop:c.module.offset().top},s.SCROLL_SPEED,"easeOutQuad")};var l=function(){c.listings.each(function(){if(this.tagName.toLowerCase()==="h3"){return}var C=$(this),B=C,A=C.find(".favorite h4");A.bind("click",function(){B.addClass(s.FAVE_CLASS)});$("<p></p>").addClass("close").append($("<a></a>").attr("href","#").text("close").bind("click",function(D){D.preventDefault();B.removeClass(s.FAVE_CLASS)})).insertAfter(A)})};var d=function(){var B=c.window.scrollTop();var A=m.top-B;if(A<s.VERTICAL_OFFSET){c.module.addClass(s.DETACHED_CLASS);A=s.VERTICAL_OFFSET}else{c.module.removeClass(s.DETACHED_CLASS)}if(!XLI.Global.ie6){c.module.css("top",A+"px")}};var y=function(){if(XLI.Global.win||XLI.Global.moz){c.bodyAds=c.bodyAds||$(s.BODY_AD_SELECTOR);c.bodyAds.css("visibility","hidden")}};var t=function(){if(XLI.Global.win||XLI.Global.moz){c.bodyAds=c.bodyAds||$(s.BODY_AD_SELECTOR);c.bodyAds.css("visibility","visible")}};return{initialize:function(){if(i||typeof GMap2!=="function"){return}c.module=$(s.MODULE_ID);if(!c.module.length){return}q();r();l();i=true}}}();$(document).ready(XLI.SearchResultsMapper.initialize);