
	var volume = 0;
	var currStoria = 0;
	var aspect = 1280/333;
	var currentTicker = -1;
	var tickerAmount = 0;
	var slide = false;

	$(document).ready(function(){
	
		// SETUP TICKER
		
		tickerAmount = $('#ticker ul li').size()-1;
		$("#ticker ul li").css({left: $(window).width()+'px' });
		slideTicker(0);
	
		// MENU
	
			// FADE MENUS
	
		$(".navigazione").bind("mouseenter",function(event){
			$("ul", this).fadeIn();
		});
		
		$(".navigazione").bind("mouseleave",function(event){
			$("ul", this).fadeOut();
		});
		
			// ACTIVE MENUS
		
		$(".navigazione").bind("click",function(event){
			$("a").removeClass("active");
			$("a", this).toggleClass("active");
			clearAll();
			event.preventDefault();
		});
		
			// MAIN MENU EVENTS
		
		$("#benvenito").bind("click", function(event){
			if(!$(this).hasClass("active")){
				hideUpper();
				$("#text-benvenito").fadeIn();
				getFlashMovie("dalidia").changeVideo("video/intro.flv");
			}
		});
		
		$("#ristorante").bind("click", function(event){
			if(!$(this).hasClass("active")){
				hideUpper();
				getFlashMovie("dalidia").changeVideo("video/ristorante.flv");
			}
		});
		
		$("#grandcafe").bind("click", function(event){
			if(!$(this).hasClass("active")){
				hideUpper();
				getFlashMovie("dalidia").changeVideo("video/grand_cafe.flv");
			}
		});
		
		$("#cucina").bind("click", function(event){
			if(!$(this).hasClass("active")){
				hideUpper();
				getFlashMovie("dalidia").changeVideo("video/cucina.flv");
			}
		});
		
		$("#cantina").bind("click", function(event){
			if(!$(this).hasClass("active")){
				hideUpper();
				getFlashMovie("dalidia").changeVideo("video/vino.flv");
			}
		});
		
		$("#eventi").bind("click", function(event){
			if(!$(this).hasClass("active")){
				hideUpper();
				$("#text-eventi").fadeIn();
				getFlashMovie("dalidia").changeVideo("video/eventi.flv");
			}
		});
		
		$("#storia").bind("click", function(event){
			if(!$(this).hasClass("active")){
				hideUpper();
				$("#text-storia").fadeIn();
				getFlashMovie("dalidia").changeVideo("video/contactstoria.flv");
			}
		});
		
		$("#menu").bind("click", function(event){
			if(!$(this).hasClass("active")){
				hideUpper();
				$("#text-menu").fadeIn();
				getFlashMovie("dalidia").changeVideo("video/menu.flv");
				setTimeout("openMenu()",7000);
			}
		});
		
		$("#informazione").bind("click", function(event){
			if(!$(this).hasClass("active")){
				hideUpper();
				$("#text-informazione").fadeIn();
				getFlashMovie("dalidia").changeVideo("video/contactstoria.flv");
			}
		});
				
			// SUBMENU
				
		$("#submenu ul li").bind("click", function(){
			$("#submenu a").removeClass("active");
			$("a", this).toggleClass("active");
			$("#subsubmenu ul").css("bottom", 0);
			var index = $("#submenu ul li").index(this);
			var amount = $("#subsubmenu"+index+" li").size();
			
			$("#subsubmenu ul li").css("opacity","0");
			$("#subsubmenu ul").css("z-index","5");
			$("#subsubmenu"+index).css("z-index","10");
			fadeInSubMenu(index, amount);
			event.preventDefault();
		});
			
		$("#subsubmenu ul li").bind("mouseenter", function(){
			$("p", this).animate({ opacity: 1 }, 400, function(){
				if($.browser.msie) this.style.removeAttribute('filter');
			});
		});
		
		$("#subsubmenu10").bind("mousemove", function(event){
			var position = $(this).offset();
			$(this).css("bottom",  (-($(this).height()-(event.clientY-position.top))/2));
		});
		
		$("#subsubmenu9").bind("mousemove", function(event){
			var position = $(this).offset();
			$(this).css("bottom", (-($(this).height()-(event.clientY-position.top))/2));
		});
		
		$("#subsubmenu ul li").bind("mouseleave", function(){
			$("p", this).animate({ opacity: 0 }, 400);
		});
		
		$("#subsubmenu ul li p").css("opacity", "0");
		
		// TEXT
		
		$("#text-storia p:first").show();		
		
		$("#meer").bind("click", function(){
			$("#text-storia p:eq("+currStoria+")").hide();
			currStoria = currStoria >= ($("#text-storia p").length-1) ? 0 : currStoria+1;
			$("#text-storia p:eq("+currStoria+")").fadeIn();
		});
		
		$("#text-benvenito").fadeIn();
		
		var topY = ($(window).height()/(100/35))+($(window).width()/aspect)+20;
		$("#lower").css({top: topY+"px"});
		//$("#mosterd").css({top: (topY-5)+"px"});
		$("#mute").css({top: (topY-5)+"px"});
		
		// MUTE
				
		$("#mute a").bind("click", function(event){
			getFlashMovie("dalidia").setVolume(volume);
			if(volume){
				volume = 0;
				$("#sound").attr({
				  src: "images/sound.png",
				  title: 'muto'
				});
			}else{
				volume = 1;
				$("#sound").attr({
				  src: "images/mute.png",
				  title: 'suono'
				});
			}
			event.preventDefault();
		});
		
		// HIDE COMPONENTS
				
		clearAll();
		
		// MADE BY MOSTERD.
		
		$('#mosterd a').bind('mouseenter', function() {
			if(!slide){
				slide = true;
				$(this).animate({'width' : '59px'}, 300, function(){
					slide = false;
				});
			}
		});
		
		$('#mosterd a').bind('mouseleave', function() {

				$(this).animate({'width' : '19px'}, 300, function(){
					//slide = false;
				});

		});
			
	});
	
	// OPEN MENU AFTER FEW SECONDS
	
	function openMenu(){
		hideUpper();
		$("#submenu").show();
		$("#subsubmenu").show();
		setTimeout(function(){fadeInRootMenu($("#submenu li").size()-1);}, 30);
	}
	
	// ON RESIZE
	
	$(window).resize(function() {
		var topY = ($(window).height()/(100/35))+($(window).width()/aspect)+20;
		$("#lower").css({top: topY+"px"});
		//$("#mosterd").css({top: (topY-5)+"px"});
		$("#mute").css({top: (topY-5)+"px"});
	});
	
	// FADE MENUS
	
	function fadeInRootMenu(index){
		if(index>=0){
			$("#submenu li:eq("+index+")").animate({ opacity: 1 }, 400, function(){
				if($.browser.msie) this.style.removeAttribute('filter');
			});
			setTimeout(function(){fadeInRootMenu(--index);}, 30);
		}
	}
	
	function fadeInSubMenu(objid, index){
		if(index>=0){
			$("#subsubmenu"+objid+" li:eq("+index+")").animate({ opacity: 1 }, 400, function(){
				if($.browser.msie) this.style.removeAttribute('filter');
			});
			setTimeout(function(){fadeInSubMenu(objid, --index);}, 30);
		}
	}

	// HIDE COMPONENTS
	
	function clearAll(){
		$("#submenu ul li").css("opacity","0");
		$("#subsubmenu ul li").css("opacity","0");
	}
	
	// TALK TO FLASH MOVIE
	
	function getFlashMovie(movieName) {

		  if (window.document[movieName]) 
		  {
			return window.document[movieName];
		  }
		  if (navigator.appName.indexOf("Microsoft Internet")==-1)
		  {
			if (document.embeds && document.embeds[movieName])
			 return document.embeds[movieName]; 
		  }
		  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		  {
			return document.getElementById(movieName);
		  }
		
	}
	
	// HIDE ALL UPPER TEXT AND MENUS
	
	function hideUpper(){
		$("#text-storia").hide();
		$("#text-eventi").hide();
		$("#text-menu").hide();
		$("#text-benvenito").hide();
		$("#text-informazione").hide();
		$("#submenu").hide();
		$("#subsubmenu").hide();
	}
	
	// SLIDE TICKER
	
	function slideTicker(index){
		
		if(currentTicker!=-1){
			var wi = $(window).width();
			$('#ticker ul li:eq('+currentTicker+')').animate({ left: '-'+wi+'px'}, 1000, 'swing', function(){
				$(this).css({left: wi+'px' });
				$(this).hide();
			});
		}
		$('#ticker ul li:eq('+index+')').show();
		$('#ticker ul li:eq('+index+')').animate({ left: '0'}, 1000, 'swing', function(){
			
		});
		currentTicker = index;
		
		index = (index>=tickerAmount) ? 0 : ++index;
		
		setTimeout(function(){slideTicker(index)}, 5000);
		
	}
	
	
