var menuON = '1';
var oldmenuON = '1';
var currentContent = '1';

var bannerScroll;


var sectionColor1 = '23436c';
var sectionColor2 = '1472ee';
var sectionColor3 = 'f7b518';
var sectionColor4 = '3d7834';
var sectionColor5 = 'b0b5d3';
var sectionColor6 = '821938';

var sectionInit1 = '7';
var sectionInit2 = '19';
var sectionInit3 = '3';
var sectionInit4 = '13';
var sectionInit5 = '26';
var sectionInit6 = '6';


var accordion = '';

var Site = {

	changeSection:	function(elementId) {
 
				oldmenuON = menuON;
				menuON = elementId;


				// carica stili
				if ($('style'+elementId)) $('style'+elementId).remove();
				new Asset.css('css/style'+elementId+'.css', {id: 'style'+elementId});

				// cambia logo in alto dx
				$('box2').setStyle('background','url(../gfx/sections/'+elementId+'/logo.gif) center left no-repeat');
						
			
				// vai al banner	
				bannerScroll.toElement('banner'+elementId);

				// resetta linguetta vecchia
				if (oldmenuON) {

					$('menu'+oldmenuON).setStyle('background','url(../gfx/lingua_no.gif) center left no-repeat');
					$(oldmenuON).setStyle('color','#4c4c4c');

				}

				// accende linguetta nuova					
				$('menu'+elementId).setStyle('background','url(../gfx/sections/'+elementId+'/lingua.gif) center left no-repeat');
				$(elementId).setStyle('color','#ffffff');
				
				Site.showSubMenu(elementId);						
				Site.showContent(eval('sectionInit'+elementId));						
				

	},

	changeLanguage:	function(languageId) {

		$Aj = new Ajax(docRoot+"variabili.php?l="+languageId, {

			method: 'get',
			onComplete: function(){

				 // show/hide - saatiprintitalia
                                var myEffects = $('menu6').effects({duration: 1000, transition: Fx.Transitions.Sine.easeInOut});
                                if ( languageId == '1' && $('menu6').getStyle('top') != '102' )

				//var myEffects = $('menu5').effects({duration: 1000, transition: Fx.Transitions.Sine.easeInOut});
				//if ( languageId == '1' && $('menu5').getStyle('top') != '102' )


				myEffects.start({'top': [121, 102]});
				else {
					myEffects.start({'top': [102, 121]});
					
					// se english e sezione corrente printitalia -> vai a 1
					if (menuON == '6')
					//if (menuON == '5')
					Site.changeSection('1');
				}
			
			
				 Site.showSubMenu(menuON);
				 Site.showContent(currentContent);

				 this.evalScripts();

			}
						
		}).request();
		
	},


	triggerMenu:	function() {

				var list = $$('a.menu');

				
				list.each(function(element) {
/* 
					element.addEvent('mouseenter', function(){

	
					});
*/					
					element.addEvent('click', function(){

						Site.changeSection(element.getProperty('id'));
						
					});

				});
	
	},


	triggerSubMenu:	function() {

				var list = $$('a.submenu');
				
				list.each(function(element) {
 				
					element.addEvent('click', function(){

						element.setStyle('color',$('sectionColor'+menuON));
						
						Site.showContent(element.getProperty('id'));						
						
					});

				});
	
	},


	triggerInternalLinks: function() {


				var number = "";
				var pos = "";

				var list = $$('#content a.linkInternal');
				list.each(function(element) {
						
					        number = element.getProperty('href');
						pos = number.lastIndexOf("/");
						if ( pos != -1 )
						number = number.slice(pos+1);

					     if( isFinite(number) )		
					     element.setProperty('href',"javascript:Site.showContent("+number+");");	           
			
				});
			
			},


	hideMenu:	function(submenu){

					var myFx2 = new Fx.Styles($(submenu), {duration: 500, wait:true});					
					myFx2.start({ 'left': [$(submenu).getCoordinates().left, -500]});

			},


	showContent:	function(paramContent){


					
					var contentLoading = $('content').setHTML('<table width=100% height=300 cellpadding=0 cellspacing=0 border=0><tr><td height=300 valign="top"></td></tr></table>').addClass('ajax-loading');
					currentContent = paramContent;

					$Aj = new Ajax(docRoot+"content.php?nav="+paramContent, {
						method: 'get',
						update: $('content'),
						onComplete: function(){

								 Site.showFooter($('content').getCoordinates().bottom); 
								 Site.triggerInternalLinks();
 								 this.evalScripts();
								 contentLoading.removeClass('ajax-loading');

						 }
						}).request();
			},

	showSubMenu:	function(paramContent){

					$Aj = new Ajax(docRoot+"submenu.php?nav="+paramContent, {
						method: 'get',
						update: $('submenu'),
						onComplete: function(){
 								 this.evalScripts();
								 Site.triggerSubMenu();
						 }
						}).request();
			},

	showFooter:	function(posContent){

				 $('footer').setStyles({'visibility': 'visible'}); 
				 
			},


	slideSplash: function(languageId) {

		$('language_box').setStyle('top', '0px');
		$('box1').setStyle('top', '38px');
		$('banner-wrapper').setStyle('top', '121px');
		$('trattini_top').setStyle('top', '241px');

		$('menu1').setStyle('top', '102px');
		$('menu2').setStyle('top', '102px');
		//$('menu3').setStyle('top', '102px');
		$('menu4').setStyle('top', '102px');
		$('menu5').setStyle('top', '102px');
		$('menu6').setStyle('top', '102px');



		Site.changeLanguage(languageId);	
		Site.changeSection('1');

		var myFx = new Fx.Styles('splash',  {duration: 500});
		myFx.start({ 'left': [0, -1000] });

	},


	start: function(){


		Site.triggerMenu();

		bannerScroll = new Fx.Scroll('banner-wrapper', {
			wait: false,
			duration: 1000,
			offset: {'x': 0, 'y': 0},
			transition: Fx.Transitions.Quad.easeInOut
		});


		}


	}


window.addEvent('load', Site.start);	
