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