(function(a){var b=200,c=false,d={mapOptions:{zoom:10,mapTypeControl:c,mapTypeId:google.maps.MapTypeId.ROADMAP,minZoom:5,maxZoom:15},ui:{canvas:"b2b-location-canvas",locationItems:"b2b-location-items",centerLoc:"b2b-location-center",navs:"b2b-location-nav",navUp:"b2b-location-nav .b2b-location-nav-up",navDown:"b2b-location-nav .b2b-location-nav-down",locationItemsContainer:"b2b-location-items-container",seeMore:"b2b-location-see-more"},img:{infoBoxClose:"http://townsquareinteractive.com/wp-content/themes/tsm-theme-1/plugins/_the_map/img/map-close-button.png",toolTipArrow:"http://townsquareinteractive.com/wp-content/themes/tsm-theme-1/plugins/_the_map/img/map-tooltip-arrow.png",transparentBg:"http://townsquareinteractive.com/wp-content/themes/tsm-theme-1/plugins/_the_map/img/b2b-map-overlay-bg.png",marker:"http://townsquareinteractive.com/wp-content/themes/tsm-theme-1/plugins/_the_map/img/b2b-maps-marker.png",markerShadow:"http://townsquareinteractive.com/wp-content/themes/tsm-theme-1/plugins/_the_map/img/b2b-maps-marker-shadow.png"},toolboxWidth:b,toolBoxFontSize:12,showInfoWindow:0,showDetailsOnClick:1,itemHeight:70,isAnimating:c,currentUlPosition:0,zoom:8,map:"",latlongArray:[],infoWindowArray:[],markerArray:[]};a.googleMapsPlugin=function(v){var p="click",E=".b2b-location-basic-info",D=".b2b-location-detail-info,.b2b-location-see-more",o="block",n="top",m="easeOutCubic",r="none",q="undefined",u="location",g=28,j=".",k=true;if(!v.elem)a.extend(k,d,v);else{var e=a.extend(k,{},d,v),O=e.elem,l=a(O),M=l.find(j+e.ui.canvas),f=l.find(j+e.ui.locationItems+" > ul"),h=l.find(j+e.ui.locationItems+" > ul > li"),F=new google.maps.LatLngBounds,B=l.find(j+e.ui.navs),N=l.find(j+e.ui.navUp),I=l.find(j+e.ui.navDown),P=l.find(j+e.ui.seeMore),x="show-details",C,s,G,J=new google.maps.Geocoder,w={image:new google.maps.MarkerImage(e.img.marker,new google.maps.Size(29,29),new google.maps.Point(0,0),new google.maps.Point(15,29)),shadow:new google.maps.MarkerImage(e.img.markerShadow,new google.maps.Size(47,29),new google.maps.Point(0,0),new google.maps.Point(15,29)),shape:{coord:[19,0,21,1,23,2,24,3,25,4,26,5,26,6,27,7,27,8,g,9,g,10,g,11,g,12,g,13,g,14,g,15,g,16,g,17,g,18,g,19,27,20,27,21,26,22,26,23,25,24,24,25,23,26,21,27,19,g,9,g,7,27,5,26,4,25,3,24,2,23,2,22,1,21,1,20,0,19,0,18,0,17,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,1,8,1,7,2,6,2,5,3,4,4,3,5,2,7,1,9,0,19,0],type:"poly"}},A,i,H,t,z=function(a){if(e.showDetailsOnClick){typeof a.data(u)!==q&&e.map.panTo(e.latlongArray[parseInt(a.attr("data-index"),10)-1]);h.removeClass(x);f.find(".b2b-location-see-more").css({display:r});f.fadeOut(b,m,function(){a.addClass(x);e.currentUlPosition=f.css(n);B.css({display:r});f.css({top:"0px"});h.css({display:r});a.css({display:o});a.find(D).css({display:o});f.fadeIn(b,m)})}if(e.showInfoWindow){t=h.index(a.get(0));s&&s.close();s=e.infoWindowArray[t];s.open(e.map,e.markerArray[t])}},L=function(c,a){a.fadeOut(b,m,function(){c.removeClass(x);a.css({top:e.currentUlPosition});h.css({display:o});a.find(D).css({display:r});a.fadeIn(b,m,function(){h.length>4&&B.css({display:o})})})},y=function(b,c){if(c<b.length){var d=a(b[c]);J.geocode({address:d.attr("data-address")},function(e,a){if(a===google.maps.GeocoderStatus.OK){try{console.log(e)}catch(f){}d.data(u,e[0].geometry.location);y(b,++c)}else if(a===google.maps.GeocoderStatus.ZERO_RESULTS)y(b,++c);else a===google.maps.GeocoderStatus.OVER_QUERY_LIMIT&&alert("Too many locations.")})}else{K();return}},K=function(){e.map=new google.maps.Map(M[0],e.mapOptions);h.each(function(){var b=a(this),d=b.data("lat"),f=b.data("long");i=b.data(u);if(typeof d!==q&&typeof f!==q)if(d!==""&&f!=="")i=new google.maps.LatLng(d,f);if(typeof i!==q){F.extend(i);if(b.hasClass(e.ui.centerLoc))H=i;e.latlongArray.push(i);A=new google.maps.Marker({position:i,icon:w.image,shadow:w.shadow,shape:w.shape,map:e.map,title:b.find(".b2b-location-basic-info > h2").html()});e.markerArray.push(A);G=new InfoBox({content:"<div style=\"margin:0px 0px 11px 0px; overflow:hidden; background:url('"+e.img.transparentBg+"'); padding:10px 15px; width:"+(e.toolboxWidth-30)+'px">'+b.find(E).html()+"</div>",boxStyle:{textAlign:"left",lineHeight:"17px",fontSize:e.toolBoxFontSize+"px",width:e.toolboxWidth+"px",background:"url('"+e.img.toolTipArrow+"') no-repeat center bottom",color:"#fff"},alignBottom:k,disableAutoPan:k,pixelOffset:new google.maps.Size(e.toolboxWidth/-2,-32),closeBoxMargin:"-7px -6px -10px -8px",closeBoxURL:e.img.infoBoxClose,isHidden:c,pane:"floatPane",enableEventPropagation:k});e.infoWindowArray.push(G);google.maps.event.addListener(A,p,function(b){e.map.setZoom(e.zoom+5);e.map.setCenter(b.latLng);for(i in e.latlongArray)if(e.latlongArray[i]===b.latLng)break;z(a(h[i]))})}});e.map.fitBounds(F);e.zoom=e.map.getZoom();if(h.length===1){e.map.setZoom(5);z(a(h[0]))}};y(h,0);f.delegate(E,p,function(){z(a(this).parents("li"))}).delegate(j+e.ui.seeMore,p,function(){L(a(this).parents("li"),a(this).parents("ul"))});if(h.length>4){C=e.itemHeight*4;I.bind(p,function(){if(parseInt(f.css(n),10)>C-f.height()&&!e.isAnimating){e.isAnimating=k;f.stop().animate({top:parseInt(f.css(n),10)-e.itemHeight},{duration:b,easing:m,complete:function(){e.isAnimating=c}})}});N.bind(p,function(){if(parseInt(f.filter(":first-child").css(n),10)<0&&!e.isAnimating){e.isAnimating=k;f.stop().animate({top:parseInt(f.css(n),10)+e.itemHeight},{duration:b,easing:m,complete:function(){e.isAnimating=c}})}});B.css({display:o})}}};a.fn.googleMapsPlugin=function(b){return this.each(function(){b=b||{};b.elem=this;a.googleMapsPlugin(b)})};!a.easing.easeInCubic&&a.extend(a.easing,{easeInCubic:function(e,a,b,c,d){return c*(a/=d)*a*a+b}});!a.easing.easeOutCubic&&a.extend(a.easing,{easeOutCubic:function(e,a,b,c,d){return c*((a=a/d-1)*a*a+1)+b}})})(jQuery);
