if(!Destinia.maps){Destinia.maps={}}if(!Destinia.maps.adapters){Destinia.maps.adapters={}}Destinia.maps.Map=function(a){Destinia.maps.Composite.apply(this,arguments);this.loaded=false;this.rendered=false;this.loadCallback=null;this.ssi=null;this.provider=null;this.version=null;this.language="en";this.selector="map";this.language=null;this.auto=false;this.zoom;this.type=null;this.center=null;this.disableControls=false;Destinia.extend(this,a);switch(this.provider){case"GM3":this.adapter=new Destinia.maps.adapters.GoogleMaps3();break;default:throw {msg:"Unknown provider"}}if(this.center){this.setCenter(this.center)}};Destinia.maps.Map.prototype=new Destinia.maps.Composite();Destinia.maps.Map.prototype.constructor=Destinia.maps.Map;Destinia.maps.Map.prototype.isLoaded=function(){return this.loaded};Destinia.maps.Map.prototype.setCenter=function(a){if(Destinia.maps.Coordinates.checkCoordinate(a.lng)&&Destinia.maps.Coordinates.checkCoordinate(a.lat)||"undefined"!==typeof a.address){if("undefined"!==typeof a.text||"undefined"!==typeof a.icon||"undefined"!==typeof a.shadow){this.center=new Destinia.maps.Marker(a)}else{this.center=new Destinia.maps.Coordinates(a)}this.center.setAdapter(this.adapter);this.addComponent(this.center)}else{this.center=null}return this};Destinia.maps.Map.prototype.panTo=function(a){this.setCenter(a);if(null!=this.center){this.adapter.panTo(this.center.getLat(),this.center.getLng())}return this};Destinia.maps.Map.prototype.resize=function(){this.adapter.resize();return this};Destinia.maps.Map.prototype.show=function(){var a=new Destinia.utils.Queue();if(this.center&&!this.auto){a.add({fun:this.center.geoCodeAddressQueue,scope:this.center,onException:function(b){if("NoCoordinatesOrAddress"!==b.type){throw b}this.auto=true;a.next()}})}this._assignPoints(a);a.add({fun:this.render,scope:this});a.onEnd={fun:function(){this.rendered=true;if("function"===typeof this.loadCallback){this.loadCallback()}},scope:this};a.start();return this};Destinia.maps.Map.prototype._assignPoints=function(a){this._setAllPointsCoords(a);a.add({fun:this._separatePoints,scope:this});return this};Destinia.maps.Map.prototype._setAllPointsCoords=function(a){var b=this.adapter;this.iterate(function(c){c.setAdapter(b);if(c instanceof Destinia.maps.Coordinates){a.add({fun:c.geoCodeAddressQueue,scope:c,onException:function(d){if("NoCoordinatesOrAddress"!==d.type){throw d}}})}});return this};Destinia.maps.Map.prototype._separatePoints=function(a){var d=0,e=[];this.iterate(function(f){if(f instanceof Destinia.maps.Coordinates){e.push(f)}});for(var c=0;c<e.length;c++){d=0;for(var b=0;b<e.length;b++){if(b>c){if(e[c].sameCoordinates(e[b])){d++;e[b].setLng(e[b].getLng()+(d*0.0002))}}}}a.next();return this};Destinia.maps.Map.prototype.render=function(){var a=this;this.adapter.createMap(this,function(){a.renderComponents()});return this};Destinia.maps.Map.prototype.load=function(a){if("function"===typeof a){this.loadCallback=a}this._loadApi(this.show);return this};Destinia.maps.Map.prototype._loadApi=function(a){if(!this.loaded){Destinia.net.ProxyLoader.set({load:{fun:function(){this.adapter.includeApi();this._updateStats().loaded=true},scope:this},run:{fun:a,scope:this}}).launch()}else{a.apply(this)}return this};Destinia.maps.Map.prototype._updateStats=function(){var a={url:window.location.href,goal:"maps_stats",ssi:this.ssi,provider:this.provider,version:this.version,language:this.language};$("body").append('<iframe src="http://destinia.com/www/ajax/index.php?'+Destinia.net.Ajax.encodeParams(a)+'" style="display: none"/>');return this};