//
//  jQuery IE Fade Fix
//
//  Adapted from code found at http://jquery.malsup.com/fadetest.html.
//
//  This is only needed for IE 7 and earlier, so this is best added to your page using IE's conditional comments
//  (http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx) as follows:
//      <!--[if lt IE 8]><script type="text/javascript" src="jquery-ie-fade-fix.js"></script><![endif]-->
//
(function($) {
    $.fn.fadeIn = function(speed, callback) {
        return this.animate({opacity: 'show'}, speed, function() {
                if ( $.browser.msie )
                {
                        this.style.removeAttribute('filter');
                }
                if ( $.isFunction(callback) )
                {
                        callback.call(this);
                }
        });
    };

    $.fn.fadeOut = function(speed, callback) {
        return this.animate({opacity: 'hide'}, speed, function() {
                if ( $.browser.msie )
                {
                        this.style.removeAttribute('filter');
                }
                if ( $.isFunction(callback) )
                {
                        callback.call(this);
                }
        });
    };

    $.fn.fadeTo = function(speed, to, callback) {
        return this.animate({opacity: to}, speed, function() {
                if ( to == 1 && $.browser.msie )
                {
                        this.style.removeAttribute('filter');
                }
                if ( $.isFunction(callback) )
                {
                        callback.call(this);
                }
        });
    };
})(jQuery);
