/**
 *  Maptimize Embedded Script v1
 *  
 *  © 2008 - 2010 Xilinus - All rights reserved
**/
/*
* LabeledMarker Class, v1.2
*
* Copyright 2007 Mike Purvis (http://uwmike.com)
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
*       http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This class extends the Maps API's standard GMarker class with the ability
* to support markers with textual labels. Please see articles here:
*
*       http://googlemapsbook.com/2007/01/22/extending-gmarker/
*       http://googlemapsbook.com/2007/03/06/clickable-labeledmarker/
*/

(function(K){var Q=K.document,P=K.Array,B=K.encodeURIComponent,D=K.setTimeout,T=K.console,F=function(){};function C(W,Y){for(var X in Y){W[X]=Y[X]}return W}function V(X,W){var Y={};for(var Z=0;Z<arguments.length;Z++){C(Y,arguments[Z])}return Y}function L(Y,Z){for(var X=0,W=Y.length;X<W;X++){Z(Y[X],X)}return Y}function I(X,Y){var W=new P(X.length);L(X,function(Z,a){W[a]=Y(Z,a)});return W}function U(Y,Z){for(var X=0,W=Y.length;X<W;X++){if(Z(Y[X],X)){return Y[X]}}return false}function H(W){return I(W,function(X){return X})}function A(W){var Y=[];for(var X in W){Y.push(B(X)+"="+B(W[X]))}return Y.join("&")}function G(W,Y){var X=W.initialize||function(){};delete W.initialize;C(X.prototype,W);return C(X,Y||{})}function N(W){return H(Q.getElementsByTagName(W))}function R(W){return"http://www.maptimize.com/images/"+W}var M=N("head")[0],S=U(N("script"),function(W){return W.src.match(/\/api\/v1\/.*\/embed/)}),J=S.src.replace(/embed.*$/,"");function O(X){var W=K.google,Y=W&&W.maps;return Y&&Y[X]||K["G"+X]||K["G_"+X]}if(!O("Map2")){var E=arguments;return D(function(){E.callee.apply(null,E)},100)}(function(X,a,h,j,q,W,b,Y,l,g,o,n,m,p){var k=G({initialize:function(s,t,u){this._a=s;this._b=u;this._c=t},_d:function(){var t=++k._e,s=this._f(t);k._g(t,this._b);M.appendChild(s);D(function(){M.removeChild(s)},5000)},_f:function(s){return C(Q.createElement("script"),{src:this._a+"?"+A(C(this._c,{callback:k._h+"._"+s})),type:"text/javascript"})}},{_e:0,_h:"XSSRequest._i",_i:{},_g:function(t,s){k._i["_"+t]=function(){delete k._i[t];s.apply(null,arguments)}},send:function(s,t,u){new k(s,t,u)._d()}});function i(t,s){this.latlng_=t;this.opts_=s;this.labelText_=s.labelText||"";this.labelClass_=s.labelClass;this.labelOffset_=s.labelOffset||new j(0,0);this.clickable_=s.clickable||true;this.title_=s.title||"";this.labelVisibility_=true;if(s.draggable){s.draggable=false}b.apply(this,arguments)}i.prototype=C(new b(new h(0,0)),{initialize:function(v){b.prototype.initialize.apply(this,arguments);this.map_=v;this.div_=Q.createElement("div");this.div_.className=this.labelClass_;this.div_.innerHTML=this.labelText_;this.div_.style.position="absolute";this.div_.style.cursor="pointer";this.div_.title=this.title_;v.getPane(n).appendChild(this.div_);if(this.clickable_){function s(y,x){return function(){X.trigger(y,x)}}var w=["click","dblclick","mousedown","mouseup","mouseover","mouseout"];for(var u=0;u<w.length;u++){var t=w[u];X.addDomListener(this.div_,t,s(this,t))}}},redraw:function(s){b.prototype.redraw.apply(this,arguments);var t=this.map_.fromLatLngToDivPixel(this.latlng_);var u=GOverlay.getZIndex(this.latlng_.lat());this.div_.style.left=(t.x+this.labelOffset_.width)+"px";this.div_.style.top=(t.y+this.labelOffset_.height)+"px";this.div_.style.zIndex=u},remove:function(){X.clearInstanceListeners(this.div_);if(this.div_.outerHTML){this.div_.outerHTML=""}if(this.div_.parentNode){this.div_.parentNode.removeChild(this.div_)}this.div_=null;b.prototype.remove.apply(this,arguments)},copy:function(){return new i(this.latlng_,this.opt_opts_)},show:function(){b.prototype.show.apply(this,arguments);if(this.labelVisibility_){this.showLabel()}else{this.hideLabel()}},hide:function(){b.prototype.hide.apply(this,arguments);this.hideLabel()},setLabelVisibility:function(s){this.labelVisibility_=s;if(!this.isHidden()){if(this.labelVisibility_){this.showLabel()}else{this.hideLabel()}}},getLabelVisibility:function(){return this.labelVisibility_},hideLabel:function(){this.div_.style.visibility="hidden"},showLabel:function(){this.div_.style.visibility="visible"}});var f=G({initialize:function(u,v,t,s){this._j=u;this._k=v;this._l=t;this._m=s},getGLatLng:function(){return this._j},getValueAvg:function(){return this._l},getValueSum:function(){return this._m},getMap:function(){return this._n},_o:function(s){this._n=s;s._p().addOverlay(this.getGMarker());this._q=X.bind(this.getGMarker(),"click",this,this._r)},_s:function(){this._n._p().removeOverlay(this.getGMarker());X.removeListener(this._q)},openPopup:function(s){var u=this.getGMarker(),t=Q.createElement("div");t.className="maptimize_info_window";t.innerHTML='<span class="maptimize_load_message">please wait</span>';u.openInfoWindowHtml(t);this.requestContent({marker_id:s,callback:function(v){t.innerHTML=v.html}})}},{_t:function(s,t){var v=r(s.ll);if(s.n){var u=new Y(r(s.sw),r(s.ne));return new e(s.id,v,s.lbl,s.value_avg,s.value_sum,u,s.n)}else{return new d(s.id,v,s.lbl,s.value_avg,s.value_sum)}}});var d=G(V(f.prototype,{initialize:function(w,u,v,t,s){f.call(this,u,v,t,s);this._u=w},getId:function(){return this._u},getLabels:function(){return this._k},hasLabel:function(s){return this._k.indexOf(Number(s))>-1},setGMarker:function(s){this._v=s},getGMarker:function(){return this._v||(this._v=this._n._w.theme.createMarker(this))},requestContent:function(s){k.send(J+"content",{content_id:this._u},s.callback)},_r:function(){this._n._w.onMarkerClicked(this)}}));var e=G(V(f.prototype,{initialize:function(y,w,x,v,s,u,t){f.call(this,w,x,v,s);this._u=y;this._x=u;this._y=t},getPointsCountForLabel:function(s){return this._k[s-1]},getLabels:function(){var s=[];L(this._k,function(u,t){if(u>0){s.push(t+1)}});return s},getPointsCount:function(){return this._y},getGLatLngBounds:function(){return this._x},getGMarker:function(){return this._v||(this._v=this._n._w.theme.createCluster(this))},expandOnMap:function(){var s=this._n._p();s.setCenter(this.getGLatLng(),s.getBoundsZoomLevel(this.getGLatLngBounds()))},requestIds:function(s){k.send(J+"cluster_ids",{cluster_id:this._u},s)},canExpandOnMap:function(){return !(this._n.isMaxZoom()||this._z())},requestContent:function(s){var t=s.marker_id?{marker_id:s.marker_id}:{content_id:this._u,cluster:1};this._n._aa(t);k.send(J+"content",t,s.callback)},_r:function(){this._n._w.onClusterClicked(this)},_z:function(){var t=this.getGLatLngBounds(),u=t.getNorthEast(),s=t.getSouthWest();return(u.lat()-s.lat())<0.000001||(u.lat()-s.lat()<0.000001)}}));var Z={};Z.Default={markerOptions:{icon:new q({image:R("maps/cluster.png"),iconSize:new j(22,33),iconAnchor:new W(11,33),infoWindowAnchor:new W(11,2),infoShadowAnchor:new W(18,25)})},clusterOptions:[{icon:new q({image:R("maps/5.png"),iconSize:new j(50,50),iconAnchor:new W(25,25),infoWindowAnchor:new W(25,25),infoShadowAnchor:new W(25,25)}),labelClass:"maptimize_cluster_0",labelOffset:new j(-25,-25)},{icon:new q({image:R("maps/4.png"),iconSize:new j(55,55),iconAnchor:new W(28,28),infoWindowAnchor:new W(28,28),infoShadowAnchor:new W(28,28)}),labelClass:"maptimize_cluster_1",labelOffset:new j(-28,-28)},{icon:new q({image:R("maps/3.png"),iconSize:new j(62,62),iconAnchor:new W(31,31),infoWindowAnchor:new W(31,31),infoShadowAnchor:new W(31,31)}),labelClass:"maptimize_cluster_2",labelOffset:new j(-31,-31)},{icon:new q({image:R("maps/2.png"),iconSize:new j(71,71),iconAnchor:new W(35,35),infoWindowAnchor:new W(35,35),infoShadowAnchor:new W(35,35)}),labelClass:"maptimize_cluster_3",labelOffset:new j(-35,-35)},{icon:new q({image:R("maps/1.png"),iconSize:new j(85,85),iconAnchor:new W(42,42),infoWindowAnchor:new W(42,42),infoShadowAnchor:new W(42,42)}),labelClass:"maptimize_cluster_4",labelOffset:new j(-42,-42)}],createMarker:function(s){return new b(s.getGLatLng(),Z.Default.markerOptions)},createCluster:function(s){var v=s.getPointsCount(),u=parseInt(Math.log(v)/Math.log(10)),t=Z.Default.clusterOptions[u];t.labelText=v;return new i(s.getGLatLng(),t)}};var c=G({_ab:new h(0,0),_ac:new Y(new h(10,10),new h(10,10)),_ad:{theme:Z.Default,onMarkerReceived:F,onClusterReceived:F,onMarkersLoaded:F,onMarkerClicked:function(s){s.openPopup()},onClusterClicked:function(s){if(s.canExpandOnMap()){s.expandOnMap()}else{var t=s._n._w.onZoomMaxClusterClicked;if(t){s.requestIds(function(u){t(s,u)})}else{s.openPopup()}}},onZoomMaxClusterClicked:false},initialize:function(u,t){var s=this;C(s,{_ae:u,_af:[],_x:new Y(s._ab,s._ab),_ag:u.getZoom(),_w:V(s._ad,t)});s._k=s._w.labels;X.bind(u,"moveend",s,s._ah);s._ai()},filterAnyLabels:function(s){this._k=s;this._aj="any";this._ak()},filterAllLabels:function(s){this._k=s;this._aj="all";this._ak()},isMaxZoom:function(){return this._ae.getBoundsZoomLevel(this._ac)==this._ae.getZoom()},getMarkers:function(t){var s=[];t=t||this._ae.getBounds();L(this._af,function(u){if(t.contains(u.getGLatLng())){s.push(u)}});return s},requestVisibleMarkersPaginated:function(s,t){k.send(J+"markers_paginated",V(s,{sw:this._x.getSouthWest().toUrlValue(),ne:this._x.getNorthEast().toUrlValue()}),t)},getPointsCount:function(){var s=0;L(this.getMarkers(),function(t){s+=t instanceof e?t.getPointsCount():1});return s},requestMarkerForId:function(v,u){var t=this;var s=U(this._af,function(w){return w._u==v});if(s){u(s,s.getGLatLng());return }k.send(J+"marker_id",{legacy_id:v,zoom:t._ae.getZoom()},function(y){var x=null;if(y){var w=y.point;x=U(t._af,function(z){if(z instanceof e){return U(z._u.split("|"),function(AA){if(AA[0]==":"){if(AA.substr(1)==w.id){return true}}else{if(w.path==AA){return true}}})}else{return z._u==w.id}})}u(x,x._u,x?x.getGLatLng():new h(w.lat,w.lng))})},_ak:function(){this._x=this._ac;this._ah()},_ai:function(){var u=this._ae,w=u.getBounds(),v=u.getZoom(),t=new l(v+1),s=t.fromLatLngToPixel(w.getSouthWest(),v),x=t.fromLatLngToPixel(w.getNorthEast(),v);s=t.fromPixelToLatLng(new W(s.x-256,s.y+256),v,true);x=t.fromPixelToLatLng(new W(x.x+256,x.y-256),v,true);if((x.lng()>s.lng()&&w.getNorthEast().lng()<=w.getSouthWest().lng())){w=new Y(new h(-90,-180),new h(90,180))}else{w=new Y(s,x)}this._al(w)},_p:function(){return this._ae},_ah:function(){var s=this._ae,t=s.getZoom();if(this._ag!=t||!this._x.containsBounds(s.getBounds())){this._ai();this._ag=t}},_aa:function(t){var s=this;if(s._k){t.labels=s._k.join(",")}if(s._aj){t.filterType=s._aj}},_al:function(u){var s=this,t=s._ae,v={sw:u.getSouthWest().toUrlValue(),ne:u.getNorthEast().toUrlValue(),zoom:t.getZoom()};s._aa(v);k.send(J+"markers",v,function(w){s._am(w,u)})},_am:function(v,u){var s=this,t=s._w;s._x=u;s._an();L(v,function(w){w=f._t(w,t);if(w instanceof e){t.onClusterReceived(w)}else{t.onMarkerReceived(w)}w._o(s);s._af.push(w)});t.onMarkersLoaded()},_an:function(){L(this._af,function(s){s._s()});this._af.length=0},_ao:function(){return C(new g,{initialize:function(u){var t=Q.createElement("a"),s=t.style;s.width="115px";s.height="40px";s.background="url("+R("maptimize_sticker_on_map.png")+")";s.cursor="pointer";t.href="http://www.maptimize.com";t.target="_blank";u.getContainer().appendChild(t);return t},getDefaultPosition:function(){return new o(G_ANCHOR_BOTTOM_LEFT,new j(0,40))}})},_ap:function(){var s=this._ae,u=s.getSize(),t=Q.createElement("div"),x=t.style,w;x.position="absolute";x.width=u.width+"px";x.height=u.height+"px";x.background="url("+R("watermark.png")+")";s.getPane(m).appendChild(t);var v=t.parentNode.parentNode.style;X.bind(s,"moveend",this,function(){x.left=-parseInt(v.left)+"px";x.top=-parseInt(v.top)+"px"})}});c.prototype.isZoomMax=c.prototype.isMaxZoom;c.prototype.getMarkersCount=c.prototype.getPointsCount;e.prototype.getCount=e.prototype.getPointsCount;function r(s){var t=s.split(/\s*,\s*/);return new h(t[0],t[1])}if(typeof K.Maptimize=="undefined"){K.Maptimize={}}K.Maptimize=C(K.Maptimize,{Map:c,Marker:d,Cluster:e,LabeledMarker:i,_i:k._i});K.Mapeed=K.Maptimize;k._h="Maptimize._i"}).apply(null,I("Event Bounds LatLng Size Icon Point Marker LatLngBounds MercatorProjection Control ControlPosition MAP_MARKER_PANE MAP_MAP_PANE ANCHOR_TOP_RIGHT".split(" "),O))})(this);
