
Ext.onReady(function(){
                var TabPanelCentrale = new Ext.TabPanel({
                    region:'center',
                    deferredRender:false,
                    activeTab:0,
                    items:[{
                    	id:'center1Tab',
                        contentEl:'mappa',
                        title: titoloLang[0],
                        autoScroll:true
                    },{
                    	id:'center2Tab',
		                    autoLoad: 'territorio.php',
                        title: titoloLang[1],
                        autoScroll:true
                    },{
                    	id:'center3Tab',
		                    autoLoad: 'progetto.php',
                        title: titoloLang[12],
                        autoScroll:true
                    },{
                    	id:'center4Tab',
                        //contentEl:'center2',
		                    autoLoad: 'dovesiamo.php',
                        title: titoloLang[13],
                        autoScroll:true
                    },{
                    	id:'center5Tab',
		                    autoLoad: 'numeri.php',
                        title: titoloLang[2],
                        //closable:true,
                        autoScroll:true
                    }]
                });
				 
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
       var viewport = new Ext.Viewport({
            layout:'border',
            items:[
                new Ext.BoxComponent({ // raw
                    region:'north',
                    el: 'north',
                    height:48
                }),{
                    region:'south',
		                autoLoad: 'credits.php',
	                  hideBorders:true,
	                  layout:"fit",
                    split:true,
                    height: 150,
                    minSize: 100,
                    maxSize: 200,
                    collapsible: true,
                    collapsed: true,
                    title: titoloLang[3],
                    margins:'0 0 0 0'
                },{

                    region:'west',
                    id:'west-panel',
	                title:titoloLang[4],
	                width:220,
	                minWidth:220,
	                maxWidth:220,
	                split:true,
                    //collapsed: true,
	                collapsible:true,
	                hideBorders:true,
	                layout:"fit",
	                items:[{
		                layout:'accordion',
		                layoutConfig:{
		                    animate:true,
	                        autoWidth:true,
	                        titleCollapse:true
		                },
		                items: [{
		                    title:'<span id="sidebartitle2"><b>'+titoloLang[5]+'</b></span>',
		                    autoLoad: 'sidebar.php?id=2',
	                      autoScroll:true,
		                    border:false,
		                    iconCls:'nav'
		                },{
		                    title:'<span id="sidebartitle1"><b>'+titoloLang[6]+'</b></span>',
		                    autoLoad: 'sidebar.php?id=1',
	                      autoScroll:true,
		                    border:false,
		                    iconCls:'settings'
		                },{
		                    title:'<span id="sidebartitle3"><b>'+titoloLang[7]+'</b></span>',		                    
		                    autoLoad: 'percorsi.php',
		                    //contentEl: 'west1',
		                    //html:'<p>Percorso Uno</p><p>Percorso Due</p><p>Percorso Tre</p>',
	                      autoScroll:true,
		                    border:false,
		                    iconCls:'settings'
		                }]
	                }]
                }, TabPanelCentrale
             ]
        });
        var tt1 = new Ext.ToolTip({
            target: 'langIta',
            title: ToolTipLang[0]
        }); 
        var tt2 = new Ext.ToolTip({
            target: 'langEng',
            title: ToolTipLang[1]
        }); 
        var tt3 = new Ext.ToolTip({
            target: 'homelink',
            title: ToolTipLang[2]
        }); 
        var tt4 = new Ext.ToolTip({
            target: 'contattilink',
            title: ToolTipLang[3]
        });        
        //Ext.get("showhidesouth").on('click', function() {
        //   var s = Ext.getCmp('south');
        //   s.collapsed ? s.expand() : s.collapse(); 
        //}); 
    //openwindowacc();
    //openinfowin2(); 
    //ad ogni cambio tab centrale, diverso dal primo tab, chiudo la finestra, altrimenti la apro
	TabPanelCentrale.on('tabchange', function(tabPanel, tab) {
		var ActiveID = TabPanelCentrale.getActiveTab().getId();
		var west = Ext.getCmp('west-panel');
		//var w = Ext.getCmp('opzioniwin'); 
		//var w2 = Ext.get('infoBox'); 
		//if(w){
			//alert("Active ID is: "+ActiveID);
			if(ActiveID!='center1Tab'){
				//w.hide();
        west.collapse();				
			}else{
				//w.show();
        west.expand();
			}
		//}
		//if(w2){
		//	if(ActiveID!='ext-comp-1002'){
		//		w2.hide();			
		//	}else{
		//		w2.show();
		//	}
		//}
	});  	
  
	//caricamento mappa  
   	load();  	       
   	homelink(TabPanelCentrale);
   	//searchlink();
   	contattilink();
   	chlang();
   	Ext.get('loadingcont').fadeOut();
   	/*
    Ext.get("help").on('click', function() {
		var ActiveID = TabPanelCentrale.getActiveTab().getId();
		if(ActiveID!='center3Tab'){
			TabPanelCentrale.activate('center3Tab');
		}
    });
    */ 	
	//admessages(); 	
});   
function provaAjax(){
	Ext.Ajax.request({
		url : 'test.php' , 
		params : { action : 'getDate' },
		method: 'GET',
		success: function ( result, request ) { 
			Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText); 
		},
		failure: function ( result, request) { 
			Ext.MessageBox.alert('Failed', result.responseText); 
		} 
	});	
}

