var down = 1;
var contenuto = "italian/index.php";
var partenza = "Home";
var arrivo = "";
var delay = 0;


//Associa al bottone la posizione dell'immagine e  la funzione di apertura e chiusura del contenuto
$(function(){
   $('#Home')
   .css({backgroundPosition: '0 0'}) // workaround for FF 2.0 bug
   .click(function(){
   			contenuto = $(this).attr('href');
	       	arrivo = "Home";
			movimento();
			partenza = "Home";
	        return false;
	   });
});

//Associa al bottone la posizione dell'immagine e la funzione di apertura e chiusura del contenuto
$(function(){
   $('#GraphicDesign')
  		.css({backgroundPosition: '0 0'}) // workaround for FF 2.0 bug
		.click(function(){
			contenuto = $(this).attr('href');
			arrivo = "GraphicDesign";
			movimento();
			partenza = "GraphicDesign";
			return false;
	   });
});

//Associa al bottone la posizione dell'immagine e  la funzione di apertura e chiusura del contenuto
$(function(){
   $('#Advertising')
		.css({backgroundPosition: '0 0'}) // workaround for FF 2.0 bug
		.click(function(){
			contenuto = $(this).attr('href');
			arrivo = "Advertising";
			movimento();
			partenza = "Advertising";
			return false;
		});
});

//Associa al bottone la posizione dell'immagine e  la funzione di apertura e chiusura del contenuto
$(function(){
   $('#WebSolution')
   .css({backgroundPosition: '0 0'}) // workaround for FF 2.0 bug
   .click(function(){
   			contenuto = $(this).attr('href');
	        arrivo = "WebSolution";
			movimento();
			partenza = "WebSolution";      
	        return false;
	   });
});


//Associa al bottone la funzione di apertura e chiusura del contenuto
$(function(){
   $('#Contatti')
  		.css({backgroundPosition: '0 0'}) // workaround for FF 2.0 bug
		.click(function(){
			contenuto = $(this).attr('href');
			arrivo = "Arrivo";
			movimento();
			partenza = "Arrivo";
			return false;
	   });
});

//Associa alla maschera la funzione di apertura e chiusura del contenuto
$(function(){
	$('#Maschera').click(function(){
  		if (partenza == "Home"){
  			contenuto = $('#GraphicDesign').attr('href');
  			arrivo = "GraphicDesign";
			movimento();
			partenza = "GraphicDesign";
		}
		if (partenza == "Arrivo"){
  			contenuto = $('#Contatti').attr('href');
  			arrivo = "Niente";
			mostraContenuto();
			arrivo = "Arrivo";
		}
  		return false;
	});
});
	

