var backImgsNames = new Array('splash_01.jpg','splash_02.jpg','splash_03.jpg','splash_04.jpg','splash_05.jpg','splash_06.jpg');
var backImgsIndex = 0;
var backImgs = new Array();

// preload immagini

for (var i=0; i<backImgsNames.length; i++) {
	backImgs[i] = new Image();
	backImgs[i].src = baseURL+'images/'+backImgsNames[i];
}

var animatedCubo = false;

/**
* Mostra l'animazione del cubo
*/
function animCubo (qId,fromTop,toTop) {
	if (document.getElementById(qId)!=null) {
//		var myTransition = new Fx.Transition(Fx.Transitions.Elastic, 1);
		var makeItSbleong = new Fx.Style(qId,'top',{
			wait:false,
			duration:500,
			transition: Fx.Transitions.linear});
		makeItSbleong.start(toTop);
	}
}

function animCuboOut (qId,fromTop,toTop) {
	animCubo (qId,fromTop,toTop);
//	document.getElementById(qId).style.top = toTop+"px";
}


function showHideBackImg (fromAlpha, toAlpha) {
	var makeItShowHide = new Fx.Style('BackImg','opacity',{
		duration:1000,
		transition: Fx.Transitions.Quad.easeIn});
	makeItShowHide.start(fromAlpha,toAlpha);
}

function showBackImg () {
	document.getElementById('BackImg').src = backImgs[Math.round((backImgs.length-1)*Math.random())].src;
	showHideBackImg(0,1);
	setTimeout("hideBackImg()",5000);
}

function hideBackImg () {
	showHideBackImg(1,0);
	setTimeout("showBackImg()",5000);
}

//window.onload = showBackImg;
window.addEvent('load', showBackImg);
window.addEvent('load', initCubi);

function initCubi () {
	var fxTopSx = new Fx.Style('cuboTopSx','top',{ wait:false, duration:1000, transition: Fx.Transitions.Elastic.easeOut});
	$('LnkCuboTopSx').addEvent('mouseenter', function(e) { if ($('cuboTopSx')!=null) fxTopSx.start(36,36-50); });
	$('LnkCuboTopSx').addEvent('mouseleave', function(e) { if ($('cuboTopSx')!=null) fxTopSx.start(36); });

	var fxTopTop = new Fx.Style('cuboTopTop','top',{ wait:false, duration:1000, transition: Fx.Transitions.Elastic.easeOut});
	$('LnkCuboTopTop').addEvent('mouseenter', function(e) { if ($('cuboTopTop')!=null)  fxTopTop.start(0,0-50); });
	$('LnkCuboTopTop').addEvent('mouseleave', function(e) { if ($('cuboTopTop')!=null)  fxTopTop.start(0); });

	var fxTopDx = new Fx.Style('cuboTopDx','top',{ wait:false, duration:1000, transition: Fx.Transitions.Elastic.easeOut});
	$('LnkCuboTopDx').addEvent('mouseenter', function(e) { if ($('cuboTopDx')!=null)  fxTopDx.start(24,24-50); });
	$('LnkCuboTopDx').addEvent('mouseleave', function(e) { if ($('cuboTopDx')!=null)  fxTopDx.start(24); });

	var fxTopBottom = new Fx.Style('cuboTopBottom','top',{ wait:false, duration:1000, transition: Fx.Transitions.Elastic.easeOut});
	$('LnkCuboTopBottom').addEvent('mouseenter', function(e) { if ($('cuboTopBottom')!=null)  fxTopBottom.start(60,60-50); });
	$('LnkCuboTopBottom').addEvent('mouseleave', function(e) { if ($('cuboTopBottom')!=null)  fxTopBottom.start(60); });

	var fxBotSx = new Fx.Style('cuboBottomSx','top',{ wait:false, duration:1000, transition: Fx.Transitions.Elastic.easeOut});
	$('LnkCuboBotSx').addEvent('mouseenter', function(e) { if ($('cuboBottomSx')!=null)  fxBotSx.start(104,104+50); });
	$('LnkCuboBotSx').addEvent('mouseleave', function(e) { if ($('cuboBottomSx')!=null)  fxBotSx.start(104); });

	var fxBotTop = new Fx.Style('cuboBottomTop','top',{ wait:false, duration:1000, transition: Fx.Transitions.Elastic.easeOut});
	$('LnkCuboBotTop').addEvent('mouseenter', function(e) { if ($('cuboBottomTop')!=null)  fxBotTop.start(67,67+50); });
	$('LnkCuboBotTop').addEvent('mouseleave', function(e) { if ($('cuboBottomTop')!=null)  fxBotTop.start(67); });

	var fxBotDx = new Fx.Style('cuboBottomDx','top',{ wait:false, duration:1000, transition: Fx.Transitions.Elastic.easeOut});
	$('LnkCuboBotDx').addEvent('mouseenter', function(e) { if ($('cuboBottomDx')!=null)  fxBotDx.start(92,92+50); });
	$('LnkCuboBotDx').addEvent('mouseleave', function(e) { if ($('cuboBottomDx')!=null)  fxBotDx.start(92); });

	var fxBotBottom = new Fx.Style('cuboBottomBottom','top',{ wait:false, duration:1000, transition: Fx.Transitions.Elastic.easeOut});
	$('LnkCuboBotBot').addEvent('mouseenter', function(e) { if ($('cuboBottomBottom')!=null)  fxBotBottom.start(130,130+50); });
	$('LnkCuboBotBot').addEvent('mouseleave', function(e) { if ($('cuboBottomBottom')!=null)  fxBotBottom.start(130); });


	if (document.getElementById('SendCommentForm')!=null) {

		$('SendCommentForm').addEvent('submit', function(e) {
			// Prevent the submit event
			new Event(e).stop();

			$('submitComment').disabled=true;
			if ($('ll').value == 'ita:it') {
				$('submitComment').value = 'Attendere prego...';
			} else {
				$('submitComment').value = 'Please wait...';
			}

			/**
			* send takes care of encoding and returns the Ajax instance.
			* onComplete removes the spinner from the log.
			*/
			this.send({
				update: $('log_res'),
				onComplete: function() {
					showComments ();
				}
			});
		});

	}

}

function showComments () {
	document.getElementById('CommentContent').style.display = 'block';
	document.getElementById('CommentAdd').style.display = 'none';
	document.getElementById('AddCommentButton').style.display = 'inline';
}

function showAddComments () {
	document.getElementById('CommentContent').style.display = 'none';
	document.getElementById('CommentAdd').style.display = 'block';
	document.getElementById('AddCommentButton').style.display = 'none';
}
