
K024Map=Class.create(KXXXGeneric,{initialize:function($super,kidId,sConf,kLang){$super(kidId,sConf,kLang);this.preloadTime=0;this.pe=null;this.map=null;},startKidget:function(){this.bindKidget();this.loadDataFromServer();},loadDataFromServer:function(){this.kidget.getDataFromServer({onComplete:this.dataReceivedOnStartUp});},dataReceivedOnStartUp:function(request){this.setSpecificContent(request);this.displayKidget();this.displayContent();this.displayDefaultTab();this.pe=new PeriodicalExecuter(this.GLoad.bind(this),0.5);},setSpecificContent:function(request){objFromServer=request;this.skin_shown_id=objFromServer[0].skin_shown_id;this.pos_lat=objFromServer[0].pos_lat;this.pos_long=objFromServer[0].pos_long;this.zoom_level=objFromServer[0].zoom_level;this.map_type=objFromServer[0].map_type;this.tmpSkin=null;},bindKidget:function($super){$super();if(this.kidgetId==90){this.kidget.addBackTab("stile",$$('#'+this.kidget.id+' .kdflaps_idle .kdflap_1')[0],'author');this.kidget.addBackTab("notifica",$$('#'+this.kidget.id+' .kdflaps_idle .kdflap_2')[0]);this.kidget.addBackTab("importa",$$('#'+this.kidget.id+' .kdflaps_idle .kdflap_3')[0]);if($$('#'+this.kidget.id+' .kdflaps_top_idle .kdflap_top_1').length>0)
{this.kidget.addBackTab("lingua",$$('#'+this.kidget.id+' .kdflaps_top_idle .kdflap_top_1')[0]);}
this.kidget.setDefaultTab("stile");}else{this.kidget.addBackTab("notifica",$$('#'+this.kidget.id+' .kdflaps_idle .kdflap_1')[0]);this.kidget.addBackTab("importa",$$('#'+this.kidget.id+' .kdflaps_idle .kdflap_2')[0]);if($$('#'+this.kidget.id+' .kdflaps_top_idle .kdflap_top_1').length>0)
{this.kidget.addBackTab("lingua",$$('#'+this.kidget.id+' .kdflaps_top_idle .kdflap_top_1')[0]);}
this.kidget.setDefaultTab("notifica");}
cerca_rollover_on_specific_kidget(this.kidget.id);if(this.kidgetId==90){skinsA=$$('#'+this.kidget.id+" .stile_int a");for(i=0;i<2;i++){Event.observe(skinsA[i],'click',this.skinsAListener.bindAsEventListener(this));}}
this.kidget.addBeforeAction("before_tab_set_not_current",this.befTabSetNotCurrent.bindAsEventListener(this));},getConfiguration:function(){this.updateConfiguration();return{'tab_item_id':this.kidget.getTabItemId(),'skin_shown_id':this.skin_shown_id,'pos_lat':this.pos_lat,'pos_long':this.pos_long,'zoom_level':this.zoom_level,'map_type':this.map_type}},displayContent:function(){if(this.kidgetId==90){$$('#'+this.kidget.id+" .googlemap_sfondo")[0].style.backgroundImage="url(/images/kidgets/map/k024_map/skin"+this.skin_shown_id+".png)";}},displayDefaultTab:function(){this.kidget.displayDefaultTab();},displaySkins:function(){skins=$$('#'+this.kidget.id+" .stile_int");skins[0].childElements()[0].childElements()[0].src="/images/kidgets/map/k024_map/skin1_picc.png";skins[0].childElements()[0].removeClassName("preferred");skins[0].childElements()[1].childElements()[0].src="/images/kidgets/map/k024_map/skin2_picc.png";skins[0].childElements()[1].removeClassName("preferred");if(this.tmpSkin==null)
skins[0].childElements()[this.skin_shown_id-1].addClassName("preferred");else
skins[0].childElements()[this.tmpSkin-1].addClassName("preferred");},GLoad:function(){var mapdiv=$$('#'+this.kidget.id+' .googlemap')[0];var mustwait=(mapdiv.getHeight()=="0");if(mustwait)
return;else{this.pe.stop();this.pe=null;}
if(GBrowserIsCompatible()){this.map=new GMap2(mapdiv);switch(this.map_type){case 1:tmpMapType=G_NORMAL_MAP;break;case 2:tmpMapType=G_SATELLITE_MAP;break;case 3:tmpMapType=G_HYBRID_MAP;break;case 4:tmpMapType=G_PHYSICAL_MAP;break;case 5:tmpMapType=G_MOON_ELEVATION_MAP;break;case 6:tmpMapType=G_MOON_VISIBLE_MAP;break;case 7:tmpMapType=G_MARS_ELEVATION_MAP;break;case 8:tmpMapType=G_MARS_VISIBLE_MAP;break;case 9:default:tmpMapType=G_MARS_INFRARED_MAP;break;}
if(this.kidgetId==90){this.map.addMapType(G_PHYSICAL_MAP);}else if(this.kidgetId==114){this.map.addMapType(G_MOON_ELEVATION_MAP);this.map.addMapType(G_MOON_VISIBLE_MAP);this.map.removeMapType(G_NORMAL_MAP);this.map.removeMapType(G_SATELLITE_MAP);this.map.removeMapType(G_HYBRID_MAP);}else if(this.kidgetId==115){this.map.addMapType(G_MARS_ELEVATION_MAP);this.map.addMapType(G_MARS_VISIBLE_MAP);this.map.addMapType(G_MARS_INFRARED_MAP);this.map.removeMapType(G_NORMAL_MAP);this.map.removeMapType(G_SATELLITE_MAP);this.map.removeMapType(G_HYBRID_MAP);}
this.map.setMapType(tmpMapType);this.map.setCenter(new GLatLng(this.pos_lat,this.pos_long),this.zoom_level);if(this.kidgetId==90){this.map.addControl(new GMenuMapTypeControl());this.map.addControl(new GSmallMapControl());this.map.enableGoogleBar();}else if(this.kidgetId==114){this.map.addControl(new GMenuMapTypeControl(),new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(10,20)));this.map.addControl(new GSmallMapControl(),new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(5,20)));}else if(this.kidgetId==115){this.map.addControl(new GMenuMapTypeControl(),new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(10,20)));this.map.addControl(new GSmallMapControl(),new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(5,20)));}
this.map.enableContinuousZoom();this.map.enableDoubleClickZoom();}},updateConfiguration:function(){this.pos_lat=this.map.getCenter().lat();this.pos_long=this.map.getCenter().lng();this.zoom_level=this.map.getZoom();tmpMapType=this.map.getCurrentMapType();switch(tmpMapType){case G_NORMAL_MAP:this.map_type=1;break;case G_SATELLITE_MAP:this.map_type=2;break;case G_HYBRID_MAP:this.map_type=3;break;case G_PHYSICAL_MAP:this.map_type=4;break;case G_MOON_ELEVATION_MAP:this.map_type=5;break;case G_MOON_VISIBLE_MAP:this.map_type=6;break;case G_MARS_ELEVATION_MAP:this.map_type=7;break;case G_MARS_VISIBLE_MAP:this.map_type=8;break;case G_MARS_INFRARED_MAP:default:this.map_type=9;break;}},writeToDB:function(){if(this.map){this.updateConfiguration();objectToPost={'tab_item_id':this.kidget.getTabItemId(),'skin_shown_id':this.skin_shown_id,'pos_lat':this.pos_lat,'pos_long':this.pos_long,'zoom_level':this.zoom_level,'map_type':this.map_type}
this.kidget.postDataToServer(objectToPost,{JSON:true});}},skinsAListener:function(event){skinsA=$$('#'+this.kidget.id+" .stile_int a");selectedA=Event.element(event);while(selectedA.tagName!='A'){selectedA=selectedA.up();}
for(var j=0;j<2;j++){if(selectedA==skinsA[j]){this.tmpSkin=j+1;}}
skinsA.each(function(a){a.removeClassName("preferred");})
selectedA.addClassName("preferred");},beforeTurnBack:function(){if(this.kidgetId==90){this.displaySkins();}},beforeDelete:function(){GUnload();},beforeBackOK:function(){if(this.kidget.userCanModifyKidget()){if(this.tmpSkin!=null)
this.skin_shown_id=this.tmpSkin;this.tmpSkin=null;this.writeToDB();}
this.displayContent();},beforeBackCancel:function(){this.tmpSkin=null;},afterTurnBack:function(){},afterRestore:function(){},befTabSetNotCurrent:function(){if(this.kidget.userCanModifyKidget()){this.writeToDB();}}})