// JavaScript Document
jQuery.fn.fadeIn = function(speed, callback) {
    return this.animate({opacity: 'show'}, speed, function() {
        if (jQuery.browser.msie)
            this.style.removeAttribute('filter');
        if (jQuery.isFunction(callback))
            callback();
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) {
    return this.animate({opacity: 'hide'}, speed, function() {
        if (jQuery.browser.msie)
            this.style.removeAttribute('filter');
        if (jQuery.isFunction(callback))
            callback();
    });
};
 
jQuery.fn.fadeTo = function(speed,to,callback) {
    return this.animate({opacity: to}, speed, function() {
        if (to == 1 && jQuery.browser.msie)
            this.style.removeAttribute('filter');
        if (jQuery.isFunction(callback))
            callback();
    });
};

$(document).ready(function(){
	
	//menu
	$('#menu_principale li').mouseover(function() {
		var nameImg = $(this).find('a').attr('id');
		$('a img', this).attr('src','img/menu_' + nameImg + '_on.png');
	});
	$('#menu_principale li').mouseout(function() {
		var nameImg = $(this).find('a').attr('id');
		$('a img', this).attr('src','img/menu_' + nameImg + '.png');
	});
	
	//in base all'id del body
	if ($('#index').length > 0){
		$('#container').hide();
		$('#content .blocco').hide();
		$('h1').hide();
		$('a').hide();
		$('#container').delay(600).fadeIn(800);
		$('#content .blocco').delay(1400).fadeIn(800);
		$('h1').delay(2200).fadeIn(600);
		$('#ita').delay(2600).fadeIn(600);
		$('#eng').delay(3000).fadeIn(600);
		$('#credits').delay(3400).fadeIn(600);
		
		$('#ita').click(function(){
			$('#container').fadeOut(800);
			setTimeout(function(){document.location.href="home_ita.html"; },1000);
		});
	};//index
	
/*	//in base all'id del body
	if ($('#chi-siamo').length > 0){
		$('.p2').click(function(){
			$('#p1').animate({'left':'-600'},600);
			$('#p2').animate({'left':'0'},600);
		});
		$('.p1').click(function(){
			$('#p1').animate({'left':'0'},600);
			$('#p2').animate({'left':'600'},600);
		});
	};//chi-siamo
*/	
	//in base all'id del body
	if ($('#chi-siamo3').length > 0){
		//scroll
		$(function() { $('.scroll').jScrollPane(); });
		
		//gallery
		var numImg = $('#gallery_chi_siamo').find("li").length;
		var controllo = numImg + 1;
		var imgCorrente = 1;
		var imgProssima = 2;
		var imgPrecedente = numImg;
		$('#gallery_chi_siamo img').fadeOut(0);
		$('#gallery_chi_siamo .li1 img').fadeIn(0);
		$('#gallery_chi_siamo .li1 img').css({'z-index':1050});
		$('#gallery_chi_siamo .li2 img').css({'z-index':1090});
		
		$('#siamodx').click(function(){
			imgPrecedente = imgCorrente;
			imgCorrente = imgProssima;
			imgProssima = imgCorrente + 1;
			if(imgProssima == controllo){
				imgProssima = 1;
			};
			$('#gallery_chi_siamo .li' + imgCorrente + ' img').fadeIn(600);
			$('#gallery_chi_siamo .li' + imgPrecedente + ' img').delay(600).fadeOut(0);
			$('#gallery_chi_siamo .li' + imgCorrente + ' img').css({'z-index':1050});
			$('#gallery_chi_siamo .li' + imgProssima + ' img').css({'z-index':1090});
			$('#gallery_chi_siamo .li' + imgPrecedente + ' img').css({'z-index':1010});
		});
		$('#siamosx').click(function(){
			imgProssima = imgCorrente;
			imgCorrente = imgPrecedente;
			imgPrecedente = imgCorrente - 1;
			if(imgPrecedente == 0){
				imgPrecedente = numImg;
			};
			$('#gallery_chi_siamo .li' + imgCorrente + ' img').css({'z-index':1050});
			$('#gallery_chi_siamo .li' + imgProssima + ' img').css({'z-index':1090});
			$('#gallery_chi_siamo .li' + imgPrecedente + ' img').css({'z-index':1010});
			$('#gallery_chi_siamo .li' + imgCorrente + ' img').fadeIn(0);
			$('#gallery_chi_siamo .li' + imgProssima + ' img').fadeOut(600);
		});
	};//chi-siamo
	
	//in base all'id del body
	if ($('.elenco').length > 0){
		
		/*$('.div_spec').fadeTo(0,0);
		$('.immobile a').mouseover(function(){
			$('.div_spec', this).fadeTo(200,1);
		});
		$('.immobile a').mouseout(function(){
			$('.div_spec', this).fadeTo(200,0);
		});*/
		
		$('.div_spec').hide();
		$('.elenco a').mouseover(function(){
			$('.div_spec', this).show();
		});
		$('.elenco a').mouseout(function(){
			$('.div_spec', this).hide();
		});
		
		$('.div_spec_bianco').hide();
		$('.elenco a').mouseover(function(){
			$('.div_spec_bianco', this).show();
		});
		$('.elenco a').mouseout(function(){
			$('.div_spec_bianco', this).hide();
		});
		
	};//immobili
	
	//in base all'id del body
	if ($('#complesso').length > 0){
		$('#bg-testo').fadeOut(0);
		$('#testo').fadeOut(0);
		$('.more').click(function(){
			$('#bg-testo').fadeIn(500);
			$('#testo').fadeIn(600);
		});
		$('.back').click(function(){
			$('#bg-testo').fadeOut(600);
			$('#testo').fadeOut(500);
		});
	};//complesso
	
	//in base all'id del body
	if ($('#scheda-immobile').length > 0){
		//gallery
		var contaLi = $('#gallery').find("li").length;
		var numeroImgGallery = contaLi-3;
		var imgVisualizzata = 1;
		
		$('#gallery a').click(function() {
			$('#gallery a').removeClass('sel');
			var nameImg = $(this).attr('rel');
			if (nameImg == 'avanti'){
				imgVisualizzata++;
				if(imgVisualizzata > numeroImgGallery){imgVisualizzata = 1;};
				$('#gallery #'+imgVisualizzata).addClass('sel');
				nameImg = $('#gallery #'+imgVisualizzata).attr('rel');
			} else if (nameImg == 'indietro'){
				imgVisualizzata--;
				if(imgVisualizzata == 0){imgVisualizzata = numeroImgGallery;};
				$('#gallery #'+imgVisualizzata).addClass('sel');
				nameImg = $('#gallery #'+imgVisualizzata).attr('rel');
			} else {
				$(this).addClass('sel');
				imgVisualizzata = $(this).attr('id');
			};
			$('#grigio img').hide().attr('src','img/' + nameImg).fadeIn(400);
		});
		//more
		$('#bg-testo').fadeOut(0);
		$('#testo').fadeOut(0);
		$('.more').click(function(){
			$('#bg-testo').fadeIn(500);
			$('#testo').fadeIn(600);
		});
		$('.back').click(function(){
			$('#bg-testo').fadeOut(600);
			$('#testo').fadeOut(500);
		});
		//mappa
		Shadowbox.init();
		/*$('iframe').fadeOut(0);
		$('.chiudi-mappa').fadeOut(0);
		$('.map').click(function(){
			$(this).addClass('sel');
			$('#grigio img').fadeOut(600);
			$('#grigio #gallery').fadeOut(600);
			$('iframe').fadeIn(600);
			$('.chiudi-mappa').fadeIn(600);
		});
		$('.chiudi-mappa').click(function(){
			$('#grigio img').fadeIn(600);
			$('#grigio #gallery').fadeIn(600);
			$('iframe').fadeOut(600);
			$('.chiudi-mappa').fadeOut(600);
			$('.map').removeClass('sel');
		});*/	
	};//scheda-immobile

});
