// JavaScript Document

<!--
settings = {
	tl: { radius: 0 },
	tr: { radius: 0 },
	bl: { radius: 20 },
	br: { radius: 20 },
	antiAlias: true,
	autoPad: true,
	validTags: ["div"]
}

$(document).ready(function() {
						   
	// SUBMENU SELEZIONATO (VALORE CHE NON ESISTE)
	subMenuSel = 't';
	subMenuToToggleSel = 's';
	
	// IMMAGINE DI PARTENZA GALLERY
	img_count = 0;
	// INTERVALLI DI VISUALIZZAZIONE DELLE IMMAGINI E DELLE NEWS NELLE RISPETTIVE GALLERIE
	img_timeout = 4500;
	new_timeout = 6000;
	
	// FUNZIONE DI APERTURA E CHIUSURA SOTTOMENU (ROLLOVER/ROLLOUT)
    $(".btnMenu").hover(
		function () {
			if($('#'+subMenuSel).length>0){
				$('#'+subMenuSel).hide();
			}
			mainMenu = $(this).attr("id");
			mainMenuPos = $(this).offset();    
			mainMenuWidth = $(this).width(); 
			mainMenuHeight = $(this).height(); 
			
			mainMenuPosLeft = mainMenuPos.left-56;
			
			if(mainMenuPosLeft>496){
				mainMenuPosLeft=496;
			} 
			
			subMenuOver = $(this).attr("ermes");
			
			if($('#'+subMenuOver).length>0){
				if($("#layScreen").length>0){
					$("#layScreen").css({"zIndex": "50"});
					var zIndex = $("#layScreen").css("z-index");
					var queryString = location.search;
					if(queryString.indexOf('test')!=-1){
						//alert(zIndex);	
					}
				}
				subMenuSel = subMenuOver;
				subMenuWidth = $('#'+subMenuOver).width(); 
				$('#'+subMenuOver).css({"left":(mainMenuPosLeft)+"px", "top":(mainMenuPos.top)+"px", "backgroundPosition":(mainMenuWidth)+"px 0", "width":(subMenuWidth), "zIndex": "500000"});
				$('#'+subMenuOver).show();
				return false;
			} else {
				subMenuSel = 't';
			}
      	},
	  	function () {
			subMenuOut = subMenuOver;
			subMenuOver = null;
			if($('#'+subMenuOut).length<=0){
				//
			} else {
				setTimeout(function(){
					if(subMenuOver==null){
						$('#'+subMenuOut).hide();
					}
				}, 500);
			}
      	}
    );
	
	// FUNZIONE DI CHIUSURA SOTTOMENU (ROLLOUT SOTTOMENU)
	$(".cssMenuSub").hover(
		function () {
			subMenuOver = $(this).attr("id");
			$('#'+mainMenu).removeClass("cssMenu");
			$('#'+mainMenu).addClass("cssMenuHover");
		}, 
		function () {
			subMenuOut = subMenuOver;
			subMenuOver = null;
			$('#'+subMenuOut).hide();
			$('#'+mainMenu).removeClass("cssMenuHover");
			$('#'+mainMenu).addClass("cssMenu");
			if($('#layScreen').length>0){
				//$('#layScreen').show();
			}
		}
	);
	
	// APERTURA LINK QUANDO NON ESISTE IL SOTTOMEU
	$(".btnMenu").click(function(){
		if(subMenuOver.indexOf('.php')!=-1){
			location.href=subMenuOver;
		}						 
	});
	
	// LINK ALLA SCHEDA AGENDA DA HOMEPAGE
	$(".cssAgenda").click(function(){
		agendaLink = $(this).attr("ermes");
		if(agendaLink.indexOf('.php')!=-1){
			location.href=agendaLink;
		}						 
	});
	
	$(".cssAgendaLungo").click(function(){
		agendaLink = $(this).attr("ermes");
		if(agendaLink.indexOf('.php')!=-1){
			location.href=agendaLink;
		}						 
	});
	
	// LINK DI NAVIGAZIONE RECORDSET
	$(".cssNavBarAtt").click(function(){
		navLink = $(this).attr("ermes");
		if(navLink.indexOf('.php')!=-1){
			location.href=navLink;
		}						 
	});
	
	// APERTURA/CHIUSURA BOX STORIA
	$(".btnStoryTab").click(function(){
		if($('#layStoryTab').length>0){
			$('#layStoryTab').toggle();
			$('.btnStoryTab').toggle();
			fPosizionaFooter();
		}					 
	});
	
	// APERTURA/CHIUSURA BOX NEWS
	$(".btnTab").click(function(){
		newsLay = $(this).attr("ermes");
		if($('#layTab'+newsLay).length>0){
			$('#layTab'+newsLay).toggle();
			$('.cssNewsTab'+newsLay).toggle();
			fPosizionaFooter();
		}					 
	});
	
	// APERTURA/CHIUSURA BOXES AGENDA
	$(".btnAgenda").click(function(){
		if($('#layStoryTab').length>0){
			$('#layStoryTab').toggle();
			$('.btnStoryTab').toggle();
			fPosizionaFooter();
		}					 
	});
		
	// NAVIGAZIONE TAB RELATORI E SCHEDE
	var apiTab = $(".cssTabs").tabs(".cssSchede > div", { 
					/* tabs configuration goes here */      
					// first configuration property     
					current: 'cssCurrent',
					event: 'click',      
					// another property     
					effect: 'default',          
					// start from the beginning after the last tab        
					initialIndex: null,
					// ... the rest of the configuration properties 
					tabs: 'table',
					onClick: function(event, tabIndex) {
						//this.getCurrentTab().removeClass("cssRelatore"); 
						//this.getCurrentPane().addClass("cssCurrent");  
						window.location.hash = "#items";
						if($("#layFooter").length>0){
							$("#layFooter").hide();	
							$("#layFooter").css({"top":"0"});
							objPos = $(document).height();
							if($("#laySponsor").length>0){
								boxPos = $("#laySponsor").offset();   
								$("#layBoxSponsor").css({"top":(objPos-boxPos.top)*1+"px"});
							}
							objPos = $(document).height();
							$("#layFooter").css({"top":objPos+"px"});
							$("#layFooter").show();	
						}
				} 
	}); 
	
	// IMPOSTAZIONE GALLERIA FOTOGRAFICA PER HOMEPAGE
	if($(".cssGallery").length>0){
		var apiImg = $(".cssGallery").scrollable({
			api: true,
			easing: 'swing', 
			size: 1, 
			loop: true
		});
		
		//$(".cssGallery").scrollable().autoscroll({autoplay: true});
	
		setInterval(function(){
			apiImg.next();
		}, img_timeout);
	
	}
	
	// IMPOSTAZIONE GALLERIA FOTOGRAFICA
	if($("#layGallery").length>0){
		// SCORRIMENTO VERTICALE TRA GALLERIES
		var apiImg = $("#layGallery").scrollable({
		
			// basic settings
			vertical: true,
			size: 1,
			clickable: false,
			
			// up/down keys will always control this scrollable
			keyboard: 'static',
		
			// assign left/right keys to the actively viewed scrollable
			onSeek: function(event, i) {
				horizontal.scrollable(i).focus();
				//horizontal.eq(i).autoscroll({
				//	autoplay: true,
				//	interval: 2000,
				//});
			}
		
		// main navigator (thumbnail images)
		}).navigator(".cssNav");
		
		// horizontal scrollables. each one is circular and has its own navigator instance
		var horizontal = $(".cssScrollable").scrollable({size: 1}).circular().navigator(".cssGalleryNav");
		
		// when page loads setup keyboard focus on the first horzontal scrollable
		horizontal.eq(0).scrollable().focus();
		horizontal.eq(0).autoscroll({autoplay: true, interval: 2000});
		horizontal.eq(1).autoscroll({autoplay: true, interval: 2000});
		horizontal.eq(2).autoscroll({autoplay: true, interval: 2000});
		horizontal.eq(3).autoscroll({autoplay: true, interval: 2000});
	}
	
		
	
	// IMPOSTAZIONE GALLERIA SPONSOR
	if($("#laySponsor").length>0){
			// INIZIALIZZAZIONE FUNZIONALITÀ DI SCORRIMENTO E DI AUTOSCORRIMENTO
			window.apiScroller = $("#laySponsor").scrollable().circular().mousewheel().autoscroll({
				autoplay: false,
				items: "a",
				api: true,
				loop: true,
				speed: 250,
				interval: 1000,
				size:3
			});
			
			if($(".cssSponsorItems a").length>3){
				apiScroller.play();
			}

	}
	
	// IMPOSTAZIONE BOX NEWS
	if($("#layNews").length>0){
		
		if($(".cssNewsItems .cssNews").length>1){

			window.apiNews = $("#layNews").scrollable({
				api:true,
				vertical: true,
				size: 1,
				clickable: false,
				loop:true
			});
			
			$("#layNews").circular();
			
			$("#layNews").autoscroll({
				 interval: new_timeout 
			});

		}

	}
	if($("#layFooter").length>0){
		fPosizionaFooter();
	}
	
	function fPosizionaFooter(){
		$("#layFooter").hide();	
		$("#layFooter").css({"top":"0"});
		objPos = $(document).height();
		if($("#laySponsor").length>0){
			boxPos = $("#laySponsor").offset();   
			$("#layBoxSponsor").css({"top":(objPos-boxPos.top)*1+"px"});
		}
		objPos = $(document).height();
		$("#layFooter").css({"top":objPos+"px"});
		$("#layFooter").show();	
	}
	
	if($("#layCrediti").length>0){
		var apiOver = $("#layCrediti").overlay({
			oneInstance: false, 
			target:'#layCrediti',
			api: true, 
			effect:'default',
			left: 'center', 
			top: -150, 
			expose: { 
				color: '#FFF', 
				loadSpeed: 1500, 
				opacity: 1 
			}
			
		});
		
		
	}
	
	// APERTURA OVERLAY CREDITI
	$(".btnCrediti").click(function(){
		if($("#layCrediti").length>0){
			apiOver.load();
		}					 
	});


});


//-->