var nextStartimage = 0;
var currentStartimage = 0;
var startimageHeight = '150px';
var startimageContentElementId = 'ce436';
var startimageStaticContentElementId = 'ce442';

// set a fix image
function setFixStartimage(imageNumber){
	if($(startimageStaticContentElementId) && $(startimageContentElementId)){
		var staticImage = $(startimageStaticContentElementId).getElementsByTagName('img');
		staticImage[0].style.position = 'absolute';
		staticImage[0].style.left = 0;
		staticImage[0].style.top = 0
		staticImage[0].src = $('startImageAnimation' + imageNumber).src;
		$(startimageContentElementId).style.display = 'none';
		$(startimageStaticContentElementId).style.display = 'block';
	}
}

// starts over the rotation
function continueStartimageRotation(){
	if($(startimageStaticContentElementId) && $(startimageContentElementId)){
		$(startimageStaticContentElementId).style.display = 'none';
		$(startimageContentElementId).style.display = 'block';
	}
}

// after effects are done rotation is startet again
function callbackRotationEffect(effect){
	startRotationEffect();
}

// rotation function, here happens everthing
function startRotationEffect(){
	// hide current image
	$('startImageAnimation' + currentStartimage).style.display = 'none';
	
	// startimage array
	ctElement = $(startimageContentElementId);
	var startimages = ctElement.getElementsByTagName('img');
	
	// start with image 0 after the last image
	if(nextStartimage == startimages.length){
		nextStartimage = 0;
	}
	
	// rotate
	new Effect.Appear('startImageAnimation' + nextStartimage, {duration: 2, from: 0.01, to:  1});
	new Effect.Fade('startImageAnimation' + nextStartimage, {queue:'end', from: 1, to: 0.01, delay:10, duration: 2, afterFinish: callbackRotationEffect});
	
	// set the counters
	currentStartimage = nextStartimage;
	nextStartimage++;
}

// numbers all images, and starts the rotation
startImageAnimation = function() {
	if($(startimageStaticContentElementId) && $(startimageContentElementId)){
		$(startimageStaticContentElementId).style.display = 'none';
		$(startimageStaticContentElementId).style.height = startimageHeight;
		$(startimageStaticContentElementId).style.overflow = 'hidden';
		$(startimageStaticContentElementId).style.position = 'relative';
		
		ctElement = $(startimageContentElementId);
		ctElement.style.height = startimageHeight;
		ctElement.style.overflow = 'hidden'
		ctElement.style.position = 'relative';
		var startimages = ctElement.getElementsByTagName('img');
		for (var i=0; i<startimages.length; i++) {
			startimages[i].style.display = 'none';
			startimages[i].style.position = 'absolute';
			startimages[i].style.left = 0;
			startimages[i].style.top = 0;
			startimages[i].id = 'startImageAnimation' + i;
		}
		
		startRotationEffect();
	}
}

if (window.attachEvent) {
	window.attachEvent("onload", startImageAnimation);
} else {
	window.addEventListener("load", startImageAnimation, false);
}