function movimento(){

$('#ContentUp img').fadeTo("slow",0.001).hide();
$('#ContentUp').fadeTo("slow",0.001);
		
	if(partenza == 'Home'){
		if(arrivo == 'Home'){
			delay = 0;
		}
		if(arrivo == 'GraphicDesign'){
			$("#centrale").stop().animate({'background-position': '-2700px 0'},{duration:1000});
			$("#superiore").stop().animate({'background-position': '204px 25px'},{duration:1000});
			delay = 0;
		}
		if(arrivo == 'Advertising'){
			$("#centrale").stop().animate({'background-position': '-4800px 0'},{duration:2000});
			$("#superiore").stop().animate({'background-position': '404px 25px'},{duration:2000});
			delay = 1000;
		}
		if(arrivo == 'WebSolution'){
			$("#centrale").stop().animate({'background-position': '-6550px 0'},{duration:3000});
			$("#superiore").stop().animate({'background-position': '590px 25px'},{duration:3000});
			delay = 2000;
		}
		if(arrivo == 'Arrivo'){
			$("#centrale").stop().animate({'background-position': '-8700px 0'},{duration:4000});
			$("#superiore").stop().animate({'background-position': '804px 25px'},{duration:4000});
			delay = 3000;
		}

	}
	
	if(partenza == 'GraphicDesign'){
		if(arrivo == 'GraphicDesign'){
			delay = 0;
		}
		if(arrivo == 'Home'){
			$("#centrale").stop().animate({'background-position': '-450px 0'},{duration:1000});
			$("#superiore").stop().animate({'background-position': '64px 25px'},{duration:1000});
			delay = 0;
		}
		if(arrivo == 'Advertising'){
			$("#centrale").stop().animate({'background-position': '-4800px 0'},{duration:1000});
			$("#superiore").stop().animate({'background-position': '404px 25px'},{duration:1000});
			delay = 0;
		}
		if(arrivo == 'WebSolution'){
			$("#centrale").stop().animate({'background-position': '-6550px 0'},{duration:2000});
			$("#superiore").stop().animate({'background-position': '590px 25px'},{duration:2000});
			delay = 1000;
		}
		if(arrivo == 'Arrivo'){
			$("#centrale").stop().animate({'background-position': '-8700px 0'},{duration:3000});
			$("#superiore").stop().animate({'background-position': '804px 25px'},{duration:3000});
			delay = 2000;
		}

	}
	
	if(partenza == 'Advertising'){
		if(arrivo == 'Advertising'){
			delay = 0;
		}
		if(arrivo == 'Home'){
			$("#centrale").stop().animate({'background-position': '-450px 0'},{duration:2000});
			$("#superiore").stop().animate({'background-position': '64px 25px'},{duration:2000});
			delay = 1000;
		}
		if(arrivo == 'GraphicDesign'){
			$("#centrale").stop().animate({'background-position': '-2700px 0'},{duration:1000});
			$("#superiore").stop().animate({'background-position': '204px 25px'},{duration:1000});
			delay = 0;
		}

		if(arrivo == 'WebSolution'){
			$("#centrale").stop().animate({'background-position': '-6550px 0'},{duration:1000});
			$("#superiore").stop().animate({'background-position': '590px 25px'},{duration:1000});
			delay = 0;
		}
		if(arrivo == 'Arrivo'){
			$("#centrale").stop().animate({'background-position': '-8700px 0'},{duration:2000});
			$("#superiore").stop().animate({'background-position': '804px 25px'},{duration:2000});
			delay = 1000;
		}

	}
	
	if(partenza == 'WebSolution'){
		if(arrivo == 'WebSolution'){
			delay = 0;
		}
		if(arrivo == 'Home'){
			$("#centrale").stop().animate({'background-position': '-450px 0'},{duration:3000});
			$("#superiore").stop().animate({'background-position': '64px 25px'},{duration:3000});
			delay = 2000;
		}
		if(arrivo == 'GraphicDesign'){
			$("#centrale").stop().animate({'background-position': '-2700px 0'},{duration:2000});
			$("#superiore").stop().animate({'background-position': '204px 25px'},{duration:2000});
			delay = 1000;
		}
		if(arrivo == 'Advertising'){
			$("#centrale").stop().animate({'background-position': '-4800px 0'},{duration:1000});
			$("#superiore").stop().animate({'background-position': '404px 25px'},{duration:1000});
			delay = 0;
		}
		if(arrivo == 'Arrivo'){
			$("#centrale").stop().animate({'background-position': '-8700px 0'},{duration:1000});
			$("#superiore").stop().animate({'background-position': '804px 25px'},{duration:1000});
			delay = 0;
		}

	}
	
	if(partenza == 'Arrivo'){
		if(arrivo == 'Arrivo'){
			delay = 0;
		}
		if(arrivo == 'Home'){
			$("#centrale").stop().animate({'background-position': '-450px 0'},{duration:4000});
			$("#superiore").stop().animate({'background-position': '64px 25px'},{duration:4000});
			delay = 3000;
		}
		if(arrivo == 'GraphicDesign'){
			$("#centrale").stop().animate({'background-position': '-2700px 0'},{duration:3000});
			$("#superiore").stop().animate({'background-position': '204px 25px'},{duration:3000});
			delay = 2000;
		}
		if(arrivo == 'Advertising'){
			$("#centrale").stop().animate({'background-position': '-4800px 0'},{duration:2000});
			$("#superiore").stop().animate({'background-position': '404px 25px'},{duration:2000});
			delay = 1000;
		}
		if(arrivo == 'WebSolution'){
			$("#centrale").stop().animate({'background-position': '-6550px 0'},{duration:1000});
			$("#superiore").stop().animate({'background-position': '590px 25px'},{duration:1000});
			delay = 0;
		}

	}	
	
mostraContenuto();

}


function mostraContenuto(){
	if(arrivo==partenza) return;
	var toLoad = contenuto;
	
/*
	if (jQuery.browser.msie) {
		if(arrivo == "Niente"){
			$("#Contenuto").stop().fadeTo(1,0.001).animate({'top': '0px'},1,'',function(){$(this).load(toLoad,'');}).animate({'top': '0px'},1).animate({'top': '-630px'},1000).fadeTo(1,1); return;
		}
		if(arrivo != 'Home' && arrivo != 'Arrivo')
			$("#Contenuto").stop().animate({'top': '0px'},600,'',function(){$(this).load(toLoad,'');}).animate({'top': '0px'},delay).animate({'top': '-630px'},1000);
		else
			$("#Contenuto").stop().animate({'top': '0px'},600,'',function(){$(this).load(toLoad,'');});
	
		return;
	}
*/
	
	if(arrivo == "Niente"){
		$("#Contenuto").stop().animate({'top': '0px'},1,'',function(){$(this).load(toLoad,'');}).animate({'top': '0px'},1).animate({'top': '-630px'},1000); return;
	}
	if(arrivo != 'Home' && arrivo != 'Arrivo')
		$("#Contenuto").stop().animate({'top': '0px'},600,'',function(){$(this).load(toLoad,'');}).animate({'top': '0px'},delay).animate({'top': '-630px'},1000);
	else
		$("#Contenuto").stop().animate({'top': '0px'},600,'',function(){$(this).load(toLoad,'');});
}


function iniPulsanti(){
	$(".btn").each(function() {
		var percorso = $(this).attr("src").split(".");
		$(this).hover(	
			function () { $(this).attr({src: "." + percorso[1] + "Up." + percorso[2]});}, 
            function () { $(this).attr({src: "." + percorso[1] + "." + percorso[2]});  }
        );
	});
}

