/*--------------------------------------------------
cover carousel
--------------------------------------------------*/
function coverCarousel(){
	$("#banner li").each(function(j){
		$(this).data("pos",j);
	});
	
	var i = 1;
	var arr = [1,2,3,4,5];
	var pos = [];
	pos[0] = [{"left":"1px","top":"28px"},{"width":402,"height":268},70];
	pos[1] = [{"left":"92px","top":"19px"},{"width":416,"height":283},80];
	pos[2] = [{"left":"221px","top":"1px"},{"width":518,"height":321},90];
	pos[3] = [{"left":"450px","top":"19px"},{"width":416,"height":283},80];
	pos[4] = [{"left":"557px","top":"28px"},{"width":402,"height":268},70];
	
	function moveCarousel(obj){
		$("#banner .png").hide();
		var i;
		for (i in obj) {
			$("#banner .img"+obj[i]).data("pos",i).animate(pos[i][0],300,function(){
				$(this).css({"z-index":pos[$(this).data("pos")][2]});
				if ($.browser.msie) {
					$("#banner .png").show();
				} else {
					$("#banner .png").fadeIn(200);
				}
			}).children().css(pos[i][1]);
		}
		
	}
	
	$("#banner a.prev").click(function(){
		el = arr.shift();
		arr.push(el);
		$("#banner li[rel=3]").css("z-index",1000);
		$("#banner li").each(function(){
			if ($(this).data("pos")==3){
				$(this).css({"z-index":100});
			}
		});
		moveCarousel (arr);
		return false;
	});
	
	$("#banner a.next").click(function(){
		el = arr.pop();
		arr = arr.reverse();
		arr.push(el);
		arr = arr.reverse();
		$("#banner li[rel=1]").css("z-index",1000);
		
		$("#banner li").each(function(){
			if ($(this).data("pos")==1){
				$(this).css({"z-index":100});
			}
		});
		
		moveCarousel (arr);
		return false;
	});
	/* Attiva l'animazione automatica del Corousel */
	$('#banner').hover(function(){$(this).data('stop_autoplay',true);},function(){$(this).data('stop_autoplay',false);});
	var autoplay = setInterval(function(){
				if(!$('#banner').data('stop_autoplay')){
					$("#banner a.next").trigger('click');
				}
			}, 3600)
}


/*--------------------------------------------------
INIT
--------------------------------------------------*/
$(function(){
	coverCarousel();
	$('#fancybox').each(function(){if ($(this).children('.scrollable').children().size()==0)$(this).remove()});
	$("a.fancybox").fancybox({"overlayColor":"#000", "overlayOpacity":"0.5", "speedIn":250, "speedOut":250});
	$(".scrollable").scrollable(); //.navigator()
	$('.doc_img_1').click(function(){$('a.fancybox:eq(0)').click()});
	// Rimuovo la galleria se non ci sono elementi da mostrare
});
