$(document).ready(function(){

	var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
	var contenuto_height = viewportHeight*0.9;
	var footer_height = viewportHeight*0.1;
		

	$('#sottoNews, #sottoExposition, #sottoPortfolio, #exposition, #contact').hide();
	$('#sottoNews, #sottoExposition, #news_content, #exposition_content, #sottoPortfolio, #contact').css({ bottom:-500 });
	$('.menu').css({ bottom:-99 });
	$('#footer_menu').css({ left:-9999 });
	$('#main_title').css({ bottom:-99 });
	$('#galleryTOP').css({ top:-2000 });
	$('#gallery').css({ top:-2000 });
	$('.hide').hide();
	$('#sfondo').hide(0);
	
	var loadedGallery=false;
	var loadedNews=false;
	var loadedExposition=false;
	var loadedSottomenuNews=false;
	var loadedSottomenuExposition=false;
	var loadedSottomenuPortfolio=false;
	var pretty=false;
	

	$(document).queue(function(){
		$('#contenuto').css({ height:contenuto_height });
		$('#footer_menu').css({ height:footer_height });
		$('#sfondo').fadeIn(1500);
		$('#sfondo').queue(function(){
		    $('#footer_menu').animate({ left:0 }, 2500);
		    $('#main_title').animate({ bottom:0 }, 1000);
		    $(this).dequeue();
		});

	    $(this).dequeue();
	});
	
	$('#main_title a').click(function(){
		$('#footer_menu').animate({ height:"20%" }, 1000, function(){
			$('.menu').animate({ bottom:0 }, 1000);
			$('#sottoNews, #sottoExposition, #sottoPortfolio, #exposition, #contact').hide();
			$('#sottoNews, #news_content,  #sottoExposition, #sottoPortfolio, #exposition, #contact').css({ bottom:-500 });
			$('#01_menu_news, #02_menu_portfolio, #03_menu_exposition, #04_menu_contact').css({ fontWeight: "normal" });
			$('#galleryTOP').css({ top:-3000 });
			$('#gallery').css({ top:-3000 });
		});
	});
	
	$('#01_menu_news').click(function(){		
		$('#portfolio, #exposition, #contact').fadeOut(1000).hide();
		$('#02_menu_portfolio, #03_menu_exposition, #04_menu_contact').css({ fontWeight: "normal" });
		$("#sottoNews a").css({ fontWeight: "normal" });
		$(this).css({ fontWeight: "Bold" });
		if(!loadedSottomenuNews){
			loadedSottomenuNews=true;
			$('<div id="info" />').load('news.asp #news', function(){
				$(this).hide().appendTo('#sottoNews').show();
			});
		}
		$('#footer_menu').animate({ height:"60%" }, 1000, function(){
			$('#sottoNews, #news').show();
			$('#sottoNews').animate({ bottom:0 }, 2000);
		});
		
		if(!loadedNews){
			loadedNews=true;
			$('<div id="news_content" />').load('news.asp #news_content_', function(){
				$(this).hide().appendTo('#sottoNews');
			});
		}
		
		return false; //per evitare che il link indirizzi a movies.html --> serve solo nel caso il javascript sia disattivato
	});
	
	$('#02_menu_portfolio').click(function(){				
		$('#news, #exposition, #contact').fadeOut(1000).hide();
		$('#01_menu_news, #03_menu_exposition, #04_menu_contact').css({ fontWeight: "normal" });
		$("#sottoPortfolio a").css({ fontWeight: "normal" });
		$(this).css({ fontWeight: "Bold" });
		if(!loadedSottomenuPortfolio){
			loadedSottomenuPortfolio=true;
			$('<div id="info" />').load('portfolio.asp #portfolio', function(){
			$(this).hide().appendTo('#sottoPortfolio').show();
		});
		}
		
		$('#footer_menu').animate({ height:"20%" }, 1000, function(){
				$('#sottoPortfolio, #portfolio').show();
				$('#sottoPortfolio').animate({ bottom:0 }, 1500);
		});
		if(!loadedGallery){
			loadedGallery=true;
			$('<div id="info" />').load('portfolio.asp #gallery', function(){
				$(this).hide().appendTo('#galleryTOP').show();	
			});
		}
		return false; //per evitare che il link indirizzi a movies.html --> serve solo nel caso il javascript sia disattivato
	});
	
	$('#03_menu_exposition').click(function(){
	
		$('#news, #portfolio, #contact').fadeOut(1000).hide();
		$('#01_menu_news, #02_menu_portfolio, #04_menu_contact').css({ fontWeight: "normal" });
		$("#sottoExposition a").css({ fontWeight: "normal" });
		$(this).css({ fontWeight: "Bold" });
		if(!loadedSottomenuExposition){
			loadedSottomenuExposition=true;
			$('<div id="info" />').load('exposition.asp #exposition', function(){
				$(this).hide().appendTo('#sottoExposition').show();
			});
		}
		$('#footer_menu').animate({ height:"60%" }, 1000, function(){
			$('#sottoExposition, #exposition').show();
			$('#sottoExposition').animate({ bottom:0 }, 2000);
		});
		
		if(!loadedExposition){
			loadedExposition=true;
			$('<div id="exposition_content" />').load('exposition.asp #exposition_content_', function(){
				$(this).hide().appendTo('#sottoExposition');
			});
		}
		
		return false; //per evitare che il link indirizzi a movies.html --> serve solo nel caso il javascript sia disattivato
	});
	
	$('#04_menu_contact').click(function(){
	
		$('#news, #portfolio, #exposition').fadeOut(1000);
		$('#01_menu_news, #02_menu_portfolio, #03_menu_exposition').css({ fontWeight: "normal" });
	
		$(this).css({ fontWeight: "Bold" });
		$('#footer_menu').animate({ height:"70%" }, 1000, function(){
			$('#contact').show();
			$('#contact').animate({ bottom:0 }, 2000);
		});
	});
	
	$('#portfolio a').livequery('click', function(event){
		var i=this.title;
		
		if(!pretty){
			pretty=true;
			$("a[rel^='prettyPhoto']").prettyPhoto({
				animationSpeed: 'normal', /* fast/slow/normal */
				padding: 40, /* padding for each side of the picture */
				opacity: 0.35, /* Value betwee 0 and 1 */
				showTitle: true, /* true/false */
				allowresize: true, /* true/false */
				counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
				theme: 'dark_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
			});
		}
		$('#portfolio a').css({ fontWeight: "Normal" });
		$(this).css({ fontWeight: "Bold" });
		
		$('#galleryTOP').animate({ top:0 }, 0, function(){
			$('#gallery').animate({ top:0 }, 1000);
			$('#gallery ul').hide();
			$('#gallery ul').css({ fontWeight: "Normal" });
			$("ul[title='" +i+ "']").fadeIn("slow");
			return false;
		});
	});
	
	$('#01_menu_news, #03_menu_exposition, #04_menu_contact').click(function(){
		$('#gallery, #galleryTOP').animate({ top:-200 }, 1000);
	});
	
	$('#02_menu_portfolio, #01_menu_news, #04_menu_contact').click(function(){
		$("#exposition_content ul").fadeOut("slow");
	});

	$('#02_menu_portfolio, #03_menu_exposition, #04_menu_contact').click(function(){
		$("#news_content ul").fadeOut("slow");
	});
	
	$('#01_menu_news, #02_menu_portfolio, #03_menu_exposition').click(function(){
		$('#contact').css({ bottom:-500 });
	});
	
	
	$('#news a').livequery('click', function(event){
		var n=this.title;
		$('#news a').css({ fontWeight: "Normal" });
		$(this).css({ fontWeight: "Bold" });
		
		$("#news_content ul").hide();
		$("#news_content").show();
		$("ul[title='" +n+ "']").fadeIn("slow");
		return false;
	});
	
	$('#exposition a').livequery('click', function(event){
		var n=this.title;
		$('#exposition a').css({ fontWeight: "Normal" });
		$(this).css({ fontWeight: "Bold" });
		
		$("#exposition_content ul").hide();
		$("#exposition_content").show();
		$("ul[title='" +n+ "']").fadeIn("slow");
		return false;
	});
	
	$("#sendmail").click(function(){
		var valid = '';
		var isr = ' is required.';
		var name = $("#name").val();
		var mail = $("#mail").val();
		var subject = $("#subject").val();
		var text = $("#text").val();
		if (name.length<1) {
			valid += '<br />Name'+isr;
		}
		if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			valid += '<br />A valid Email'+isr;
		}
		if (subject.length<1) {
			valid += '<br />Subject'+isr;
		}
		if (text.length<1) {
			valid += '<br />Text'+isr;
		}
		if (valid!='') {
			$("#response").fadeIn("slow");
			$("#response").html("Error:"+valid);
		}
		else {
			var datastr ='name=' + name + '&mail=' + mail + '&subject=' + subject + '&text=' + text;
			$("#response").css("display", "block");
			$("#response").html("Sending message .... ");
			$("#response").fadeIn("slow");
			//setTimeout("send('"+datastr+"')",2000);
			
			$.ajax({	
				type: "POST",
				url: "mail.php",
				data: datastr,
				cache: false,
				success: function(html){
				$("#response").fadeIn("slow",2000);
				$("#response").html(html);
				//setTimeout('$("#response").fadeOut("slow")',2000);
				$("#formail").fadeOut("slow");
			}
			});
			
		}
		return false;
	});

	/*
$('#news a:first').click(function(){
		$('.hide').hide();
		$('#berlin').fadeIn("slow");

	});
	
	$('#news a').eq(1).click(function(){
		$('.hide').hide();
		$('#steel').fadeIn("slow");
	});	
*/
});
