function homeInit() {
	actualImageIndexNr = 0;
	resizeScreen();
	new Effect.Appear('promotionImage', { duration: 1.5 } );
	initAutoChange();
}

function initAutoChange() {		
	setTimeout("autoChange()",6000);
}	

function autoChange() {
	if (promotionImageList.length > 1) {
		++actualImageIndexNr;
		if (actualImageIndexNr > promotionImageList.length - 1) {
			actualImageIndexNr = 0;
		}
		changePromotionImage(actualImageIndexNr);
		initAutoChange();
	}
}

function resizeScreen() {
	homeImgResize('promotionImage');
}

function homeImgResize(id) {
	$(id).setStyle({ width: 'auto', height: 'auto' });
	var dimensions = $(id).getDimensions();
	windowHeigth = window.innerHeight;
	windowWidth = window.innerWidth;
	var ratio = dimensions.width / dimensions.height;
	
	imgWidth = windowWidth;
	imgHeight = Math.round(imgWidth / ratio);
	if (imgHeight < windowHeigth) {	
		imgHeight = windowHeigth;
		imgWidth = Math.round(ratio * imgHeight);
		offsetHeight = 0;
		offsetWidth = (windowWidth -imgWidth) / 2;
	} else {
		offsetHeight = (windowHeigth -imgHeight) / 2;
		offsetWidth = 0;
	}
	$(id).setStyle({
			width: imgWidth+'px',
			height: imgHeight+'px',
		top: offsetHeight+'px',
		left: offsetWidth+'px'
	});
}

function changePromotionImage(imageIndexNr) {
	new Effect.Fade('promotionImage', { duration: 1, afterFinish: function()
		{
			$('promotionImage').src = promotionImageList[imageIndexNr];
			homeImgResize('promotionImage');
			new Effect.Appear('promotionImage', { duration: 1 } );
		}} );
}



