/*
 *  GMAP3 Plugin for JQuery 
 *  Version   : 3.4
 *  Date      : July 04, 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=0;g<f[h].length;g++){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,g=0;this.init(m);for(j=0;j<f[m].length;j++){if(!f[m][j]){continue}if(g==1){l.push(h)}l.push(f[m][j]);g++}if(g<2){l.push(h)}f[m]=l};this.get=function(h){var g;if(f[h]){for(g=0;g<f[h].length;g++){if(f[h][g]){return f[h][g]}}}return false};this.ack=function(h){var g;if(f[h]){for(g=0;g<f[h].length;g++){if(f[h][g]){delete f[h][g];break}}if(this.empty(h)){delete f[h]}}}}function b(){var j=[],g=[],h=[],f=[],i=false,l;this.events=function(){for(var m=0;m<arguments.length;m++){g.push(arguments[m])}};this.startRedraw=function(){if(!i){i=true;return true}return false};this.endRedraw=function(){i=false};this.redraw=function(){var n,m=[],o=this;for(n=0;n<arguments.length;n++){m.push(arguments[n])}if(this.startRedraw){l.apply(o,m);this.endRedraw()}else{setTimeout(function(){o.redraw.apply(o,m)},50)}};this.setRedraw=function(m){l=m};this.store=function(m,n){h.push({data:m,obj:n})};this.free=function(){for(var m=0;m<g.length;m++){google.maps.event.removeListener(g[m])}g=[];this.freeAll()};this.freeIndex=function(m){if(typeof(h[m].obj.setMap)==="function"){h[m].obj.setMap(null)}if(typeof(h[m].obj.remove)==="function"){h[m].obj.remove()}delete h[m].obj;delete h[m].data;delete h[m]};this.freeAll=function(){var m;for(m=0;m<h.length;m++){if(h[m]){this.freeIndex(m)}}h=[]};this.freeDiff=function(p){var o,n,q={},m=[];for(o=0;o<p.length;o++){m.push(p[o].idx.join("-"))}for(o=0;o<h.length;o++){if(!h[o]){continue}n=d.inArray(h[o].data.idx.join("-"),m);if(n>=0){q[n]=true}else{this.freeIndex(o)}}return q};this.add=function(n,m){j.push({latLng:n,marker:m})};this.get=function(m){return j[m]};this.clusters=function(N,o,n){var q=N.getProjection(),E=q.fromLatLngToPoint(new google.maps.LatLng(N.getBounds().getNorthEast().lat(),N.getBounds().getSouthWest().lng())),J,H,m,D,B,A,F,v,w=N.getZoom(),s={},M={},I={},u=[],K,L,r,O,C,G,t=N.getBounds();G=0;C={};for(J=0;J<j.length;J++){if(!t.contains(j[J].latLng)){continue}D=q.fromLatLngToPoint(j[J].latLng);s[J]=[Math.floor((D.x-E.x)*Math.pow(2,w)),Math.floor((D.y-E.y)*Math.pow(2,w))];C[J]=true;G++}if(!n){for(F=0;F<f.length;F++){if(F in C){G--}else{break}}if(!G){return false}}f=C;C=[];for(J in s){B=s[J][0];A=s[J][1];if(!(B in M)){M[B]={}}if(!(A in M[B])){M[B][A]=J;I[J]={};C.push(J)}I[M[B][A]][J]=true}o=Math.pow(o,2);delete (M);F=0;while(1){while((F<C.length)&&!(C[F] in I)){F++}if(F==C.length){break}J=C[F];r=s[J][0];O=s[J][1];M=null;do{K={lat:0,lng:0,idx:[]};for(v=F;v<C.length;v++){if(!(C[v] in I)){continue}H=C[v];if(Math.pow(r-s[H][0],2)+Math.pow(O-s[H][1],2)<=o){for(m in I[H]){K.lat+=j[m].latLng.lat();K.lng+=j[m].latLng.lng();K.idx.push(m)}}}K.lat/=K.idx.length;K.lng/=K.idx.length;if(!M){L=K.idx.length>1;M=K}else{L=K.idx.length>M.idx.length;if(L){M=K}}if(L){D=q.fromLatLngToPoint(new google.maps.LatLng(M.lat,M.lng));r=Math.floor((D.x-E.x)*Math.pow(2,w));O=Math.floor((D.y-E.y)*Math.pow(2,w))}}while(L);for(v=0;v<M.idx.length;v++){if(M.idx[v] in I){delete (I[M.idx[v]])}}u.push(M)}return u};this.getBounds=function(){var m,n=new google.maps.LatLngBounds();for(m=0;m<j.length;m++){n.extend(j[m].latLng)}return n}}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=0;f<g.length;f++){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({},g in this._default?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(o,h,m,g){if(!this._ids[o].stored[h]||!this._ids[o].stored[h].length){return null}var l=this._ids[o].stored[h],j,f=m?l.length:-1,n=m?-1:1;for(j=0;j<l.length;j++){f+=n;if(l[f]){if(g!==undefined){if((l[f].tag===undefined)||(d.inArray(l[f].tag,g)<0)){continue}}return l[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]=[]}this._ids[i].stored[g].push({obj:h,tag:this._ival(f,"tag")});return g+"-"+(this._ids[i].stored[g].length-1)},_unstore:function(l,i,g,h){var f,j=this._ids[l].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[l].stored[i]=this._rmFromArray(j,f)}else{if(h){j.pop()}else{j.shift()}}return true},_clear:function(o,j,h,l,f){var m,g;if(!j||!j.length){j=[];for(k in this._ids[o].stored){j.push(k)}}else{j=this._array(j)}for(g=0;g<j.length;g++){if(j[g]){m=j[g].toLowerCase();if(!this._ids[o].stored[m]){continue}if(h){this._unstore(o,m,f,true)}else{if(l){this._unstore(o,m,f,false)}else{while(this._unstore(o,m,f,false)){}}}}}},_autoInit:function(f){var g,h=["init","geolatlng","getlatlng","getroute","getelevation","addstyledmap","setdefault","destroy"];if(!f){return true}for(g=0;g<h.length;g++){if(h[g]===f){return false}}return true},_proceed:function(g,i){i=i||{};var j=this._ival(i,"action")||"init",h=j.toLowerCase(),o=true,m=this._ival(i,"target"),n=this._ival(i,"args"),f,l;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(!m&&!n&&(h in this)&&(typeof(this[h])==="function")){this[h](g,d.extend({},h in this._default?this._default[h]:{},i.args?i.args:i))}else{if(m&&(typeof(m)==="object")){if(typeof(m[j])==="function"){l=m[j].apply(m,i.args?i.args:[])}else{o=false}}else{f=this._getMap(g);if(typeof(f[j])==="function"){l=f[j].apply(f,i.args?i.args:[])}else{o=false}}if(!o&&this._default.verbose){alert("unknown action : "+j)}this._callback(g,l,i);this._end(g)}},_call:function(){if((arguments.length<2)||(!this._exist(arguments[0]))){return}var g,l=arguments[0],j=arguments[1],h=this._getMap(l),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=[];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(o,i,g,n,m,j){var l=this,h=this._jObject(o);google.maps.event["addListener"+(j?"Once":"")](i,g,function(f){n.apply(h,[i,f,m])})},_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,n){var o=this._ival(h,"address"),m,j,l=this,i;if(o){i=function(q,p){if(p==google.maps.GeocoderStatus.OK){l[f](g,h,n?q:q[0].geometry.location)}else{if(l._default.verbose){alert("Geocode error : "+p)}l[f](g,h,false)}};if(typeof(o)==="object"){j=o}else{j={address:o};m=this._ival(h,"region");if(m){j.region=m}}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(n,g){var m,j=this._jObject(n),i=this._latLng(g,false,true),h=this._ival(g,"address"),l=i?{latLng:i}:(h?(typeof(h)==="string"?{address:h}:h):null),f=this._ival(g,"callback");if(l&&f&&typeof(f)==="function"){m=function(q,o){var p=o==google.maps.GeocoderStatus.OK?q:false;f.apply(j,[p,o])};this._getGeocoder().geocode(l,m)}this._end(n)},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(n,l){var m=l==google.maps.DirectionsStatus.OK?n:false;f.apply(h,[m,l])};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(t,r){var s=r==google.maps.ElevationStatus.OK?t:false;i.apply(n,[s,r])};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,l,j,m){var r,q,p,i="marker",h="infowindow",g=this._object(i,l,["to"]);if(!m){if(!j){this._manageEnd(f,false,g);return}this._subcall(f,l,j)}else{if(!j){return}}if(g.to){p=this._getStoredId(f,g.to);r=p&&(typeof(p.add)==="function");if(r){p.add(j,l);if(typeof(p.redraw)==="function"){p.redraw()}}if(!m){this._manageEnd(f,r,g)}}else{g.options.position=j;g.options.map=this._getMap(f);r=new google.maps.Marker(g.options);if(l[h]){q=this._object(h,l[h],["open"]);if((q.open===undefined)||q.open){q.apply=this._array(q.apply);q.apply.unshift({action:"open",args:[this._getMap(f),r]})}q.action="add"+h;this._planNext(f,q)}if(!m){this._store(f,i,r,g);this._manageEnd(f,r,g)}}return r},addmarkers:function(g,f){if(this._ival(f,"clusters")){this._addclusteredmarkers(g,f)}else{this._addmarkers(g,f)}},_addmarkers:function(f,j){var t,g,l,i,q,s={},p,r,h="marker",m=this._ival(j,"markers");this._subcall(f,j);if(!m||(typeof(m)!=="object")){return this._end(f)}g=this._object(h,j,["to","markers"]);if(g.to){r=this._getStoredId(f,g.to);t=r&&(typeof(r.add)==="function");if(t){for(l in m){i=this._latLng(m[l]);if(!i){continue}r.add(i,m[l])}if(typeof(r.redraw)==="function"){r.redraw()}}this._manageEnd(f,t,g)}else{d.extend(true,s,g.options);s.map=this._getMap(f);t=[];for(l in m){i=this._latLng(m[l]);if(!i){continue}if(m[l].options){p={};d.extend(true,p,s,m[l].options);g.options=p}else{g.options=s}g.options.position=i;q=new google.maps.Marker(g.options);t.push(q);g.data=m[l].data;g.tag=m[l].tag;this._store(f,h,q,g);this._manageEnd(f,q,g,true)}g.options=s;this._callback(f,t,j);this._end(f)}},getscale:function(l,f,g){var i=this._getMap(l),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(l,scale,f);this._end(l)}return scale},_addclusteredmarkers:function(f,h){var m,l,g,p,n=this,o=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(o)==="number"){m=new b();for(l=0;l<j.length;l++){g=this._latLng(j[l]);m.add(g,j[l])}p=this._initClusters(f,h,m,o,q)}this._callback(f,p,h);this._end(f)},_initClusters:function(m,g,h,f,j){var i=this,l=this._getMap(m);h.setRedraw(function(o){var p,n=h.clusters(l,f,o);if(n){p=h.freeDiff(n);i._displayClusters(m,g,h,n,p,j)}});h.events(google.maps.event.addListener(l,"zoom_changed",function(){h.redraw(true)}),google.maps.event.addListener(l,"bounds_changed",function(){h.redraw()}));h.redraw();return this._store(m,"cluster",h,g)},_displayClusters:function(s,j,w,h,v,l){var u,x,o,t,q,p,y,f={},z,g,n=this._ival(j,"cluster")||{},r=this._ival(j,"marker")||j;for(x=0;x<h.length;x++){if(x in v){continue}y=h[x];q=false;if(y.idx.length>1){t=0;for(u in l){if((u>t)&&(u<=y.idx.length)){t=u}}if(l[t]){g={content:l[t].content.replace("CLUSTER_COUNT",y.idx.length),offset:{x:-this._ival(l[t],"width")/2,y:-this._ival(l[t],"height")/2}};p=this._addOverlay(s,g,this._latLng(y),true);n.data={latLng:this._latLng(y),markers:[]};for(o=0;o<y.idx.length;o++){n.data.markers.push(w.get(y.idx[o]).marker)}this._attachEvents(s,p,n);w.store(y,p);q=true}}if(!q){d.extend(true,f,r.options);for(o=0;o<y.idx.length;o++){t=w.get(y.idx[o]);r.latLng=t.latLng;r.data=t.marker.data;r.tag=t.marker.tag;if(t.marker.options){z={};d.extend(true,z,f,t.marker.options);r.options=z}else{r.options=f}p=this._addMarker(s,r,r.latLng,true);this._attachEvents(s,p,r);w.store(y,p)}r.options=f}}},addinfowindow:function(g,f){this._resolveLatLng(g,f,"_addInfoWindow")},_addInfoWindow:function(m,f,h){var j,i,g=[],l="infowindow";this._subcall(m,f,h);j=this._object(l,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(m));if(j.anchor){g.push(j.anchor)}j.apply.unshift({action:"open",args:g})}this._store(m,l,i,j);this._manageEnd(m,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,l,h,n=this._object(j.toLowerCase(),f,[m]);if(n[m]){n.options[m]=[];for(g=0;g<n[m].length;g++){h=this._latLng(n[m][g]);if(h){n.options[m].push(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(l,f,g){var j,i="circle",h=this._object(i,f);if(!g){g=this._latLng(h.options.center)}if(!g){return this._manageEnd(l,false,h)}this._subcall(l,f,g);h.options.center=g;h.options.map=this._getMap(l);j=new google.maps.Circle(h.options);this._store(l,i,j,h);this._manageEnd(l,j,h)},addrectangle:function(g,f){this._resolveLatLng(g,f,"_addRectangle")},_addRectangle:function(l,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(l,false,i)}this._subcall(l,f,i.options.bounds.getCenter());i.options.map=this._getMap(l);g=new google.maps.Rectangle(i.options);this._store(l,j,g,i);this._manageEnd(l,g,i)},addoverlay:function(g,f){this._resolveLatLng(g,f,"_addOverlay")},_addOverlay:function(i,n,l,p){var m,h,j=this._object("overlay",n),g=d.extend({pane:"floatPane",content:"",offset:{x:0,y:0}},j.options),s=d("<div></div>"),r=[];this._subcall(i,n,l);h=this._getMap(i);s.css("border","none").css("borderWidth","0px").css("position","absolute");s.append(d(g.content));function q(){google.maps.OverlayView.call(this);this.setMap(h)}q.prototype=new google.maps.OverlayView();q.prototype.onAdd=function(){var f=this.getPanes();if(g.pane in f){d(f[g.pane]).append(s)}};q.prototype.draw=function(){var f=this.getProjection(),t=f.fromLatLngToDivPixel(l),o=this;s.css("left",(t.x+g.offset.x)+"px").css("top",(t.y+g.offset.y)+"px");d.each(("dblclick click mouseover mousemove mouseout mouseup mousedown").split(" "),function(v,u){r.push(google.maps.event.addDomListener(s[0],u,function(w){google.maps.event.trigger(o,u)}))});r.push(google.maps.event.addDomListener(s[0],"contextmenu",function(u){google.maps.event.trigger(o,"rightclick")}))};q.prototype.onRemove=function(){for(var f=0;f<r.length;f++){google.maps.event.removeListener(r[f])}s.remove()};q.prototype.hide=function(){s.hide()};q.prototype.show=function(){s.show()};q.prototype.toggle=function(){if(s){if(s.is(":visible")){this.show()}else{this.hide()}}};q.prototype.toggleDOM=function(){if(this.getMap()){this.setMap(null)}else{this.setMap(h)}};q.prototype.getDOMElement=function(){return s[0]};m=new q();if(!p){this._store(i,"overlay",m,j);this._manageEnd(i,m,j)}return m},addfixpanel:function(p,g){var m="fixpanel",j=this._object(m,g),f=0,l=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(p).width()-i.width()-j.options.right}else{if(j.options.center){f=(this._jObject(p).width()-i.width())/2}}}if(j.options.top!==undefined){l=j.options.top}else{if(j.options.bottom!==undefined){l=this._jObject(p).height()-i.height()-j.options.bottom}else{if(j.options.middle){l=(this._jObject(p).height()-i.height())/2}}}h=d("<div></div>").css("position","absolute").css("top",l+"px").css("left",f+"px").css("z-index","1000").append(j.options.content);this._jObject(p).first().prepend(h);this._attachEvents(p,this._getMap(p),j);this._store(p,m,h,j);this._callback(p,h,j)}this._end(p)},adddirectionsrenderer:function(l,f,g){var j="directionrenderer",h,i=this._object(j,f,["panelId"]);this._clear(l,j);i.options.map=this._getMap(l);h=new google.maps.DirectionsRenderer(i.options);if(i.panelId){h.setPanel(document.getElementById(i.panelId))}this._store(l,j,h,i);this._manageEnd(l,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(j,g){var i="kmllayer",h=this._object(i,g,["url"]),f;h.options.map=this._getMap(j);f=new google.maps.KmlLayer(h.url,h.options);this._store(j,i,f,h);this._manageEnd(j,f,h)},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(l){var m=new google.maps.LatLng(l.coords.latitude,l.coords.longitude);f.apply(h,[m])},function(){var l=false;f.apply(h,[l])})}else{if(google.gears){browserSupportFlag=true;i=google.gears.factory.create("beta.geolocation");i.getCurrentPosition(function(l){var m=new google.maps.LatLng(l.latitude,l.longitude);f.apply(h,[m])},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(l,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(l,i,h,j,f);this._end(l)},get:function(h,j){var g=this._ival(j,"name")||"map",m=this._ival(j,"first"),n=this._ival(j,"all"),p=this._ival(j,"tag"),f,l,o;g=g.toLowerCase();if(p!==undefined){p=this._array(p)}if(g=="map"){return this._getMap(h)}if(m){return this._getStored(h,g,false,p)}else{if(n){f=new Array();o=this._ids[h].stored[g];if(o){for(l=0;l<o.length;l++){if(!o[l]){continue}if(p!==undefined){if((o[l].tag===undefined)||(d.inArray(o[l].tag,p)<0)){continue}}f.push(o[l].obj)}}return f}else{return this._getStored(h,g,true,p)}}},earthradius:function(f){f=f?f:this._default.unit;return(typeof(f)==="string"&&(f.toLowerCase()==="km"))?6371:3959},distance:function(i,j){var s=this._ival(j,"unit"),r=this._latLng(this._ival(j,"a")),q=this._latLng(this._ival(j,"b")),o,n,m,l,p;if(r&&q){o=(Math.PI*r.lat()/180);n=(Math.PI*r.lng()/180);m=(Math.PI*q.lat()/180);l=(Math.PI*q.lng()/180);p=this.earthradius(s)*Math.acos(Math.min(Math.cos(o)*Math.cos(m)*Math.cos(n)*Math.cos(l)+Math.cos(o)*Math.sin(n)*Math.cos(m)*Math.sin(l)+Math.sin(o)*Math.sin(m),1))}return p},getmaxzoom:function(g,f){this._resolveLatLng(g,f,"_getMaxZoom")},_getMaxZoom:function(l,g,h){var j,i=this._jObject(l),f=this._ival(g,"callback");if(f&&typeof(f)==="function"){j=function(m){var n=m.status==google.maps.MaxZoomStatus.OK?m.zoom:false;f.apply(i,[n,m.status])};this._getMaxZoomService().getMaxZoomAtLatLng(h,j)}this._end(l)},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,j,o){var h,m,q,l,p=true,f=new google.maps.LatLngBounds();if(g in this._ids){for(h in this._ids[g].stored){q=this._ids[g].stored[h];for(m=0;m<q.length;m++){l=q[m].obj;if(l.getPosition){f.extend(l.getPosition());p=false}else{if(l.getBounds){f.extend(l.getBounds().getNorthEast());f.extend(l.getBounds().getSouthWest());p=false}else{if(l.getPaths){l.getPaths().forEach(function(i){i.forEach(function(n){f.extend(n);p=false})})}else{if(l.getPath){l.getPath().forEach(function(i){f.extend(i);p=false})}else{if(l.getCenter){f.extend(l.getCenter());p=false}}}}}}}if(!p){this._getMap(g).fitBounds(f)}}if(!o){this._manageEnd(g,p?false:f,j,o)}}};var a=0;d.fn.gmap3=function(){var g,j,f=[],h=[],l=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=d(this),m=i.data("id");l=false;if(!m){m=++a;i.data("id",m)}if(f.length==1){if(e._isDirect(m,f[0])){h.push(e._direct(m,f[0]))}else{e._plan(i,m,f)}}else{e._plan(i,m,f)}});if(h.length){if(h.length===1){return h[0]}else{return h}}if(l&&(arguments.length==2)&&(typeof(arguments[0])==="string")&&(arguments[0].toLowerCase()==="setdefault")){e.setdefault(0,arguments[1],true)}return this}}(jQuery));
