var timeout;
var posizioneFoto = -1;

$(function() {
	
	// GALLERIA \\
	var elementi = $(".show_foto_images img").size();
	for(i = 0; i < elementi;i++) {
		$('.show_foto .cerchietti').append('<img src="/views/east/images/latest/inattivo.png" style="position: static"/> ');
	}
	imageRoll();
	setInterval('imageRoll()', 10000);
	
	$(window).trigger('resize');
	
});

$(window).bind('resize', function() {
	etichette();
	posizioneMenu();
})

function imageRoll() {
	
	var elementi = $(".show_foto_images img").size() - 1;
	
	var hide = posizioneFoto;
	var show = posizioneFoto+1;
	
	if(posizioneFoto == elementi) {
		show = 0;
		hide = elementi;
		posizioneFoto = -1;
	}
	
	$($(".show_foto .cerchietti img").get(show)).attr("src", "/views/east/images/latest/attivo.png");
	$($(".show_foto .cerchietti img").get(posizioneFoto)).attr("src", "/views/east/images/latest/inattivo.png");
	
	$($(".show_foto h1").get(hide)).fadeOut();
	$($(".show_foto h1").get(show)).fadeIn();
	
	$($(".show_foto div.desc").css({width: 201, height: 50}).get(hide)).fadeOut();
	$($(".show_foto div.desc").css({width: 201, height: 50}).get(show)).fadeIn();
	
	$($(".show_foto_images img").get(hide)).fadeOut();
	$($(".show_foto_images img").get(show)).fadeIn();
	
	posizioneFoto++;
	
}

function chiudiMenu() {
	
	var posizione = $("#sub-menu").offset();
	var larghezza = $("#sub-menu").innerWidth();
	var altezza = $("#sub-menu").innerHeight();
	
	$("<div />")
		.html('<img src="/views/east/images/etichette/fine-menu.png" />')
		.css({
			height: 11,
			position: 'absolute',
			top: posizione.top + altezza,
			left: posizione.left + larghezza - 11
		})
		.appendTo('body');
	
}

function posizioneMenu() {
	
	if($(".selected").html()) {
	
		var posizione = $(".selected").offset();
		var larghezza = $(".selected").innerWidth();
	
		$("<div />")
			.css({
				backgroundImage: 'url(/views/east/images/etichette/li-background.png)',
				backgroundPosition: 'top right',
				height: 6,
				position: 'absolute',
				top: posizione.top - 6,
				left: posizione.left,
				width: larghezza + 6
			})
			.appendTo("body");
	
			chiudiMenu();
		
	}
}

function etichette() {
	
	$(".etichetta").css({
		zIndex: 9
	});
	
	$('.orange-left').each(function() {
		
		$(this).css({
			float: 'right',
			padding: '10px',
			backgroundColor: '#f6a033',
			marginRight: '0px',
			marginBottom: '10px',
			color: 'white'
		}).wrap('<div></div>').parent().append('<img src="/views/east/images/etichette/orange-left.png" style="float: right; margin-top: 27px" />');
		
	});
	
	$('.orange-right').each(function() {
		
		$(this).css({
			float: 'right',
			padding: '10px',
			backgroundColor: '#f6a033',
			marginBottom: '10px',
			color: 'white'
		}).wrap('<div style="margin-right: -12px"></div>').parent().prepend('<img src="/views/east/images/etichette/orange-right.png" style="float: right; margin-top: 27px" />');
		
	});
	
	$('.orange-bottom').each(function() {
		
		$(this).css({
			float: 'right',
			padding: '10px',
			backgroundColor: '#f6a033',
			marginBottom: '10px',
			color: 'white'
		}).wrap('<div></div>').parent().prepend('<img src="/views/east/images/etichette/orange-bottom.png" style="float: right; margin-top: 38px; margin-left: -12px" />');
		
	});
	
	$('.gray-down').each(function() {
		
		$(this).css({
			float: 'right',
			padding: '10px',
			backgroundColor: '#8b8b8b',
			marginBottom: '10px',
			color: 'white'
		}).wrap('<div></div>').parent().prepend('<img src="/views/east/images/etichette/gray-bottom.png" style="float: right; margin-top: 38px; margin-left: -12px" />');
		
	});	
	
	
}