function homelink(TabPanelCentrale){
	Ext.get('homelink').on('click', function(){
	    //load();
		var ActiveID = TabPanelCentrale.getActiveTab().getId();
		if(ActiveID!='center1Tab'){
			TabPanelCentrale.activate('center1Tab');
			//TabPanelCentrale.setActiveTab('center1Tab');
		}		 
	    map.returnToSavedPosition();
	});
}
function chlang(){
	Ext.get('langIta').on('click', function(){	 
	    window.document.location.href = 'index.php?lang=ita';
	});
	Ext.get('langEng').on('click', function(){	 
	    window.document.location.href = 'index.php?lang=eng';
	});
}
function searchlink(){
	var el = Ext.get('searchlink');
	el.on('click', function(){
	    var form = new Ext.form.FormPanel({
	        baseCls: 'x-plain',
	        labelWidth: 55,
	        url:'save-form.php',
	        defaultType: 'textfield',
	
	        items: [{
	            fieldLabel: 'uno',
	            name: 'uno',
	            anchor:'100%'  // anchor width by percentage
	        },{
	            fieldLabel: 'due',
	            name: 'due',
	            anchor: '100%'  // anchor width by percentage
	        }, {
	            xtype: 'textarea',
	            hideLabel: true,
	            name: 'msg',
	            anchor: '100% -33'  // anchor width by percentage and height by raw adjustment
	        }]
	    });
	
	    var window = new Ext.Window({
	        title: titoloLang[8],
	        width: 500,
	        height:300,
	        minWidth: 300,
	        minHeight: 180,
	        layout: 'fit',
	        plain:true,
	        modal: true,
	        bodyStyle:'padding:5px;',
	        buttonAlign:'center',
	        items: form,
	
	        buttons: [{
	            text: cercawinLang[0]
	        },{
	            text: cercawinLang[1]
	        }]
	    });
	
	    window.show();
	});
}
function contattilink(){
	var el = Ext.get('contattilink');
	el.on('click', function(){
	    var formContatti = new Ext.FormPanel({
	        baseCls: 'x-plain',
	        labelWidth: 75,
	        defaultType: 'textfield',
	
	        items: [{
	            fieldLabel: contattiLang[0],
	            name: 'Nome',
              //allowBlank:false,
	            anchor:'100%'  // anchor width by percentage
	        },{
	            fieldLabel: contattiLang[1],
	            name: 'Cognome',
              //allowBlank:false,
	            anchor: '100%'  // anchor width by percentage
	        }, {
	            fieldLabel: contattiLang[2],
	            name: 'Email',
              //vtype: 'email',
	            anchor: '100%'  // anchor width by percentage
	        }, {
	            xtype: 'textarea',
	            //hideLabel: true,
	            fieldLabel: contattiLang[3],
              //allowBlank:false,
	            name: 'msg',
	            anchor: '100% -33'  // anchor width by percentage and height by raw adjustment
	        }]
	    });
    var submit = formContatti.addButton({
        text: contattiLang[4],
        //disabled:true,
        handler: function(){
            formContatti.form.submit({
	              url:'sendmail.php',
	              waitTitle : contattiLang[5],
                waitMsg: contattiLang[6],
                success: function (form, action) {
                    window.hide();
                    Ext.MessageBox.alert(contattiLang[7], contattiLang[8]);
                },
                failure:function(form, action) {
                    //Ext.MessageBox.alert('Messaggio', action.response.responseText);
                    if(action.response){
                      if(action.response.responseText=='{success: false, errors:{Email: "email non valida"} }'){
                          Ext.MessageBox.alert(contattiLang[7], contattiLang[9]);
                      }else{
                          Ext.MessageBox.alert(contattiLang[7], contattiLang[10]);
                      }
                    }else{
                      Ext.MessageBox.alert(contattiLang[7], contattiLang[11]);
                    }
                    
                }
            });
        }
    });

	    var window = new Ext.Window({
	        title: titoloLang[11],
	        width: 500,
	        height:400,
	        minWidth: 300,
	        minHeight: 180,
	        layout: 'fit',
	        plain:true,
	        modal: true,
	        bodyStyle:'padding:5px;',
	        buttonAlign:'center',
	        items: formContatti
	    });
	
	    window.show();
	});
}
function admessages(){
 // messages
 var msgs = [
 {text: 'Ext Enterprise Training Now Available &raquo;', url:'http://extjs.com/support/training/'},
 {text: 'Introducing Ext GWT 1.0 &raquo;', url:'http://extjs.com/products/gxt/'},
 {text: 'Ext 2.1 Release Now Available &raquo;', url:'http://extjs.com/products/extjs/download.php'}
 ];

 var msgIndex = 0;
 var msg = Ext.get('msg'),
 msgInner = Ext.get('msg-inner'),
 active = null;

 msgInner.addClassOnOver('msg-over');

 msg.on('click', function(){
 window.location = active.url;
 });

 function doUpdate(){
 msgInner.update(active.text);
 msg.slideIn('b');
 }

 function showMsg(index){
 if(!msgInner.hasClass('msg-over')) {
 active = msgs[index];
 if(msg.isVisible()){
 msg.slideOut('b', {callback: doUpdate});
 }else{
 doUpdate();
 }
 }
 }

 setInterval(function(){
 msgIndex = msgs[msgIndex+1] ? msgIndex+1 : 0;
 showMsg(msgIndex);
 }, 5000);

 showMsg(0);
}

