/* Weather Box */

Sppc.Landing.GoogleMapBox$Class = {
	map : null,
		
	constructor: function(data) {
		Sppc.Core.extendSuper(this, Sppc.Landing.AbstractBox, Sppc.Landing.GoogleMapBox$Class, data);
	},
	
	_contentLoaded: function() {
		this.__super._contentLoaded();
		
		var lat = jQuery('#box_google_map_lat_'+this._id).val();
		var lng = jQuery('#box_google_map_lng_'+this._id).val();
		var zoom= jQuery('#box_google_map_zoom_'+this._id).val();
		var mType = jQuery('#box_google_map_mType_'+this._id).val();
		jQuery('#google_map_canvas_'+this._id).height(Math.floor(jQuery('#google_map_canvas_'+this._id).width()*2/3));
		 var latlng = new google.maps.LatLng(lat, lng);
		 var myOptions = {
			  'noClear': false,
		      'zoom': parseInt(zoom),
		      'center': latlng,
		      'mapTypeId': mType,
		      'scrollwheel': false,
		      'mapTypeControlOptions': {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
		      'navigationControl': true,
		      'navigationControlOptions': {style: google.maps.NavigationControlStyle.SMALL}
		 };
		 this.map = new google.maps.Map(document.getElementById("google_map_canvas_"+this._id), myOptions);
 		 
		 var thisObj=this;
		 google.maps.event.addListener(this.map, 'zoom_changed', function() {
			 thisObj._saveMapState(thisObj._id, thisObj.map);
		  });
		 google.maps.event.addListener(this.map, 'dragend', function() {
			 thisObj._saveMapState(thisObj._id, thisObj.map);
		 });
		 google.maps.event.addListener(this.map, 'maptypeid_changed', function() {
			 thisObj._saveMapState(thisObj._id, thisObj.map);
		 });

	},
	
	_afterMove: function() {
		jQuery('#google_map_canvas_'+this._id).height(Math.floor(jQuery('#google_map_canvas_'+this._id).width()*2/3));
		this._contentLoaded();
	},

	_saveMapState: function(idBox, map) {
		var center = map.getCenter();
	     jQuery.post(site_url+'box/google_map/state_changed/'+idBox,
	    		 {
	    	 		lat: center.lat(),
	    	 		lng: center.lng(),
	    	 		zoom: map.getZoom(),
	    	 		mType: map.getMapTypeId() 
	    		 },
	    		 function() {
	    		 }
		 );
	}
};
Sppc.Landing.GoogleMapBox = Sppc.Landing.GoogleMapBox$Class.constructor;