function home_performTransition(finalImg, preImg) {
	if (!finalImg.complete) {
		// Wait, image is not fully loaded
		setTimeout(function(){home_performTransition(finalImg, preImg)}, 2000);
		return;
	}
	else {
		// Ready! Perform transition
		new Effect.Appear(finalImg, { duration: 2.5, from: 0.0, to: 1.0});
		new Effect.Appear(preImg, { duration: 2.5, from: 1.0, to: 0.0});
		$$('#imgPanel p')[0].show();
	}
}

document.observe("dom:loaded", function() {
	// Preparar imagen
	var finalImg = $('finalImg');
	finalImg.hide();
	$$('#imgPanel p')[0].hide();

	var preImg = $('preImg');
	new Effect.Appear(preImg, { duration: 1.5, from: 0.0, to: 1.0});

	setTimeout(function(){home_performTransition(finalImg, preImg)}, 2000);


	// Preparar notícies
	$('newsPanel').addClassName("js-enabled");
	var cnt = 0;
	$$('#newsPanel li').each(function(li){
        li.writeAttribute('id', 'news_' + cnt);
		if (cnt > 0) li.hide();
		cnt++;
    });
	// cnt holds the number of news items

	if (cnt > 1) { // Més d'una notícia
		// Rotar notícies
		var INTERVAL = 5000; // in ms
		var currItem = 0;
		var nextItem = 1;
		setInterval(
			function() {
				Effect.Fade(
					'news_' + currItem,
					{
						duration:.5,
						from:1.0,
						to:0.0,
						afterFinish:function(){
							$('news_' + currItem).hide();
							Effect.Appear('news_' + nextItem, {duration:.5, from:0.0, to:1.0});
							currItem = nextItem;
							nextItem = (currItem == (cnt - 1)) ? 0 : nextItem + 1;
						}
					}
				);
			},
			INTERVAL
		);
	}
});