var transizioneObject = function(preloader, posizioni, menuPannello) {
	jQuery.fx.off=false;

	var numLoop=0;
	var me;
	var prossimoFrame=0;

	var estro = $("div.payload>div.estro");
	var dati = $("div.pannello_container");

	var browser = $("div.browser",estro);
	var frecce = $("div.freccia", estro);

	var sinistra = $("div.navbar>div.sinistra");
	var destra = $("div.navbar>div.destra");

	var intro = $("div.payload>div.intro");
	var controlli = $("div.controlli_container");

//	var clock = function() { return (new Date()).getTime() };
//	var zulu=clock();	
//	var indica = $("<span style='position: absolute; bottom: 1em; left: 2em' />").appendTo("body");

	var testo = new scrollerPannello(parseInt($("div.testo").css("lineHeight")), parseInt($("div.testo_container").css("height")));

	$("div.testo_container>div.testo").mousewheel(function(ev,s){testo.scrolla((s>0)?-1:1)});
	$("div.testo_su").click(function(){testo.scrolla(-1)});
	$("div.testo_giu").click(function(){testo.scrolla(1)});

	var slideshow = new slideshowObject("img.slideshow", true);

	var me=this;

	this.tavola = (function() {
		var me;
		var posizione = 1;

		browser.css({top: posizioni[posizione]});

		return me={
			corrente: 0,
			alza: function() {
				browser.eq(me.corrente).css({top: posizioni[posizione]});
			},
			alzaLento: function() {
				browser.eq(me.corrente).animate({top: posizioni[posizione]}, 2500);
			},
			scambia: function() {					
				browser.eq(me.corrente)
					.fadeOut(500);
				me.corrente = (me.corrente+1)%browser.length;
				browser.eq(me.corrente)
					.css({top: posizioni[posizione]})
					.fadeIn(500);
			},
			scambiaLento: function() {					
				browser.eq(me.corrente)
					.fadeOut(500, function() {
						me.corrente = (me.corrente+1)%browser.length;
						browser.eq(me.corrente)
							.css({top: posizioni[posizione]})
							.fadeIn(500);
				});
			},
			aggiorna: function(m,p) {
				switch (m) {
				case 1:
					me.alza();
					break;
				case 2:
					if (
						((posizione == 0)&&(p>1))||
						((p==0)&&(posizione>1))
					)
						me.scambiaLento();
					else
						me.alzaLento();
					break;
				case 3:
					me.scambia();
					break;
				case 4:
					me.scambiaLento();
					break;
				}
			},
			scrollaA: function(modo, a) {
				var p=posizione;
				posizione = a;
				me.aggiorna(modo,p);
			},
			scrolla: function(modo, delta) {
				var p=posizione;
				posizione += delta;
				if (posizione<0) {
					posizione = 0;
				} else if (posizione>=posizioni.length) {
					posizione = posizioni.length-1;
				} else {
					me.aggiorna(modo,p);
				}
				//posizione = (posizione+delta+posizioni.length)%posizioni.length;
			}
		};
	})();
	var h_filetto_bottom = $("div.payload").height()+2;
	var h_img_full = parseInt($("img.tavola").css("height"))+2;

	$("div.filetto.bottom")
		.css({top: h_img_full});
	$("div.filetto").show();
	sinistra.show();
	destra.hide();
	
	intro.hide();

	if (0)
	estro
		.unbind("mousewheel")
		.mousewheel(function(ev,s) {me.tavola.scrolla(2,(s<0)?1:-1)})
	;			

	controlli
		.hide(); 
	browser
		.hide()
		.empty();
	dati
		.hide();
	estro
		.show();

	var update=function() {
		var skipToFrame = function(n) {
			prossimoFrame = n;
			update();				
		}	
		function pausaUpdate(t) {
			if (jQuery.fx.off)
				setTimeout(update,100);
			else
				setTimeout(update,t);
		}
		var frame = prossimoFrame++;	

		//var delta = clock()-zulu;
		//indica.html("frame "+numLoop+":"+frame+" time "+delta/1000+"s");
		//console.log(frame);

		switch (frame) {
		case 0:
			browser
				.empty()
				.append(preloader.img(2))
				.append(preloader.img(3))
			;
			loadProgress.update(100);
			loadProgress.d().fadeOut(1000, update);

			browser.eq(me.tavola.corrente).hide();
			sinistra.show();
			break;
		case 1:
			destra.hide();
			controlli.hide();
			dati.hide();

			$("div.payload,div.filetto")
				.fadeIn(1000);
			intro.fadeIn(1000, update);
			break;
		case 2:
			pausaUpdate( 2000 );
			break;
		case 3:
			intro.fadeOut(2000);
			pausaUpdate( 1000 );
			break;
		case 4:
			$("div.filetto.bottom")
				.animate({top: h_filetto_bottom},1000,null,update);
			break;
		case 5:
			browser.eq(me.tavola.corrente)
				.fadeIn(1000, update);
			break;
		case 6:			
			destra.show();
			$("div.payload").height(estro.height());
			if (menuPannello !== undefined)
				menuPannello.mostraIntro();
			dati.fadeIn(1000, update);
			break;
		case 7:
			controlli
				.show();
			frecce
				.unbind("click")
				.click(function() {
					if (this===frecce[0])
						me.tavola.scrolla(2,-1);
					else
						me.tavola.scrolla(2,1);
				})
			;
			testo.open($("div.testo"));
			$("div.viewall,div.browser",estro).click(function() {
				skipToFrame(10);
			});
			$("a.dettaglio,img.tavola",intro).click(function() {
				skipToFrame(11);
			});
			break;
		case 10:
			menuVoci.hide();
			controlli
				.fadeOut(1000);
			dati
				.hide();
			$("div.filetto.bottom")
				.animate({top: h_img_full},1000);
			browser.stop(true,true);
			browser.eq(me.tavola.corrente)
				.fadeOut(1000, function(){estro.hide();});
			$("a.dettaglio",intro)
				.show();
			intro
				.fadeIn(1000);
			$("div.payload").css( {height: intro.height()} );
			break;
		case 11:
			menuVoci.hide();
			$("div.filetto.bottom")
				.animate({top: h_filetto_bottom},1000, function() {dati.show()});
			browser.eq(me.tavola.corrente)
				.fadeIn(1000);
			frecce.fadeIn(1000);

			intro
				.fadeOut(1000);
			estro.show();
			controlli
				.fadeIn(1000);
			$("div.payload").css( {height: estro.height()} );
			break;
		}			
	};

	preloader.progress(function(a,b) {
		loadProgress.update(100*a/b);
	});
	preloader.load(function() {
		update();
	});
	loadProgress.d().show();
	preloader.run();

	return this;
};