$(document).ready(function() {
	auto();
});
var	current_item = 1;
var item_destination;
var interval;

function control_item(){ 
	if (current_item == 5) { current_item = 1 };
};
function timer() {};

function avanti(item_dest) {

			$('#cont_1 > .descr_item').removeClass("display");
			$('#cont_1 > .descr_item').animate({opacity: 0}, 1000);
			
	$('#content_gallery > #cont_1:first').animate({ opacity: 0.1, height: '+=30', width: '+=30', left: '-=100', top: '-=15' }, 800);
		
		setTimeout (function(){
			current_item = current_item + 1;
			control_item();
			
			$('#cont_2').css({'z-index':'100'});
			$('#cont_2').animate({top: '0', left: '0', width: '672', height: '222', opacity: 1}, 200 );
			$('#cont_3').css({'z-index':'99'});
			$('#cont_3').animate({ top: '10', left: '46', width: '652',	height: '202', opacity: 0.8}, 400 );
			$('#cont_4').css({'z-index':'98'});
			$('#cont_4').animate({ top: '20', left: '86', width: '632', height: '182', opacity: 0.5}, 600 );
			$('#content_gallery > #cont_1:first').css({'z-index':'96'});
			$('#content_gallery > #cont_1:first').animate({ top: '30', left: '126', width: '612', height: '162', opacity: 0.2}, 700 );
			$('#cont_2').attr ({id: "cont_prov"});
			$('#cont_3').attr ({id: "cont_2"});
			$('#cont_4').attr ({id: "cont_3"});
			$('#cont_1').attr ({id: "cont_4"});
			$('#cont_prov').attr ({id: "cont_1"});
				
			
			if (item_dest!=current_item && item_dest) {
				avanti(item_dest);
			}
			else {
				$('#cont_1 > .descr_item').animate({opacity: 1},1000,
					function () {
						$('#cont_1 > .descr_item').addClass("display");
						if (!interval) {
							auto()
						}
						
					});
			};
			
		}, 400);
};




function azione(item_destination) {
	
	if (interval) {
			clearInterval (interval);
			interval = false;
		}
	
	var item_d = item_destination;
	if (item_d == current_item) {
		
	}
	else {
		avanti(item_d);
	}
	
};
function auto() {
	interval=setInterval("avanti()", 8000);
	
};


