<html>
<head>
<script type="text/javascript" src="/bundle/swfobject.js"></script>
<style>
body {
	margin: 0px;
	padding: 0px;
	background: #AAAAAA;
}

#container {
	position: absolute;
	top: 0px;
	left: 0px;
	width: 100%;
	height: 100%;
	overflow: hidden;
}

#place1 {
	position: absolute;
	top: 0px;
	left: 0px;
	width: 100%;
	height: 100%;
	/*height: auto;*/
	margin: 0px;
	padding: 0px;
	z-index: 2;
	visibility: hidden;
}

#place2 {
	position: absolute;
	top: 0px;
	left: 0px;
	width: 100%;
	height: 100%;
	/*height: auto;*/
	margin: 0px;
	padding: 0px;
	z-index: 1;
	visibility: hidden;
}

#hidden_music {
	z-index: 0;
	/*visibility: hidden;*/
}

</style>
</head>
<body>

<div id="container">
	<img src="" id="place1" />
	<img src="" id="place2" />
</div>

<div id="hidden_music"></div>

<script type="text/javascript">

var background_music = "[background_music]";
if (background_music.length > 0) {
	var swf = new SWFObject("/bundle/MusicPlayer.swf", "line", "50", "50", "7");
	swf.addVariable("play_track", background_music);
	swf.write("hidden_music");
}

</script>

<script language="javascript">

var gImages = new Array([image_list]);

var kDelayMilliseconds = [rotate_seconds] * 1000;
var kLoadMilliseconds = 2000;
var kStepsPerFade = 10.0;
var kStepMilleseconds = 100;

var gCurrentFadeProgress = 0; // 0..10
var gCurrentFadeElement = null;
var gCurrentImageIndex = 1; // img 2 is already setup
var gCurrentImageCounter = 1;
var gFlipDelayTimer = null;

document.onkeypress = function (e) {
	setupDefaults();
	
	if ((e.keyCode == 175) || (e.keyCode == 63232)) {
		// up
		return false;
	}
	else if ((e.keyCode == 176) || (e.keyCode == 63233)) {
		// down
		return false;
	}
	else if ((e.keyCode == 177) || (e.keyCode == 63235)) {
		// right
		return false;
	}
	else if (e.keyCode == 13) {
		// click
		if (gFlipDelayTimer != null) {
			clearTimeout (gFlipDelayTimer);
			gFlipDelayTimer = null;
		}
		finishFlip();
		return false;
	}
	else if ((e.keyCode == 178) || (e.keyCode == 63234)) {
		// left
		return false;
	}
	else {
		return true;
	}
}

function startFade(inElement)
{
	gCurrentFadeProgress = kStepsPerFade;
	gCurrentFadeElement = inElement;
	setTimeout('nextFade();', kStepMilleseconds);
}

function nextFade()
{
	if (gCurrentFadeProgress > 0) {
		gCurrentFadeProgress--;
		gCurrentFadeElement.style.opacity = gCurrentFadeProgress/kStepsPerFade;
		setTimeout('nextFade();', kStepMilleseconds);
	}
	else {
		finishedFade();
	}
}

function finishedFade()
{
	if (gCurrentImageIndex < (gImages.length - 1)) {
		gCurrentImageIndex = gCurrentImageIndex + 1;
	}
	else {
		gCurrentImageIndex = 0;
	}

	gCurrentImageCounter = gCurrentImageCounter + 1;

	setTimeout('setupNextImage();', kStepMilleseconds);
	gFlipDelayTimer = setTimeout('finishFlip();', kDelayMilliseconds);
}

function setupNextImage()
{
	if ((gCurrentImageCounter % 2) == 0) {
		e1 = document.getElementById('place1');
		e2 = document.getElementById('place2');
	}
	else {
		e1 = document.getElementById('place2');
		e2 = document.getElementById('place1');
	}
		
	e2.style.zIndex = 2;
	
	e1.style.zIndex = 1;
	changeImage(e1, gImages[gCurrentImageIndex]);
	e1.style.opacity = 1;
	e1.style.visibility = 'visible';
}

function finishFlip()
{
	if ((gCurrentImageCounter % 2) == 0) {
		e1 = document.getElementById('place1');
		e2 = document.getElementById('place2');
	}
	else {
		e1 = document.getElementById('place2');
		e2 = document.getElementById('place1');
	}

	startFade(e2);
}

function hitFirstSlide()
{
	e1 = document.getElementById('place1');
	startFade(e1);
}

function finishLoading()
{
	e1 = document.getElementById('place1');
	e2 = document.getElementById('place2');
	e1.style.visibility = 'visible';
	e2.style.visibility = 'visible';
	setTimeout('hitFirstSlide();', kDelayMilliseconds);
}

function changeImage(inElement, inImageURL)
{
	inElement.src = gImages[gCurrentImageIndex];
	//inElement.style.backgroundImage = "url('" + inImageURL + "')";
}

e1 = document.getElementById('place1');
e2 = document.getElementById('place2');
changeImage(e1, gImages[0]);
changeImage(e2, gImages[1]);
setTimeout('finishLoading();', kLoadMilliseconds);

</script>

</body>
</html>