/*
 *  GMAP3 Plugin for JQuery 
 *  Version   : 3.3
 *  Date      : June 02, 2011
 *  Licence   : GPL v3 : http://www.gnu.org/licenses/gpl.html  
 *  Author    : DEMONTE Jean-Baptiste
 *  Contact   : jbdemonte@gmail.com
 *  Web site  : http://gmap3.net
 *   
 *  Copyright (c) 2010-2011 Jean-Baptiste DEMONTE
 *  All rights reserved.
 *   
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 * 
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   - Redistributions in binary form must reproduce the above 
 *     copyright notice, this list of conditions and the following 
 *     disclaimer in the documentation and/or other materials provided 
 *     with the distribution.
 *   - Neither the name of the author nor the names of its contributors 
 *     may be used to endorse or promote products derived from this 
 *     software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 */
(function(d){function c(){var f={};this.init=function(g){if(!f[g]){f[g]=[]}};this.empty=function(h){var g;if(!f[h]){return true}for(g in f[h]){if(f[h][g]){return false}}return true};this.add=function(h,g){this.init(h);f[h].push(g)};this.addNext=function(m,h){var l=[],j=0,g;this.init(m);for(g in f[m]){if(j==1){l.push(h)}l.push(f[m][g]);j++}if(j<2){l.push(h)}f[m]=l};this.get=function(h){var g;if(f[h]){for(g in f[h]){if(f[h][g]){return f[h][g]}}}return false};this.ack=function(h){var g;if(f[h]){for(g in f[h]){if(f[h][g]){delete f[h][g];break}}if(this.empty(h)){delete f[h]}}}}function b(){var j=[],g=[],i=[],f=[],h=false,k;this.events=function(){for(var l=0;l<arguments.length;l++){g.push(arguments[l])}};this.startRedraw=function(){if(!h){h=true;return true}return false};this.endRedraw=function(){h=false};this.redraw=function(){var m,l=[],n=this;for(m=0;m<arguments.length;m++){l.push(arguments[m])}if(this.startRedraw){k.apply(n,l);this.endRedraw()}else{setTimeout(function(){n.redraw.apply(n,l)},50)}};this.setRedraw=function(l){k=l};this.store=function(l){i.push(l)};this.free=function(){for(var l in g){google.maps.event.removeListener(g[l])}g=[];this.freeDom()};this.freeDom=function(){var m,l;for(m in i){if(typeof(i[m].setMap)==="function"){i[m].setMap(null)}if(typeof(i[m].remove)==="function"){i[m].remove()}delete i[m]}i=[]};this.add=function(m,l){j.push([m.lat(),m.lng(),l])};this.get=function(l){return j[l]};this.clusters=function(L,n,m){var o=L.getProjection(),D=o.fromLatLngToPoint(new google.maps.LatLng(L.getBounds().getNorthEast().lat(),L.getBounds().getSouthWest().lng())),H,F,l,C,A,w,E,u,v=L.getZoom(),r={},K={},G={},t=[],I,J,q,M,B,s=L.getBounds();B=[];for(H in j){if(!s.contains(new google.maps.LatLng(j[H][0],j[H][1]))){continue}C=o.fromLatLngToPoint(new google.maps.LatLng(j[H][0],j[H][1]));r[H]=[Math.floor((C.x-D.x)*Math.pow(2,v)),Math.floor((C.y-D.y)*Math.pow(2,v))];B.push(H)}if(!m){if(f.length==B.length){J=false;for(E in f){J=true;for(u in B){if(f[E]==B[u]){J=false;break}}if(J){break}}if(!J){return false}}}f=B;B=[];for(H in r){A=r[H][0];w=r[H][1];if(!(A in K)){K[A]={}}if(!(w in K[A])){K[A][w]=H;G[H]={};B.push(H)}G[K[A][w]][H]=true}n=Math.pow(n,2);delete (K);E=0;while(1){while((E<B.length)&&!(B[E] in G)){E++}if(E==B.length){break}H=B[E];q=r[H][0];M=r[H][1];K=null;do{I={lat:0,lng:0,idx:[]};for(u=E;u<B.length;u++){if(!(B[u] in G)){continue}F=B[u];if(Math.pow(q-r[F][0],2)+Math.pow(M-r[F][1],2)<=n){for(l in G[F]){I.lat+=j[l][0];I.lng+=j[l][1];I.idx.push(l)}}}I.lat/=I.idx.length;I.lng/=I.idx.length;if(!K){J=I.idx.length>1;K=I}else{J=I.idx.length>K.idx.length;if(J){K=I}}if(J){C=o.fromLatLngToPoint(new google.maps.LatLng(K.lat,K.lng));q=Math.floor((C.x-D.x)*Math.pow(2,v));M=Math.floor((C.y-D.y)*Math.pow(2,v))}}while(J);for(u in K.idx){if(K.idx[u] in G){delete (G[K.idx[u]])}}t.push(K)}return t};this.getBounds=function(){var l,m=new google.maps.LatLngBounds();for(l in j){m.extend(new google.maps.LatLng(j[l][0],j[l][1]))}return m}}var e={_ids:{},_properties:["events","onces","options","apply","callback","data","tag"],_default:{verbose:false,unit:"mi",init:{mapTypeId:google.maps.MapTypeId.ROADMAP,center:[46.578498,2.457275],zoom:2}},_running:{},_stack:new c(),_init:function(f,g){if(!this._ids[g]){this._ids[g]={$this:f,styles:{},stored:{},map:null}}},_plan:function(h,i,g){var f;this._init(h,i);for(f in g){this._stack.add(i,g[f])}this._run(i)},_isDirect:function(i,f){var h=this._ival(f,"action"),g={distance:true,earthradius:true,get:true};return h in g},_direct:function(h,f){var g=this._ival(f,"action");if(g.substr(0,1)==":"){g=g.substr(1)}return this[g](h,d.extend({},this._default[g],f.args?f.args:f))},_planNext:function(h,f){var g=this._jObject(h);this._init(g,h);this._stack.addNext(h,f)},_end:function(f){delete this._running[f];this._stack.ack(f);this._run(f)},_run:function(g){if(this._running[g]){return}var f=this._stack.get(g);if(!f){return}this._running[g]=true;this._proceed(g,f)},_geocoder:null,_getGeocoder:function(){if(!this._geocoder){this._geocoder=new google.maps.Geocoder()}return this._geocoder},_directionsService:null,_getDirectionsService:function(){if(!this._directionsService){this._directionsService=new google.maps.DirectionsService()}return this._directionsService},_elevationService:null,_getElevationService:function(){if(!this._elevationService){this._elevationService=new google.maps.ElevationService()}return this._elevationService},_maxZoomService:null,_getMaxZoomService:function(){if(!this._maxZoomService){this._maxZoomService=new google.maps.MaxZoomService()}return this._maxZoomService},_getMap:function(f){return this._ids[f].map},_setMap:function(g,f){this._ids[g].map=f},_jObject:function(f){return this._ids[f].$this},_addStyle:function(h,f,g){this._ids[h].styles[f]=g},_getStyles:function(f){return this._ids[f].styles},_getStyle:function(g,f){return this._ids[g].styles[f]},_styleExist:function(g,f){return this._ids[g]&&this._ids[g].styles[f]},_getDirectionRenderer:function(f){return this._getStored(f,"directionrenderer")},_exist:function(f){return this._ids[f].map?true:false},_getStored:function(n,h,l,g){if(!this._ids[n].stored[h]||!this._ids[n].stored[h].length){return null}var k=this._ids[n].stored[h],j,f=l?k.length:-1,m=l?-1:1;for(j=0;j<k.length;j++){f+=m;if(k[f]){if(g!==undefined){if((k[f].tag===undefined)||(d.inArray(k[f].tag,g)<0)){continue}}return k[f].obj}}return null},_getStoredId:function(g,f){f=f.split("-");if((f.length==2)&&this._ids[g].stored[f[0]]&&this._ids[g].stored[f[0]][f[1]]){return this._ids[g].stored[f[0]][f[1]].obj}return null},_store:function(i,g,h,f){g=g.toLowerCase();if(!this._ids[i].stored[g]){this._ids[i].stored[g]=new Array()}this._ids[i].stored[g].push({obj:h,tag:this._ival(f,"tag")});return g+"-"+(this._ids[i].stored[g].length-1)},_unstore:function(k,i,g,h){var f,j=this._ids[k].stored[i];if(!j){return false}if(g!==undefined){if(h){for(f=j.length-1;f>=0;f--){if((j[f]!==undefined)&&(j[f].tag!==undefined)&&(d.inArray(j[f].tag,g)>=0)){break}}}else{for(f=0;f<j.length;f++){if((j[f]!==undefined)&&(j[f].tag!==undefined)&&(d.inArray(j[f].tag,g)>=0)){break}}}}else{f=h?j.length-1:0}if(!(f in j)){return false}if(typeof(j[f].obj.setMap)==="function"){j[f].obj.setMap(null)}if(typeof(j[f].obj.remove)==="function"){j[f].obj.remove()}if(typeof(j[f].obj.free)==="function"){j[f].obj.free()}delete j[f].obj;if(g!==undefined){this._ids[k].stored[i]=this._rmFromArray(j,f)}else{if(h){j.pop()}else{j.shift()}}return true},_clear:function(p,l,j,m,f){var g,o,h;if(!l||!l.length){l=[];for(g in this._ids[p].stored){l.push(g)}}else{l=this._array(l)}for(g in l){if(l[g].toLowerCase){o=l[g].toLowerCase();if(!this._ids[p].stored[o]){continue}if(j){this._unstore(p,o,f,true)}else{if(m){this._unstore(p,o,f,false)}else{while(this._unstore(p,o,f,false)){}}}}}},_autoInit:function(g){var f,h=g.substr(0,1),i=["init","geolatlng","getlatlng","getroute","getelevation","addstyledmap","setdefault","destroy"];if(!g){return true}for(f in i){if(i[f]==g){return false}}return true},_proceed:function(g,i){i=i||{};var j=this._ival(i,"action")||"init",h=j.toLowerCase(),n=true,l=this._ival(i,"target"),m=this._ival(i,"args"),f,k;if(!this._exist(g)&&this._autoInit(h)){this.init(g,d.extend({},this._default.init,i.args&&i.args.map?i.args.map:i.map?i.map:{}),true)}if(!l&&!m&&(typeof(this[h])==="function")){this[h](g,d.extend({},this._default[h],i.args?i.args:i))}else{if(l&&(typeof(l)==="object")){if(typeof(l[j])==="function"){k=l[j].apply(l,i.args?i.args:[])}else{n=false}}else{f=this._getMap(g);if(typeof(f[j])==="function"){k=f[j].apply(f,i.args?i.args:[])}else{n=false}}if(!n&&this._default.verbose){alert("unknown action : "+j)}this._callback(g,k,i);this._end(g)}},_call:function(){if(arguments.length<2){return}if(!this._exist(arguments[0])){return}var g,k=arguments[0],j=arguments[1],h=this._getMap(k),f=[];if(typeof(h[j])!=="function"){return}for(g=2;g<arguments.length;g++){f.push(arguments[g])}return h[j].apply(h,f)},_array:function(h){var g,f=[];if(h!==undefined){if(typeof(h)==="object"){for(g in h){f.push(h[g])}}else{f.push(h)}}return f},_rmFromArray:function(f,h){var g,i=new Array();for(g in f){if(g!=h){i.push(f[g])}}return i},_subcall:function(i,f,h){var g={};if(!f.map){return}if(!h){h=this._ival(f.map,"latlng")}if(!this._exist(i)){if(h){g={center:h}}this.init(i,d.extend({},f.map,g),true)}else{if(f.map.center&&h){this._call(i,"setCenter",h)}if(f.map.zoom!==undefined){this._call(i,"setZoom",f.map.zoom)}if(f.map.mapTypeId!==undefined){this._call(i,"setMapTypeId",f.map.mapTypeId)}}},_attachEvent:function(n,i,g,m,l,j){var k=this,h=this._jObject(n);google.maps.event["addListener"+(j?"Once":"")](i,g,function(f){m.apply(h,[i,f,l])})},_attachEvents:function(i,h,f){var g;if(!f){return}if(f.events){for(g in f.events){if(typeof(f.events[g])==="function"){this._attachEvent(i,h,g,f.events[g],f.data,false)}}}if(f.onces){for(g in f.onces){if(typeof(f.onces[g])==="function"){this._attachEvent(i,h,g,f.onces[g],f.data,true)}}}},_callback:function(i,g,f){var h,j;if(typeof(f.callback)==="function"){j=typeof(i)==="number"?this._jObject(i):i;f.callback.apply(j,[g])}else{if(typeof(f.callback)==="object"){for(h in f.callback){if(!j){j=typeof(i)==="number"?this._jObject(i):i}if(typeof(f.callback[h])==="function"){f.callback[h].apply(j,[g])}}}}},_manageEnd:function(l,i,f,g){var h,j;if(i&&(typeof(i)==="object")){this._attachEvents(l,i,f);for(h in f.apply){j=f.apply[h];if(!j.action){continue}if(typeof(i[j.action])!=="function"){continue}if(j.args){i[j.action].apply(i,j.args)}else{i[j.action]()}}}if(!g){this._callback(l,i,f);this._end(l)}},_isNumeric:function(f){return(typeof(f)==="number"||typeof(f)==="string")&&f!==""&&!isNaN(f)},_latLng:function(j,n,h){var f,l={},g=0,m=n?j:null;if(!j||(typeof(j)==="string")){return m}if(j.latLng){return this._latLng(j.latLng)}if(typeof(j.lat)==="function"){return j}else{if(this._isNumeric(j.lat)){return new google.maps.LatLng(j.lat,j.lng)}else{if(!h){for(f in j){if(!this._isNumeric(j[f])){return m}l[g?"lng":"lat"]=j[f];if(g){break}g++}if(g){return new google.maps.LatLng(l.lat,l.lng)}}}}return m},_count:function(g){var f,h=0;for(f in g){h++}return h},_latLngBounds:function(q,g,j){var o,h,l,r,m,s,p,f,n;if(!q){return null}o=j?q:null;if(typeof(q.getCenter)==="function"){return q}h=this._count(q);if(h==2){if(q.ne&&q.sw){l=this._latLng(q.ne);r=this._latLng(q.sw)}else{for(m in q){if(!l){l=this._latLng(q[m])}else{r=this._latLng(q[m])}}}if(r&&l){return new google.maps.LatLngBounds(r,l)}return o}else{if(h==4){s=["n","e","s","w"];p=true;for(n in s){p&=this._isNumeric(q[s[n]])}if(p){return new google.maps.LatLngBounds(this._latLng([q.s,q.w]),this._latLng([q.n,q.e]))}if(g){n=0;f={};for(m in q){if(!this._isNumeric(q[m])){return o}f[s[n]]=q[m];n++}return new google.maps.LatLngBounds(this._latLng([f.s,f.w]),this._latLng([f.n,f.e]))}}}return o},_ikey:function(g,h){if(h.toLowerCase){h=h.toLowerCase();for(var f in g){if(f.toLowerCase&&(f.toLowerCase()==h)){return f}}}return false},_ival:function(g,h,i){var f=this._ikey(g,h);if(f){return g[f]}return i},_hasKey:function(g,h){var i,f;if(!g||!h){return false}for(i in g){if(i.toLowerCase){i=i.toLowerCase();for(f in h){if(i==h[f]){return true}}}}return false},_extractObject:function(g,f,i){if(this._hasKey(g,this._properties)||this._hasKey(g,f)){var h,j,l,i={};for(h in this._properties){j=this._properties[h];l=this._ikey(g,j);i[j]=l?g[l]:{}}for(h in f){j=f[h];l=this._ikey(g,j);if(l){i[j]=g[l]}}return i}else{i.options={};for(h in g){if(h=="action"){continue}i.options[h]=g[h]}return i}},_object:function(g,l,h,j){var n=this._ikey(l,g),i,f={},o=["map"],m="callback";f[m]=this._ival(l,m);if(n){return this._extractObject(l[n],h,f)}for(n in j){o.push(j[n])}if(!this._hasKey(l,o)){f=this._extractObject(l,h,f)}for(n in this._properties){i=this._properties[n];if(!f[i]){f[i]={}}}return f},_resolveLatLng:function(g,h,f,m){var n=this._ival(h,"address"),l,j,k=this,i;if(n){i=function(p,o){if(o==google.maps.GeocoderStatus.OK){k[f](g,h,m?p:p[0].geometry.location)}else{if(k._default.verbose){alert("Geocode error : "+o)}k[f](g,h,false)}};if(typeof(n)==="object"){j=n}else{j={address:n};l=this._ival(h,"region");if(l){j.region=l}}this._getGeocoder().geocode(j,i)}else{this[f](g,h,this._latLng(h,false,true))}},destroy:function(i,f){var g,h;if(this._ids[i]){this._clear(i);this._ids[i].$this.empty();if(this._ids[i].bl){delete this._ids[i].bl}for(g in this._ids[i].styles){delete this._ids[i].styles[g]}delete this._ids[i].map;h=this._jObject(i);delete this._ids[i];this._callback(h,null,f)}this._end(i)},init:function(h,j,m){var i,f,g,p,l,n;if((h=="")||(this._exist(h))){return this._end(h)}i=this._object("map",j);if((typeof(i.options.center)==="boolean")&&i.options.center){return false}f=d.extend({},this._default.init,i.options);if(!f.center){f.center=[this._default.init.center.lat,this._default.init.center.lng]}f.center=this._latLng(f.center);n=this._jObject(h);this._setMap(h,new google.maps.Map(n.get(0),f));g=this._getMap(h);p=this._getStyles(h);for(l in p){g.mapTypes.set(l,p[l])}this._manageEnd(h,g,i,m);return true},getlatlng:function(g,f){this._resolveLatLng(g,f,"_getLatLng",true)},_getLatLng:function(h,f,g){this._manageEnd(h,g,f)},getaddress:function(m,g){var l,j=this._jObject(m),i=this._latLng(g,false,true),h=this._ival(g,"address"),k=i?{latLng:i}:(h?(typeof(h)==="string"?{address:h}:h):null),f=this._ival(g,"callback");if(k&&f&&typeof(f)==="function"){l=function(p,n){var o=n==google.maps.GeocoderStatus.OK?p:false;f.apply(j,[o,n])};this._getGeocoder().geocode(k,l)}this._end(m)},getroute:function(j,g){var i,h=this._jObject(j),f=this._ival(g,"callback");if((typeof(f)==="function")&&g.options){g.options.origin=this._latLng(g.options.origin,true);g.options.destination=this._latLng(g.options.destination,true);i=function(m,k){var l=k==google.maps.DirectionsStatus.OK?m:false;f.apply(h,[l,k])};this._getDirectionsService().route(g.options,i)}this._end(j)},getelevation:function(f,h){var p,g,l,j,q,o,m=[],n=this._jObject(f),i=this._ival(h,"callback"),g=this._ival(h,"latlng");if(i&&typeof(i)==="function"){p=function(s,k){var r=k==google.maps.ElevationStatus.OK?s:false;i.apply(n,[r,k])};if(g){m.push(this._latLng(g))}else{l=this._ival(h,"locations");if(l){for(j in l){m.push(this._latLng(l[j]))}}}if(m.length){this._getElevationService().getElevationForLocations({locations:m},p)}else{q=this._ival(h,"path");o=this._ival(h,"samples");if(q&&o){for(j in q){m.push(this._latLng(q[j]))}if(m.length){this._getElevationService().getElevationAlongPath({path:m,samples:o},p)}}}}this._end(f)},addmarker:function(g,f){this._resolveLatLng(g,f,"_addMarker")},_addMarker:function(f,k,j,m){var l,q,p,i="marker",h="infowindow",g=this._object(i,k,["to"]);if(!m){if(!j){this._manageEnd(f,false,g);return}this._subcall(f,k,j)}else{if(!j){return}}if(g.to){p=this._getStoredId(f,g.to);l=p&&(typeof(p.add)==="function");if(l){p.add(j,k);if(typeof(p.redraw)==="function"){p.redraw()}}if(!m){this._manageEnd(f,l,g)}}else{g.options.position=j;g.options.map=this._getMap(f);l=new google.maps.Marker(g.options);if(k[h]){q=this._object(h,k[h],["open"]);if((q.open===undefined)||q.open){q.apply=this._array(q.apply);q.apply.unshift({action:"open",args:[this._getMap(f),l]})}q.action="add"+h;this._planNext(f,q)}if(!m){this._store(f,i,l,g);this._manageEnd(f,l,g)}}return l},addmarkers:function(g,f){if(this._ival(f,"clusters")){this._addclusteredmarkers(g,f)}else{this._addmarkers(g,f)}},_addmarkers:function(p,f){var l,h,i,g,j=[],m="marker",j=this._ival(f,"markers");this._subcall(p,f);if(!j||(typeof(j)!=="object")){return this._end(p)}l=this._object(m,f,["to"]);if(l.to){to=this._getStoredId(p,l.to);mk=to&&(typeof(to.add)==="function");if(mk){for(h in j){i=this._latLng(j[h]);if(!i){continue}to.add(i,j[h])}if(typeof(to.redraw)==="function"){to.redraw()}}this._manageEnd(p,mk,l)}else{l.options.map=this._getMap(p);for(h in j){i=this._latLng(j[h]);if(!i){continue}l.options.position=i;g=new google.maps.Marker(l.options);j.push(g);l.data=j[h].data;l.tag=j[h].tag;this._store(p,m,g,l);this._manageEnd(p,g,l,true)}this._callback(p,j,f);this._end(p)}},getscale:function(k,f,g){var i=this._getMap(k),h=i.getZoom(),j=[77.86446203412031,45.42785688110077,16.22073057585689,6.879509682822463,3.5034960477802986,1.8034610362879133,0.9127181102723314,0.4598746767146186,0.23053567913908649,0.11545247438886701,0.05775371939320953,0.02881647975962874,0.014414070716531696,0.007207618499622224,0.003603886381819732,0.0018015948787526636,0.0009008246767800296,0.0004504160086085826,0.00022520761796505933,0.00011260535432642144,0.00005630113180858676];scale=j[h];if(!g){this._callback(k,scale,f);this._end(k)}return scale},_addclusteredmarkers:function(f,h){var l,i,g,o,p,n=this,m=this._ival(h,"radius"),j=this._ival(h,"markers"),q=this._ival(h,"clusters");if(!this._getMap(f).getBounds()){google.maps.event.addListenerOnce(this._getMap(f),"bounds_changed",function(){n._addclusteredmarkers(f,h)});return}if(typeof(m)==="number"){l=new b();for(i in j){g=this._latLng(j[i]);l.add(g,j[i])}p=this._initClusters(f,h,l,m,q)}this._callback(f,p,h);this._end(f)},_initClusters:function(l,g,h,f,j){var i=this,k=this._getMap(l);h.setRedraw(function(n){var m=h.clusters(k,f,n);if(m){clusters=m;h.freeDom();i._displayClusters(l,g,h,clusters,j)}});h.events(google.maps.event.addListener(k,"zoom_changed",function(){h.redraw(true)}),google.maps.event.addListener(k,"bounds_changed",function(){h.redraw()}));h.redraw();return this._store(l,"cluster",h,g)},_displayClusters:function(f,h,p,s,v){var r,j,o,g,l,n,u,q=this._ival(h,"cluster")||{},t=this._ival(h,"marker")||h;for(r in s){u=s[r];l=false;if(u.idx.length>1){g=0;for(j in v){if((j>g)&&(j<=u.idx.length)){g=j}}if(v[g]){q={options:{content:v[g].content.replace("CLUSTER_COUNT",u.idx.length),offset:{x:-this._ival(v[g],"width")/2,y:-this._ival(v[g],"height")/2}},data:{latLng:this._latLng(u)}};n=this._addOverlay(f,q,this._latLng(u),true);this._attachEvents(f,n,q);p.store(n);l=true}}if(!l){u.dom=[];for(o in u.idx){g=p.get(u.idx[o]);t.latLng=this._latLng(g);t.data=g[2].data;if(t.latLng){n=this._addMarker(f,t,t.latLng,true);this._attachEvents(f,n,t);p.store(n)}}}}},addinfowindow:function(g,f){this._resolveLatLng(g,f,"_addInfoWindow")},_addInfoWindow:function(l,f,h){var j,i,g=[],k="infowindow";this._subcall(l,f,h);j=this._object(k,f,["open","anchor"]);if(h){j.options.position=h}i=new google.maps.InfoWindow(j.options);if((j.open===undefined)||j.open){j.apply=this._array(j.apply);g.push(this._getMap(l));if(j.anchor){g.push(j.anchor)}j.apply.unshift({action:"open",args:g})}this._store(l,k,i,j);this._manageEnd(l,i,j)},addpolyline:function(g,f){this._addPoly(g,f,"Polyline","path")},addpolygon:function(g,f){this._addPoly(g,f,"Polygon","paths")},_addPoly:function(p,f,j,m){var g,h,l,n=this._object(j.toLowerCase(),f,[m]);if(n[m]){n.options[m]=[];h=0;for(g in n[m]){n.options[m][h++]=this._latLng(n[m][g])}}l=new google.maps[j](n.options);l.setMap(this._getMap(p));this._store(p,j.toLowerCase(),l,n);this._manageEnd(p,l,n)},addcircle:function(g,f){this._resolveLatLng(g,f,"_addCircle")},_addCircle:function(k,f,g){var j,i="circle",h=this._object(i,f);if(!g){g=this._latLng(h.options.center)}if(!g){return this._manageEnd(k,false,h)}this._subcall(k,f,g);h.options.center=g;h.options.map=this._getMap(k);j=new google.maps.Circle(h.options);this._store(k,i,j,h);this._manageEnd(k,j,h)},addrectangle:function(g,f){this._resolveLatLng(g,f,"_addRectangle")},_addRectangle:function(k,f,h){var g,j="rectangle",i=this._object(j,f);i.options.bounds=this._latLngBounds(i.options.bounds,true);if(!i.options.bounds){return this._manageEnd(k,false,i)}this._subcall(k,f,i.options.bounds.getCenter());i.options.map=this._getMap(k);g=new google.maps.Rectangle(i.options);this._store(k,j,g,i);this._manageEnd(k,g,i)},addoverlay:function(g,f){this._resolveLatLng(g,f,"_addOverlay")},_addOverlay:function(n,g,k,h){var i,m=this._object("overlay",g),j=d.extend({pane:"floatPane",content:"",offset:{x:0,y:0}},m.options);l.prototype=new google.maps.OverlayView();function l(o,f,p){this.opts_=o;this.$div_=null;this.latLng_=f;this.map_=p;this.setMap(p)}l.prototype.onAdd=function(){var o,f=d("<div></div>");f.css("border","none").css("borderWidth","0px").css("position","absolute");f.append(d(this.opts_.content));this.$div_=f;o=this.getPanes();if(o[this.opts_.pane]){d(o[this.opts_.pane]).append(this.$div_)}};l.prototype.draw=function(){if(!this.$div_){return}var o,f=this.getProjection();o=f.fromLatLngToDivPixel(this.latLng_);this.$div_.css("left",(o.x+this.opts_.offset.x)+"px").css("top",(o.y+this.opts_.offset.y)+"px")};l.prototype.onRemove=function(){this.$div_.remove();this.$div_=null};l.prototype.hide=function(){if(this.$div_){this.$div_.hide()}};l.prototype.show=function(){if(this.$div_){this.$div_.show()}};l.prototype.toggle=function(){if(this.$div_){if(this.$div_.is(":visible")){this.show()}else{this.hide()}}};l.prototype.toggleDOM=function(){if(!this.$div_){return}if(this.getMap()){this.setMap(null)}else{this.setMap(this.map_)}};i=new l(j,k,this._getMap(n));if(!h){this._store(n,"overlay",i,m);this._manageEnd(n,i,m)}return i},addfixpanel:function(m,g){var l="fixpanel",j=this._object(l,g),f=0,k=0,i,h;if(j.options.content){i=d(j.options.content);if(j.options.left!==undefined){f=j.options.left}else{if(j.options.right!==undefined){f=this._jObject(m).width()-i.width()-j.options.right}else{if(j.options.center){f=(this._jObject(m).width()-i.width())/2}}}if(j.options.top!==undefined){k=j.options.top}else{if(j.options.bottom!==undefined){k=this._jObject(m).height()-i.height()-j.options.bottom}else{if(j.options.middle){k=(this._jObject(m).height()-i.height())/2}}}h=d("<div></div>").css("position","absolute").css("top",k+"px").css("left",f+"px").css("z-index","1000").append(j.options.content);this._jObject(m).first().prepend(h);this._attachEvents(m,this._getMap(m),j);this._store(m,l,h,j);this._callback(m,h,j)}this._end(m)},adddirectionsrenderer:function(k,f,g){var j="directionrenderer",h,i=this._object(j,f,["panelId"]);this._clear(k,j);i.options.map=this._getMap(k);h=new google.maps.DirectionsRenderer(i.options);if(i.panelId){h.setPanel(document.getElementById(i.panelId))}this._store(k,j,h,i);this._manageEnd(k,h,i,g)},setdirectionspanel:function(i,f){var g,h=this._object("directionpanel",f,["id"]);if(h.id){g=this._getDirectionRenderer(i);g.setPanel(document.getElementById(h.id))}this._manageEnd(i,g,h)},setdirections:function(i,f){var g,h=this._object("directions",f);if(f){h.options.directions=f.directions?f.directions:(f.options&&f.options.directions?f.options.directions:null)}if(h.options.directions){g=this._getDirectionRenderer(i);if(!g){this.adddirectionsrenderer(i,h,true);g=this._getDirectionRenderer(i)}else{g.setDirections(h.options.directions)}}this._manageEnd(i,g,h)},setstreetview:function(i,f){var h=this._object("streetview",f,["id"]),g;if(h.options.position){h.options.position=this._latLng(h.options.position)}g=new google.maps.StreetViewPanorama(document.getElementById(h.id),h.options);this._getMap(i).setStreetView(g);this._manageEnd(i,g,h)},addkmllayer:function(i,g){var f,h=this._object("kmllayer",g,["url"]);h.options.map=this._getMap(i);f=new google.maps.KmlLayer(h.url,h.options);this._manageEnd(i,f,g)},addtrafficlayer:function(j,f){var i="trafficlayer",h=this._object(i,f),g=this._getStored(j,i);if(!g){g=new google.maps.TrafficLayer();g.setMap(this._getMap(j));this._store(j,i,g,h)}this._manageEnd(j,g,h)},addbicyclinglayer:function(j,f){var i="bicyclinglayer",g=this._object(i,f),h=this._getStored(j,i);if(!h){h=new google.maps.BicyclingLayer();h.setMap(this._getMap(j));this._store(j,i,h,g)}this._manageEnd(j,h,g)},addgroundoverlay:function(j,f){var i="groundoverlay",h=this._object(i,f,["bounds","url"]),g;h.bounds=this._latLngBounds(h.bounds);if(h.bounds&&h.url){g=new google.maps.GroundOverlay(h.url,h.bounds);g.setMap(this._getMap(j));this._store(j,i,g,h)}this._manageEnd(j,g,h)},geolatlng:function(j,g){var i,f=this._ival(g,"callback"),h=this._jObject(j);if(typeof(f)==="function"){if(navigator.geolocation){browserSupportFlag=true;navigator.geolocation.getCurrentPosition(function(k){var l=new google.maps.LatLng(k.coords.latitude,k.coords.longitude);f.apply(h,[l])},function(){var k=false;f.apply(h,[k])})}else{if(google.gears){browserSupportFlag=true;i=google.gears.factory.create("beta.geolocation");i.getCurrentPosition(function(k){var l=new google.maps.LatLng(k.latitude,k.longitude);f.apply(h,[l])},function(){out=false;f.apply(h,[out])})}else{out=false;f.apply(h,[out])}}}this._end(j)},addstyledmap:function(j,f,g){var i=this._object("styledmap",f,["id","style"]),h;if(i.style&&i.id&&!this._styleExist(j,i.id)){h=new google.maps.StyledMapType(i.style,i.options);this._addStyle(j,i.id,h);if(this._getMap(j)){this._getMap(j).mapTypes.set(i.id,h)}}this._manageEnd(j,h,i,g)},setstyledmap:function(i,f){var h=this._object("styledmap",f,["id","style"]),g;if(h.id){this.addstyledmap(i,h,true);g=this._getStyle(i,h.id);if(g){this._getMap(i).setMapTypeId(h.id);this._callback(i,g,f)}}this._manageEnd(i,g,h)},clear:function(k,g){var i=this._array(this._ival(g,"list")||this._ival(g,"name")),h=this._ival(g,"last",false),j=this._ival(g,"first",false),f=this._ival(g,"tag");if(f!==undefined){f=this._array(f)}this._clear(k,i,h,j,f);this._end(k)},get:function(h,i){var g=this._ival(i,"name")||"map",j=this._ival(i,"first"),k=this._ival(i,"all"),n=this._ival(i,"tag"),f,l,m;g=g.toLowerCase();if(n!==undefined){n=this._array(n)}if(g=="map"){return this._getMap(h)}if(j){return this._getStored(h,g,false,n)}else{if(k){f=new Array();m=this._ids[h].stored[g];if(m){for(l in m){if(!m[l]){continue}if(n!==undefined){if((m[l].tag===undefined)||(d.inArray(m[l].tag,n)<0)){continue}}f.push(m[l].obj)}}return f}else{return this._getStored(h,g,true,n)}}},earthradius:function(f){f=f?f:this._default.unit;return(typeof(f)==="string"&&(f.toLowerCase()==="km"))?6371:3959},distance:function(i,j){var r=this._ival(j,"unit"),q=this._latLng(this._ival(j,"a")),p=this._latLng(this._ival(j,"b")),n,m,l,k,o;if(q&&p){n=(Math.PI*q.lat()/180);m=(Math.PI*q.lng()/180);l=(Math.PI*p.lat()/180);k=(Math.PI*p.lng()/180);o=this.earthradius(r)*Math.acos(Math.min(Math.cos(n)*Math.cos(l)*Math.cos(m)*Math.cos(k)+Math.cos(n)*Math.sin(m)*Math.cos(l)*Math.sin(k)+Math.sin(n)*Math.sin(l),1))}return o},getmaxzoom:function(g,f){this._resolveLatLng(g,f,"_getMaxZoom")},_getMaxZoom:function(k,g,h){var j,i=this._jObject(k),f=this._ival(g,"callback");if(f&&typeof(f)==="function"){j=function(l){var m=l.status==google.maps.MaxZoomStatus.OK?l.zoom:false;f.apply(i,[m,l.status])};this._getMaxZoomService().getMaxZoomAtLatLng(h,j)}this._end(k)},setdefault:function(i,f,g){for(var h in f){if(typeof(this._default[h])==="object"){this._default[h]=jQuery.extend({},this._default[h],f[h])}else{this._default[h]=f[h]}}if(!g){this._end(i)}},autofit:function(g,i,m){var h,j,p,l,o=true,f=new google.maps.LatLngBounds();if(g in this._ids){for(h in this._ids[g].stored){p=this._ids[g].stored[h];for(j in p){l=p[j].obj;if(l.getPosition){f.extend(l.getPosition());o=false}else{if(l.getBounds){f.extend(l.getBounds().getNorthEast());f.extend(l.getBounds().getSouthWest());o=false}else{if(l.getPaths){l.getPaths().forEach(function(k){k.forEach(function(n){f.extend(n);o=false})})}else{if(l.getPath){l.getPath().forEach(function(k){f.extend(k);o=false})}else{if(l.getCenter){f.extend(l.getCenter());o=false}}}}}}}if(!o){this._getMap(g).fitBounds(f)}}if(!m){this._manageEnd(g,o?false:f,i,m)}}};var a=0;d.fn.gmap3=function(){var g,j,f=[],h=[],k=true;for(j=0;j<arguments.length;j++){g=arguments[j]||{};if(typeof(g)==="string"){g={action:g}}if(g.action&&(g.action.substr(0,1)==":")){g.action=g.action.substr(1)}f.push(g)}if(!f.length){f.push({})}d.each(this,function(){var i;$this=d(this),i=$this.data("id");k=false;if(!i){i=++a;$this.data("id",i)}if(f.length==1){if(e._isDirect(i,f[0])){h.push(e._direct(i,f[0]))}else{res=e._plan($this,i,f);if(res){for(j in res){h.push(res[j])}}}}else{e._plan($this,i,f)}});if(h.length){if(h.length===1){return h[0]}else{return h}}if(k&&(arguments.length==2)&&(typeof(arguments[0])==="string")&&(arguments[0].toLowerCase()==="setdefault")){e.setdefault(0,arguments[1],true)}return this}}(jQuery));
