/*
 *  GMAP3 Plugin for JQuery 
 *  Version   : 3.1
 *  Date      : 2011-04-16
 *  Licence   : GPL v3 : http://www.gnu.org/licenses/gpl.html  
 *  Author    : DEMONTE Jean-Baptiste
 *  Contact   : jbdemonte@gmail.com
 *  Web site  : http://gmap3.net      
 */

(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(n,h){var m=[],j=0,g;this.init(n);for(g in f[n]){if(j==1){m.push(h)}m.push(f[n][g]);j++}if(j<2){m.push(h)}f[n]=m};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 h=[],f=[],g=[];this.events=function(){for(var j=0;j<arguments.length;j++){f.push(arguments[j])}};this.redraw=function(){};this.setRedraw=function(i){this.redraw=i};this.store=function(i){g.push(i)};this.free=function(){for(k in f){google.maps.event.removeListener(f[k])}f=[];this.freeDom()};this.freeDom=function(){var n,m;for(n in g){if(typeof(g[n].setMap)==="function"){g[n].setMap(null)}if(typeof(g[n].remove)==="function"){g[n].remove()}delete g[n]}g=[]};this.add=function(j,i){h.push([j.lat(),j.lng(),i])};this.get=function(j){return h[j]};this.clusters=function(p,u,o,v){var z,E,D,C,H,t=[],B,s,O,y={},r=[],n=[],m=[],L=p/3959,K,J,I,G,A=Math.PI/180,x,N,w,M,F=o===undefined;for(E in h){if(!u.contains(new google.maps.LatLng(h[E][0],h[E][1]))){continue}y[E]=true;if(!F&&!(E in o.keys)){F=true}n[E]=[Math.cos(A*h[E][0]),Math.cos(A*h[E][1])];m[E]=[Math.sin(A*h[E][0]),Math.sin(A*h[E][1])]}if(!F){for(E in o.keys){if(!(E in y)){F=true;break}}if(!F&&!v){o.updated=false;return o}}for(E in h){if(!y[E]){continue}r[E]=[];for(D=E;D<h.length;D++){if(y[D]&&(Math.acos(Math.min(n[E][0]*n[D][0]*n[E][1]*n[D][1]+n[E][0]*m[E][1]*n[D][0]*m[D][1]+m[E][0]*m[D][0],1))<=L)){r[E].push(D)}}}do{H=null;l=0;for(E=0;E<r.length;E++){if(r[E]&&(r[E].length>l)){l=r[E].length;H=r[E]}}if(H){do{s=O=0;len=H.length;for(C in H){E=H[C];s+=h[E][0];O+=h[E][1]}s=s/len;O=O/len;K=A*s;x=Math.cos(K);N=Math.sin(K);J=A*O;w=Math.cos(J);M=Math.sin(J);tmp=[];B={};for(E in H){for(D in h[H[E]]){if(!B[D]&&r[D]){B[D]=true;I=A*h[D][0];G=A*h[D][1];if(Math.acos(Math.min(x*n[D][0]*w*n[D][1]+x*M*n[D][0]*m[D][1]+N*m[D][0],1))<=L){tmp.push(D)}}}}if(tmp.length>H.length){H=tmp}}while(H.length>len);for(C in H){r[H[C]]=null}for(C in r){if(r[C]){tmp=[];for(E in r[C]){if(r[r[C][E]]){tmp.push(r[C][E])}}r[C]=tmp.length?tmp:null}}t.push({lat:s,lng:O,idx:H})}}while(H);if(!F&&v){F=o.clusters.length!==t.length}return{updated:F,keys:y,clusters:t}}}var e={_ids:{},_properties:["events","onces","options","apply","callback","data"],_default:{verbose:false,retro: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,h){var g=this._ival(h,"action"),f={distance:true,earthradius:true,get:true};return g in f},_direct:function(h,g){var f=this._ival(g,"action");if(f.substr(0,1)==":"){f=f.substr(1)}return this[f](h,d.extend({},this._default[f],g.args?g.args:g))},_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._getFirstStored(f,"directionrenderer")},_exist:function(f){return this._ids[f].map?true:false},_getFirstStored:function(h,g){var f=0;if(this._ids[h].stored[g]&&this._ids[h].stored[g].length){while(f<this._ids[h].stored[g].length){if(this._ids[h].stored[g][f]){return this._ids[h].stored[g][f]}f++}}return null},_getLastStored:function(h,g){var f;if(this._ids[h].stored[g]&&this._ids[h].stored[g].length){f=this._ids[h].stored[g].length-1;do{if(this._ids[h].stored[g][f]){return this._ids[h].stored[g][f]}f--}while(f>=0)}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]]}return null},_store:function(h,f,g){f=f.toLowerCase();if(!this._ids[h].stored[f]){this._ids[h].stored[f]=new Array()}this._ids[h].stored[f].push(g);return f+"-"+(this._ids[h].stored[f].length-1)},_unstore:function(j,h,g){var f,i=this._ids[j].stored[h];if(!i){return false}f=g?i.length-1:0;if(i[f]===undefined){return false}if(typeof(i[f].setMap)==="function"){i[f].setMap(null)}if(typeof(i[f].remove)==="function"){i[f].remove()}if(typeof(i[f].free)==="function"){i[f].free()}delete i[f];if(g){i.pop()}else{i.shift()}return true},_clear:function(p,j,h,m){var f,o,g;if(!j||!j.length){j=[];for(f in this._ids[p].stored){j.push(f)}}for(f in j){o=j[f].toLowerCase();if(!this._ids[p].stored[o]){continue}if(h){this._unstore(p,o,true)}else{if(m){this._unstore(p,o,false)}else{while(this._unstore(p,o,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,m){m=m||{};var i=this._ival(m,"action")||"init",h=i.toLowerCase(),p=true,n=this._ival(m,"target"),o=this._ival(m,"args"),f,j;if(!this._exist(g)&&this._autoInit(h)){this.init(g,d.extend({},this._default.init,m.args&&m.args.map?m.args.map:m.map?m.map:{}),true)}if(!n&&!o&&(typeof(this[h])==="function")){this[h](g,d.extend({},this._default[h],m.args?m.args:m))}else{if(n&&(typeof(n)==="object")){if(typeof(n[i])==="function"){j=n[i].apply(n,m.args?m.args:[])}else{p=false}}else{f=this._getMap(g);if(typeof(f[i])==="function"){j=f[i].apply(f,m.args?m.args:[])}else{p=false}}if(!p&&this._default.verbose){alert("unknown action : "+i)}this._callback(g,j,m);this._end(g)}},_call:function(){if(arguments.length<2){return}if(!this._exist(arguments[0])){return}var g,m=arguments[0],j=arguments[1],h=this._getMap(m),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},_subcall:function(i,h,g){var f={};if(!h.map){return}if(!g){g=this._ival(h.map,"latlng")}if(!this._exist(i)){if(g){f={center:g}}this.init(i,d.extend({},h.map,f),true)}else{if(h.map.center&&g){this._call(i,"setCenter",g)}if(h.map.zoom!==undefined){this._call(i,"setZoom",h.map.zoom)}if(h.map.mapTypeId!==undefined){this._call(i,"setMapTypeId",h.map.mapTypeId)}}},_attachEvent:function(p,i,g,o,n,j){var m=this,h=this._jObject(p);google.maps.event["addListener"+(j?"Once":"")](i,g,function(f){if(m._default.retro===2){o(h,i,f,n)}else{o.apply(h,[i,f,n])}})},_attachEvents:function(i,h,g){var f;if(!g){return}if(g.events){for(f in g.events){if(typeof(g.events[f])==="function"){this._attachEvent(i,h,f,g.events[f],g.data,false)}}}if(g.onces){for(f in g.onces){if(typeof(g.onces[f])==="function"){this._attachEvent(i,h,f,g.onces[f],g.data,true)}}}},_callback:function(i,f,h){var g,j;if(typeof(h.callback)==="function"){j=typeof(i)==="number"?this._jObject(i):i;h.callback.apply(j,[f])}else{if(typeof(h.callback)==="object"){for(g in h.callback){if(!j){j=typeof(i)==="number"?this._jObject(i):i}if(typeof(h.callback[g])==="function"){h.callback[g].apply(j,[f])}}}}},_manageEnd:function(m,h,i,f){var g,j;if(h&&(typeof(h)==="object")){this._attachEvents(m,h,i);for(g in i.apply){j=i.apply[g];if(!j.action){continue}if(typeof(h[j.action])!=="function"){continue}if(j.args){h[j.action].apply(h,j.args)}else{h[j.action]()}}}if(!f){this._callback(m,h,i);this._end(m)}},_isNumeric:function(f){return(typeof(f)==="number"||typeof(f)==="string")&&f!==""&&!isNaN(f)},_latLng:function(j,o,h){var f,m={},g=0,n=o?j:null;if(!j||(typeof(j)==="string")){return n}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 n}m[g?"lng":"lat"]=j[f];if(g){break}g++}if(g){return new google.maps.LatLng(m.lat,m.lng)}}}}return n},_count:function(g){var f,h=0;for(f in g){h++}return h},_latLngBounds:function(r,g,j){var p,h,m,s,n,u,q,f,o;if(!r){return null}p=j?r:null;if(typeof(r.getCenter)==="function"){return r}h=this._count(r);if(h==2){if(r.ne&&r.sw){m=this._latLng(r.ne);s=this._latLng(r.sw)}else{for(n in r){if(!m){m=this._latLng(r[n])}else{s=this._latLng(r[n])}}}if(s&&m){return new google.maps.LatLngBounds(s,m)}return p}else{if(h==4){u=["n","e","s","w"];q=true;for(o in u){q&=this._isNumeric(r[u[o]])}if(q){return new google.maps.LatLngBounds(this._latLng([r.s,r.w]),this._latLng([r.n,r.e]))}if(g){o=0;f={};for(n in r){if(!this._isNumeric(r[n])){return p}f[u[o]]=r[n];o++}return new google.maps.LatLngBounds(this._latLng([f.s,f.w]),this._latLng([f.n,f.e]))}}}return p},_ikey:function(g,h){h=h.toLowerCase();for(var f in g){if(f.toLowerCase()==h){return f}}return false},_ival:function(g,h){var f=this._ikey(g,h);if(f){return g[f]}return null},_hasKey:function(g,h){var i,f;if(!g||!h){return false}for(i in g){i=i.toLowerCase();for(f in h){if(i==h[f]){return true}}}return false},_extractObject:function(i,f){if(this._hasKey(i,this._properties)||this._hasKey(i,f)){var g,j,m,h={};for(g in this._properties){j=this._properties[g];m=this._ikey(i,j);h[j]=m?i[m]:{}}for(g in f){j=f[g];m=this._ikey(i,j);if(m){h[j]=i[m]}}return h}else{h={options:{}};for(g in i){if(g=="action"){continue}h.options[g]=i[g]}return h}},_object:function(i,n,f,h){var g=this._ikey(n,i),o,m={},j=["map"];if(g){return this._extractObject(n[g],f)}for(g in h){j.push(h[g])}if(!this._hasKey(n,j)){m=this._extractObject(n,f)}for(g in this._properties){o=this._properties[g];if(!m[o]){m[o]={}}}return m},_resolveLatLng:function(g,j,f,o){var p=this._ival(j,"address"),n,i,m=this,h;if(p){h=function(r,q){if(q==google.maps.GeocoderStatus.OK){m[f](g,j,o?r:r[0].geometry.location)}else{if(m._default.verbose){alert("Geocode error : "+q)}m[f](g,j,false)}};if(typeof(p)==="object"){i=p}else{i={address:p};n=this._ival(j,"region");if(n){i.region=n}}this._getGeocoder().geocode(i,h)}else{this[f](g,j,this._latLng(j,false,true))}},destroy:function(i,g){var f,h;if(this._ids[i]){this._clear(i);this._ids[i].$this.empty();if(this._ids[i].bl){delete this._ids[i].bl}for(f in this._ids[i].styles){delete this._ids[i].styles[f]}delete this._ids[i].map;h=this._jObject(i);delete this._ids[i];this._callback(h,null,g)}this._end(i)},init:function(h,m,n){var i,f,g,q,j,p;if((h=="")||(this._exist(h))){return this._end(h)}i=this._object("map",m);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);p=this._jObject(h);this._setMap(h,new google.maps.Map(p.get(0),f));g=this._getMap(h);q=this._getStyles(h);for(j in q){g.mapTypes.set(j,q[j])}this._manageEnd(h,g,i,n);return true},getlatlng:function(g,f){this._resolveLatLng(g,f,"_getLatLng",true)},_getLatLng:function(h,g,f){this._manageEnd(h,f,g)},getaddress:function(m,h){var j,i=this._jObject(m),g=this._latLng(h,false,true),f=this._ival(h,"callback");if(g&&f&&typeof(f)==="function"){j=function(p,n){var o=n==google.maps.GeocoderStatus.OK?p:false;f.apply(i,[o,n])};this._getGeocoder().geocode({latLng:g},j)}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(o,m){var n=m==google.maps.DirectionsStatus.OK?o:false;f.apply(h,[n,m])};this._getDirectionsService().route(g.options,i)}this._end(j)},getelevation:function(f,j){var q,g,m,i,r,p,n=[],o=this._jObject(f),h=this._ival(j,"callback"),g=this._ival(j,"latlng");if(h&&typeof(h)==="function"){q=function(u,s){var t=s==google.maps.ElevationStatus.OK?u:false;h.apply(o,[t,s])};if(g){n.push(this._latLng(g))}else{m=this._ival(j,"locations");if(m){for(i in m){n.push(this._latLng(m[i]))}}}if(n.length){this._getElevationService().getElevationForLocations({locations:n},q)}else{r=this._ival(j,"path");p=this._ival(j,"samples");if(r&&p){for(i in r){n.push(this._latLng(r[i]))}if(n.length){this._getElevationService().getElevationAlongPath({path:n,samples:p},q)}}}}this._end(f)},addmarker:function(g,f){this._resolveLatLng(g,f,"_addMarker")},_addMarker:function(f,m,j,p){var q,s,r,i="marker",h="infowindow",g=this._object(i,m,["to"]);if(!p){if(!j){this._manageEnd(f,false,g);return}this._subcall(f,m,j)}else{if(!j){return}}if(g.to){r=this._getStoredId(f,g.to);q=r&&(typeof(r.add)==="function");if(q){r.add(j,m);if(typeof(r.redraw)==="function"){r.redraw()}}if(!p){this._manageEnd(f,q,g)}}else{g.options.position=j;g.options.map=this._getMap(f);q=new google.maps.Marker(g.options);if(m[h]){s=this._object(h,m[h],["open"]);if((s.open===undefined)||s.open){s.apply=this._array(s.apply);s.apply.unshift({action:"open",args:[this._getMap(f),q]})}s.action="add"+h;this._planNext(f,s)}if(!p){this._store(f,i,q);this._manageEnd(f,q,g)}}return q},addmarkers:function(g,f){if(this._ival(f,"clusters")!==null){this._addclusteredmarkers(g,f)}else{this._addmarkers(g,f)}},_addmarkers:function(q,i){var m,g,h,f,j=[],p="marker",j=this._ival(i,"markers");this._subcall(q,i);if(!j&&(this._default.retro===2)){j=this._ival(i,"latlng")}if(!j||(typeof(j)!=="object")){return this._end(q)}m=this._object(p,i,["to"]);if(m.to){to=this._getStoredId(q,m.to);mk=to&&(typeof(to.add)==="function");if(mk){for(g in j){h=this._latLng(j[g]);if(!h){continue}to.add(h,j[g])}if(typeof(to.redraw)==="function"){to.redraw()}}this._manageEnd(q,mk,m)}else{m.options.map=this._getMap(q);for(g in j){h=this._latLng(j[g]);if(!h){continue}m.options.position=h;f=new google.maps.Marker(m.options);j.push(f);m.data=j[g].data;this._store(q,p,f);this._manageEnd(q,f,m,true)}this._callback(q,j,i);this._end(q)}},getscale:function(m,h,f){var i=this._getMap(m),g=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[g];if(!f){this._callback(m,scale,h);this._end(m)}return scale},_addclusteredmarkers:function(g,n){var o,j,h,r,s,q=this,p=this._ival(n,"radius"),m=this._ival(n,"markers"),t=this._ival(n,"clusters"),i=this.getscale(g,null,true),f=this._getMap(g).getBounds();if(!f){google.maps.event.addListenerOnce(this._getMap(g),"bounds_changed",function(){q._addclusteredmarkers(g,n)});return}if(typeof(p)==="number"){o=new b();for(j in m){h=this._latLng(m[j]);o.add(h,m[j])}s=this._initClusters(g,n,o,p,i,f,t)}this._callback(g,s,n);this._end(g)},_initClusters:function(i,m,n,p,j,g,q){var o=this,h=this._getMap(i),f=n.clusters(p*j,g);n.setRedraw(function(){var r;j=o.getscale(i,null,true);r=n.clusters(p*j,h.getBounds(),f,true);if(!r.updated){return}n.freeDom();f=r;o._displayClusters(i,m,n,f,q)});this._displayClusters(i,m,n,f,q);n.events(google.maps.event.addListener(h,"zoom_changed",function(){n.redraw()}),google.maps.event.addListener(h,"dragend",function(){j=o.getscale(i,null,true);f=n.clusters(p*j,h.getBounds(),f,false);n.freeDom();o._displayClusters(i,m,n,f,q)}));return this._store(i,"cluster",n)},_displayClusters:function(g,q,s,f,w){var t,n,r,j,o,u,p,h,v;for(t in f.clusters){v=f.clusters[t];o=false;if(v.idx.length>1){j=0;for(n in w){if((n>j)&&(n<=v.idx.length)){j=n}}if(w[j]){h={content:w[j].content.replace("CLUSTER_COUNT",v.idx.length),offset:{x:-this._ival(w[j],"width")/2,y:-this._ival(w[j],"height")/2}};s.store(this._addOverlay(g,h,this._latLng(v)));o=true}}if(!o){v.dom=[];for(r in v.idx){u=s.get(v.idx[r]);if(latLng=this._latLng(u)){p=this._addMarker(g,u,latLng,true);q.data=u[2].data;this._attachEvents(g,p,q);s.store(p)}}}}},addinfowindow:function(g,f){this._resolveLatLng(g,f,"_addInfoWindow")},_addInfoWindow:function(p,i,g){var j,h,f=[],m="infowindow";this._subcall(p,i,g);j=this._object(m,i,["open","anchor"]);if(g){j.options.position=g}h=new google.maps.InfoWindow(j.options);if((j.open===undefined)||j.open){j.apply=this._array(j.apply);f.push(this._getMap(p));if(j.anchor){f.push(j.anchor)}j.apply.unshift({action:"open",args:f})}this._store(p,m,h);this._manageEnd(p,h,j)},addpolyline:function(g,f){this._addPoly(g,f,"Polyline","path")},addpolygon:function(g,f){this._addPoly(g,f,"Polygon","paths")},_addPoly:function(q,j,h,n){var f,g,m,p=this._object(h.toLowerCase(),j,[n]);if(p[n]){p.options[n]=[];g=0;for(f in p[n]){p.options[n][g++]=this._latLng(p[n][f])}}m=new google.maps[h](p.options);m.setMap(this._getMap(q));this._store(q,h.toLowerCase(),m);this._manageEnd(q,m,p)},addcircle:function(g,f){this._resolveLatLng(g,f,"_addCircle")},_addCircle:function(m,g,f){var j,i="circle",h=this._object(i,g);if(!f){f=this._latLng(h.options.center)}if(!f){return this._manageEnd(m,false,h)}this._subcall(m,g,f);h.options.center=f;h.options.map=this._getMap(m);j=new google.maps.Circle(h.options);this._store(m,i,j);this._manageEnd(m,j,h)},addrectangle:function(g,f){this._resolveLatLng(g,f,"_addRectangle")},_addRectangle:function(m,h,g){var f,j="rectangle",i=this._object(j,h);i.options.bounds=this._latLngBounds(i.options.bounds,true);if(!i.options.bounds){return this._manageEnd(m,false,i)}this._subcall(m,h,i.options.bounds.getCenter());i.options.map=this._getMap(m);f=new google.maps.Rectangle(i.options);this._store(m,j,f);this._manageEnd(m,f,i)},addoverlay:function(g,f){this._resolveLatLng(g,f,"_addOverlay")},_addOverlay:function(q,n,j,g){var h,p=this._object("overlay",n),i=d.extend({pane:"floatPane",content:"",offset:{x:0,y:0}},p.options);m.prototype=new google.maps.OverlayView();function m(o,f,r){this.opts_=o;this.$div_=null;this.latLng_=f;this.map_=r;this.setMap(r)}m.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_)}};m.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")};m.prototype.onRemove=function(){this.$div_.remove();this.$div_=null};m.prototype.hide=function(){if(this.$div_){this.$div_.hide()}};m.prototype.show=function(){if(this.$div_){this.$div_.show()}};m.prototype.toggle=function(){if(this.$div_){if(this.$div_.is(":visible")){this.show()}else{this.hide()}}};m.prototype.toggleDOM=function(){if(!this.$div_){return}if(this.getMap()){this.setMap(null)}else{this.setMap(this.map_)}};h=new m(i,j,this._getMap(q));if(!g){this._store(q,"overlay",h);this._manageEnd(q,h,p)}return h},addfixpanel:function(q,i){var p="fixpanel",j=this._object(p,i),f=0,m=0,h,g;if(j.options.content){h=d(j.options.content);if(j.options.left!==undefined){f=j.options.left}else{if(j.options.right!==undefined){f=this._jObject(q).width()-h.width()-j.options.right}else{if(j.options.center){f=(this._jObject(q).width()-h.width())/2}}}if(j.options.top!==undefined){m=j.options.top}else{if(j.options.bottom!==undefined){m=this._jObject(q).height()-h.height()-j.options.bottom}else{if(j.options.middle){m=(this._jObject(q).height()-h.height())/2}}}g=d("<div></div>").css("position","absolute").css("top",m+"px").css("left",f+"px").css("z-index","1000").append(j.options.content);this._jObject(q).first().prepend(g);this._attachEvents(q,this._getMap(q),j);this._store(q,p,g);this._callback(q,g,j)}this._end(q)},removedirectionsrenderer:function(i,g,f){var h=this._object("directionrenderer",g);this._clear(i,"directionrenderer");this._manageEnd(i,true,h,f)},adddirectionsrenderer:function(m,g,f){var j="directionrenderer",h,i=this._object(j,g,["panelId"]);this._clear(m,j);i.options.map=this._getMap(m);h=new google.maps.DirectionsRenderer(i.options);if(i.panelId){h.setPanel(document.getElementById(i.panelId))}this._store(m,j,h);this._manageEnd(m,h,i,f)},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,g){var h=this._object("streetview",g,["id"]),f;if(h.options.position){h.options.position=this._latLng(h.options.position)}f=new google.maps.StreetViewPanorama(document.getElementById(h.id),h.options);this._getMap(i).setStreetView(f);this._manageEnd(i,f,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,g){var i="trafficlayer",h=this._object(i),f=this._getFirstStored(j,i);if(!f){f=new google.maps.TrafficLayer();f.setMap(this._getMap(j));this._store(j,i,f)}this._manageEnd(j,f,h)},removetrafficlayer:function(m,h){var j="trafficlayer",i=this._object(j),f=this._getFirstStored(m,j),g=f?true:false;if(f){this._clear(m,j)}this._manageEnd(m,g,i)},addbicyclinglayer:function(j,f){var i="bicyclinglayer",g=this._object(i),h=this._getFirstStored(j,i);if(!h){h=new google.maps.BicyclingLayer();h.setMap(this._getMap(j));this._store(j,i,h)}this._manageEnd(j,h,g)},removebicyclinglayer:function(m,g){var j="bicyclinglayer",h=this._object(j),i=this._getFirstStored(m,j),f=i?true:false;if(i){this._clear(m,j)}this._manageEnd(m,f,h)},addgroundoverlay:function(j,g){var i="groundoverlay",h=this._object(i,g,["bounds","url"]),f;h.bounds=this._latLngBounds(h.bounds);if(h.bounds&&h.url){f=new google.maps.GroundOverlay(h.url,h.bounds);f.setMap(this._getMap(j));this._store(j,i,f)}this._manageEnd(j,f,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(m){var n=new google.maps.LatLng(m.coords.latitude,m.coords.longitude);f.apply(h,[n])},function(){var m=false;f.apply(h,[m])})}else{if(google.gears){browserSupportFlag=true;i=google.gears.factory.create("beta.geolocation");i.getCurrentPosition(function(m){var n=new google.maps.LatLng(m.latitude,m.longitude);f.apply(h,[n])},function(){out=false;f.apply(h,[out])})}else{out=false;f.apply(h,[out])}}}this._end(j)},addstyledmap:function(j,h,f){var i=this._object("styledmap",h,["id","style"]),g;if(i.style&&i.id&&!this._styleExist(j,i.id)){g=new google.maps.StyledMapType(i.style,i.options);this._addStyle(j,i.id,g);if(this._getMap(j)){this._getMap(j).mapTypes.set(i.id,g)}}this._manageEnd(j,g,i,f)},setstyledmap:function(i,g){var h=this._object("styledmap",g,["id","style"]),f;if(h.id){this.addstyledmap(i,h,true);f=this._getStyle(i,h.id);if(f){this._getMap(i).setMapTypeId(h.id);this._callback(i,f,g)}}this._manageEnd(i,f,h)},clear:function(j,h){var g=this._array(h.list),f=h.last?true:false,i=h.first?true:false;this._clear(j,g,f,i);this._end(j)},get:function(n,j){var g=this._ival(j,"name")||"map",m=this._ival(j,"first"),h=this._ival(j,"all"),i,f;g=g.toLowerCase();if(g=="map"){return this._getMap(n)}if(m){return this._getFirstStored(n,g)}else{if(h){i=new Array();if(this._ids[n].stored[g]){for(f in this._ids[n].stored[g]){if(this._ids[n].stored[g][f]){i.push(this._ids[n].stored[g][f])}}}return i}else{return this._getLastStored(n,g)}}},earthradius:function(f){f=f?f:this._default.unit;return(typeof(f)==="string"&&(f.toLowerCase()==="km"))?6371:3959},distance:function(i,j){var t=this._ival(j,"unit"),s=this._latLng(this._ival(j,"a")),r=this._latLng(this._ival(j,"b")),p,o,n,m,q;if(s&&r){p=(Math.PI*s.lat()/180);o=(Math.PI*s.lng()/180);n=(Math.PI*r.lat()/180);m=(Math.PI*r.lng()/180);q=this.earthradius(t)*Math.acos(Math.min(Math.cos(p)*Math.cos(n)*Math.cos(o)*Math.cos(m)+Math.cos(p)*Math.sin(o)*Math.cos(n)*Math.sin(m)+Math.sin(p)*Math.sin(n),1))}return q},getmaxzoom:function(g,f){this._resolveLatLng(g,f,"_getMaxZoom")},_getMaxZoom:function(m,h,g){var j,i=this._jObject(m),f=this._ival(h,"callback");if(f&&typeof(f)==="function"){j=function(n){var o=n.status==google.maps.MaxZoomStatus.OK?n.zoom:false;f.apply(i,[o,n.status])};this._getMaxZoomService().getMaxZoomAtLatLng(g,j)}this._end(m)},setdefault:function(i,h,f){for(var g in h){if(typeof(this._default[g])==="object"){this._default[g]=jQuery.extend({},this._default[g],h[g])}else{this._default[g]=h[g]}}if(!f){this._end(i)}}};var a=0;d.fn.gmap3=function(){var g,j,f=[],h=[],m=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");m=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(m&&(arguments.length==2)&&(typeof(arguments[0])==="string")&&(arguments[0].toLowerCase()==="setdefault")){e.setdefault(0,arguments[1],true)}return this}}(jQuery));
