﻿//scorrimento gallery hp
function fadejack(){
	if($('.novita img.scorrinovita:visible').next('img').length>0){
		$('.novita img.scorrinovita:visible').stop(true, true).fadeOut(1000).next().fadeIn(1000);
	} else {
		$('.novita img.scorrinovita:visible').stop(true, true).fadeOut(1000);
		$('.novita img.scorrinovita').eq(0).fadeIn(1000);
	}
}




//
function makeScrollable($outer, $inner){
	var extra = 100;
	var divWidth = $outer.width();

	var lastElem = $inner.find('div.mini_report:last');
	$outer.scrollLeft(0);
	$outer.unbind('mousemove').bind('mousemove',function(e){
		var containerWidth = lastElem[0].offsetLeft + lastElem.outerWidth() + 2*extra;
		var left = (e.pageX - $outer.offset().left) * (containerWidth-divWidth) / divWidth - extra;
		$outer.scrollLeft(left);
	});

}


$(document).ready(function(){

	$(".color_gallery_immagini .img_pc_mini a").click(function(){
		if ($(this).attr("href")!="images/img_def_pic.png"){
			//setta immagine grande
			$(".img_gr_collezione .img_sfondo_cent img").attr("src", $(this).attr("href").replace("660x450","450x200"));
			
			//setta colori dello sfondo inattivo
			$(".img_pc_mini .img_mini_cent").removeClass("img_mini_cent").addClass("img_mini_cent_off")
			$(".img_pc_mini .img_mini_left img").attr("src", "images/mini_col_gr_01_off.png");
			$(".img_pc_mini .img_mini_right img").attr("src", "images/mini_col_gr_03_off.png");
			//setta colori sfondo attivo
			$(this).parent().removeClass("img_mini_cent_off").addClass("img_mini_cent");
			$(this).parent().prev().children().eq(0).attr("src", "images/mini_col_gr_01.png" );
			$(this).parent().next().children().eq(0).attr("src", "images/mini_col_gr_03.png" );
			
			//collegamento immagine da ingrandire
			$(".upgrade_img a").attr("href", $(this).attr("href"));
		}
		return false;
	});


//news scorrimento pagine
	if ($('.mini_news').length>0){
		$('.mini_news').width($('.mini_news .mini_report').length*192);
		makeScrollable($('.cont_under_news'), $('.mini_news'));
	}
	

	$('.upgrade_img a').click(function(){
		Shadowbox.open({
			type: 'img',
			// rel: 'ciao',
			content: $(this).attr("href"),
			height: 450,
			width: 660,
			gallery: 'prodotti'
		});
		return false;
	});



	//scorrimento gallery footer
	if ($('.novita img.scorrinovita').length>1){
		$('.novita img.scorrinovita:gt(0)').hide();
		Intervaljackgallery=setInterval("fadejack()", 5000);
	}
	

	
//scorrimento gallery artigianalità
	if ($('.img_anniversary .didascalia_anniversary p').html()==""){
		$('.img_anniversary .didascalia_anniversary').hide();
	}
	$('.img_cont_gallery div').click(function(){
		
			
		$('.img_gr_gallery img').attr("src", $('.img_gr_gallery img').attr("src").replace("105x80", "80x55"));
		$('.img_gr_gallery').removeClass('img_gr_gallery').addClass('img_pc_gallery');
		$(this).find('img').attr("src", $(this).find('img').attr("src").replace("80x55","105x80"));
		$(this).removeClass('img_pc_gallery').addClass('img_gr_gallery');
		
		$('.img_anniversary img').attr("src", $(this).find('img').attr("src").replace("105x80","280x210"));
		$immagine=$(this);
		$('.img_anniversary .didascalia_anniversary').slideUp(500, function(){
			if ($immagine.find('img').attr("alt")!=""){
				$('.img_anniversary .didascalia_anniversary').html("<p>"+$immagine.find('img').attr("alt")+"</p>").slideDown();
			}
		});

		$('.titolo_anniversary h2').html($('.hidden ').eq($('.img_cont_gallery div').index($(this))).find('h2').html());
		$('.box_anniversary h2').html($('.hidden ').eq($('.img_cont_gallery div').index($(this))).find('h2').html());
		$('.testo_anniversary p').html($('.hidden ').eq($('.img_cont_gallery div').index($(this))).find('p').html());
		//Cufon.replace('.title', { fontFamily: 'Gotham' }); 
		Cufon.replace('.menu', { fontFamily: 'Edwardian Script ITC' });
		fleXenv.updateScrollBars();
		document.getElementById("flex__1").fleXcroll.setScrollPos(false,0);
		return false;
	});
	

	
	
//scorrimento freccia
	
	$('.container_anniversary .freccia').click(function(){
		if ($('.img_cont_gallery .img_gr_gallery').next().length>0){
			
			$('.img_gr_gallery img').attr("src", $('.img_gr_gallery img').attr("src").replace("105x80", "80x55")).parent().next().find('img').attr("src", $('.img_gr_gallery').next().find('img').attr("src").replace("80x55","105x80"));
			$('.img_gr_gallery').removeClass('img_gr_gallery').addClass('img_pc_gallery').next().removeClass('img_pc_gallery').addClass('img_gr_gallery');
		
			$('.img_anniversary img').attr("src", $('.img_gr_gallery img').attr("src").replace("105x80","280x210"));
			$('.img_anniversary .didascalia_anniversary p').html($('.img_gr_gallery img').attr("alt"));

			$('.titolo_anniversary h2').html($('.hidden ').eq($('.img_cont_gallery div').index($('.img_gr_gallery'))).find('h2').html());
			$('.box_anniversary h2').html($('.hidden ').eq($('.img_cont_gallery div').index($('.img_gr_gallery'))).find('h2').html());
			$('.testo_anniversary p').html($('.hidden ').eq($('.img_cont_gallery div').index($('.img_gr_gallery'))).find('p').html());
			//Cufon.replace('.title', { fontFamily: 'Gotham' }); 
			Cufon.replace('.menu', { fontFamily: 'Edwardian Script ITC' });
			fleXenv.updateScrollBars();
			document.getElementById("flex__1").fleXcroll.setScrollPos(false,0);
			
			
		} else {
			$('.img_gr_gallery img').attr("src", $('.img_gr_gallery img').attr("src").replace("105x80", "80x55"));
			$('.img_gr_gallery').removeClass('img_gr_gallery').addClass('img_pc_gallery');
			$('.img_pc_gallery').first().find('img').attr("src", $('.img_pc_gallery').first().find('img').attr("src").replace("80x55","105x80"));
			$('.img_pc_gallery').first().removeClass('img_pc_gallery').addClass('img_gr_gallery');
		
			$('.img_anniversary img').attr("src", $('.img_gr_gallery img').attr("src").replace("105x80","280x210"));
			$('.img_anniversary .didascalia_anniversary p').html($('.img_gr_gallery img').attr("alt"));

			$('.titolo_anniversary h2').html($('.hidden ').eq($('.img_cont_gallery div').index($('.img_gr_gallery'))).find('h2').html());
			$('.box_anniversary h4').html($('.hidden ').eq($('.img_cont_gallery div').index($('.img_gr_gallery'))).find('h4').html());
			$('.testo_anniversary p').html($('.hidden ').eq($('.img_cont_gallery div').index($('.img_gr_gallery'))).find('p').html());
			// Cufon.replace('.title', { fontFamily: 'Gotham' }); 
			Cufon.replace('.menu', { fontFamily: 'Edwardian Script ITC' });
			fleXenv.updateScrollBars();
			document.getElementById("flex__1").fleXcroll.setScrollPos(false,0);
		}
		return false;
	});
	
	
//scorrimento collezione
	animationmenu=false;
if ($('.under_collections .sfondo_anteprima').length>3){
		$('.freccia_D').show();
		$('.under_collections .under_scorri').css("width", $('.under_collections .sfondo_anteprima').length*312+"px")
	}
	
	$('.freccia_S').click(function(){
		if (!animationmenu){
			animationmenu=true;
			$('.freccia_D').show();
			if ($('.under_collections .under_scorri').css("left")!="0px"){
				$('.under_collections .under_scorri').stop(true, true).animate({left: "+=936"}, 500, function(){
					if ($('.under_collections .under_scorri').css("left")=="0px"){
						$('.freccia_S').hide();
					}
					fleXenv.updateScrollBars();
					animationmenu=false;
				});
			}
		}
		return false;
	});
	$('.freccia_D').click(function(){
		if (!animationmenu){
			animationmenu=true;
			$('.freccia_S').show();
			
			if ($('.under_collections .under_scorri').css("left")>((Math.floor(($('.under_collections .sfondo_anteprima').length-1)/3))*-936)+"px"){
				$('.under_collections .under_scorri').stop(true, true).animate({left: "-=936"}, 500, function(){
		
					if ($('.under_collections .under_scorri').css("left")==((Math.floor(($('.under_collections .sfondo_anteprima').length-1)/3))*-936)+"px"){
						$('.freccia_D').hide();
					}
					fleXenv.updateScrollBars();
					animationmenu=false;
				});
			}
			else{	
				$('.under_collections .under_scorri').stop(true, true).animate({left: "-=936"}, 500, function(){
		
					if ($('.under_collections .under_scorri').css("left")==((Math.floor(($('.under_collections .sfondo_anteprima').length-1)/3))*-936)+"px"){
						$('.freccia_D').hide();
					}
					fleXenv.updateScrollBars();
					animationmenu=false;
				});
			}
		}
		return false;
	});
//scorrimento altri punti di vista

	animationmenu=false;
if ($('.color_gallery .img_pc_mini').length>5){
		$('.freccia_D_color').show();
		$('.color_gallery .color_gallery_immagini').css("width", $('.color_gallery .img_pc_mini').length*86+"px")
	}
	
	$('.freccia_S_color').click(function(){
		if (!animationmenu){
			animationmenu=true;
			$('.freccia_D_color').show();
			if ($('.color_gallery .color_gallery_immagini').css("left")!="0px"){
				$('.color_gallery .color_gallery_immagini').stop(true, true).animate({left: "+=420"}, 500, function(){
					if ($('.color_gallery .color_gallery_immagini').css("left")=="0px"){
						$('.freccia_S_color').hide();
					}
					animationmenu=false;
				});
			}
		}
		return false;
	});
	$('.freccia_D_color').click(function(){
		if (!animationmenu){
			animationmenu=true;
			$('.freccia_S_color').show();
			if ($('.color_gallery .color_gallery_immagini').css("left")!=((Math.floor($('.color_gallery .img_pc_mini').length/5))*-420)+"px"){
				$('.color_gallery .color_gallery_immagini').animate({left: "-=420"}, 500, function(){
		
					if ($('.color_gallery .color_gallery_immagini').css("left")==((Math.floor($('.color_gallery .img_pc_mini').length/5))*-420)+"px"){
						$('.freccia_D_color').hide();
					}
					animationmenu=false;
				});
			}
		}
		return false;
	});

	


//scorrimento gallery index
	
	$('.slider_gallery_home').css("width", $('.slider_gallery_home .gallery_home').length*942);
		
	
	$('.testo_gallery strong').click(function(){
		$('.testo_gallery span').show();
		if ($('.container_gallery_home .slider_gallery_home').css("left")!="0px"){
			$('.container_gallery_home .slider_gallery_home').stop(true, true).animate({left: "+=942"}, 500, function(){
				if ($('.container_gallery_home .slider_gallery_home').css("left")=="0px"){
					$('.testo_gallery strong').hide();
				}
			});
		}
		return false;
	});
	$('.testo_gallery span').click(function(){
		$('.testo_gallery strong').show();
		if ($('.container_gallery_home .slider_gallery_home').css("left")!=(($('.container_gallery_home .gallery_home').length-1)*-942)+"px"){
			$('.container_gallery_home .slider_gallery_home').animate({left: "-=942"}, 500, function(){
				if ($('.container_gallery_home .slider_gallery_home').css("left")==(($('.container_gallery_home .gallery_home').length-1)*-942)+"px"){
					$('.testo_gallery span').hide();
				}
			});
			return false;
		}
	});
	
	
	
});