function iniGallery(cartella){
	$('#ContentUp img').fadeTo(1,0.001).hide();
	$('#ContentUp').fadeTo(1,0.001);
	var numeroImg = $('#ulGallery img').size()-1;
	var larghezzaImg = $('#ulGallery img:first').width();
	var marginImg = $('#ulGallery img:first').css("marginLeft");
	marginImg =	parseInt(marginImg);
	var maxLeft = 0;
	var maxRight = ((numeroImg * (larghezzaImg + (marginImg*2))) - $('#GalleriaC').width())*-1;
	$('#Indietro').click(function(){
		var valore = $('#ulGallery').css("margin-left");
		valore = parseInt(valore);
		if( valore < maxLeft )
			$('#ulGallery').animate({ marginLeft: '+=665' }, 500, function() { });
	});
	$('#Avanti').click(function(){ 
		var valore = $('#ulGallery').css("margin-left");
		valore = parseInt(valore);
		if( valore > maxRight)
			$('#ulGallery').animate({ marginLeft: '-=665' }, 500, function() { });
	});
	$('#Chiudi').click(function(){ 
		$('#ContentUp img').fadeTo("slow",0.001).hide();
		$('#ContentUp').fadeTo("slow",0.001);
	})
	
	$(".btn").each(function() {
		var percorso = 'fotogallery/'+cartella+'/'+$(this).attr('title')+".jpg";
		$(this).click(	
			function () { 
				$('#ContentUp img').show().fadeTo(1,1);
				$('#ContentUp').show().fadeTo('slow',1);
				$("#ImgGal").stop()
				.fadeTo(200,0.01, function(){$(this).hide().attr({src: ''}).attr({src: percorso}).fadeTo(1000,0.01).fadeTo('slow',1).show();});
				//.fadeTo('slow',1);
				$("#Descrizione").html($(this).children('img').attr("alt")); 
				if(cartella == "WebDesign") {$("#Descrizione").attr('href', 'http://'+$(this).children('img').attr("alt"));}
				return false;
/*
				$('#ContentUp img').show().fadeTo(1,1);
				$('#ContentUp').show().fadeTo('slow',1);
				$("#ImgGal").fadeOut('slow', function(){$("#ImgGal").attr({src: percorso});});
				$("#ImgGal").fadeIn('slow');
				$("#Descrizione").html($(this).children('img').attr("alt")); 
				if(cartella == "WebDesign") {$("#Descrizione").attr('href', 'http://'+$(this).children('img').attr("alt"));}
				return false;
*/
			}
        );
	});
}

function controllaSchermo(){
		if (($(window).width()>=1000) && ($(window).height()>=850)) {
			$('#VerticalAlign').removeClass('zoom');
			$('#VerticalAlign').removeClass('zoom2');
			$('#Social').removeClass('zoom');
			$('#Social').removeClass('zoom2');
			$('#Social').css('left', '0');
			$('#Zoom').html('Zoom: 100%');
		}
		if (($(window).width()<1000) || ($(window).height()<850)) {
			$('#VerticalAlign').removeClass('zoom3');
 			$('#VerticalAlign').removeClass('zoom2');
 			$('#VerticalAlign').addClass('zoom');
 			$('#Social').removeClass('zoom3');
 			$('#Social').removeClass('zoom2');
 			$('#Social').addClass('zoom');	
 			$('#Social').css('left', '-7px');
 			$('#Zoom').html('Zoom: 85%');	
		}
		if (($(window).width()<=900) || ($(window).height()<=750)) {
			$('#VerticalAlign').removeClass('zoom3');
 			$('#VerticalAlign').removeClass('zoom');
 			$('#VerticalAlign').addClass('zoom2');
 			$('#Social').removeClass('zoom3');
 			$('#Social').removeClass('zoom');
 			$('#Social').addClass('zoom2');
 			$('#Social').css('left', '-12px');
 			$('#Zoom').html('Zoom: 75%');
		}
		if (($(window).width()<=800) || ($(window).height()<=650)) {
			$('#VerticalAlign').removeClass('zoom');
 			$('#VerticalAlign').removeClass('zoom2');
 			$('#VerticalAlign').addClass('zoom3');
 			$('#Social').removeClass('zoom');
 			$('#Social').removeClass('zoom2');
 			$('#Social').addClass('zoom3');
 			$('#Social').css('left', '-17px');
 			$('#Zoom').html('Zoom: 65%');
		}
		
}


function controllaBrowser(){

if (jQuery.browser.msie) { 
	if(jQuery.browser.version=="6.0"){
		alert("Questo sito non supporta IE"+jQuery.browser.version+"\nPer una corretta visualizzazione ti consigliamo di cambiare \nil tuo browser o di aggiornarlo ad una versione meno obsoleta");
	}
	if(jQuery.browser.version=="7.0"){
		alert("Questo sito non supporta IE"+jQuery.browser.version+"\nPer una corretta visualizzazione ti consigliamo di cambiare \nil tuo browser o di aggiornarlo ad una versione meno obsoleta");
	}	
}

}
