var nextStartimage = 0;
var currentStartimage = 0;
var startimageHeight = '262px';
var startimageContentElementId = 'ce424';
var startimageStaticContentElementId = 'ce425';

// 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
	ctElement.style.height = $('startImageAnimation' + nextStartimage).height + 10;
	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:1, duration: 1, afterFinish: callbackRotationEffect});
	
	// set the counters
	currentStartimage = nextStartimage;
	nextStartimage++;
}

// numbers all images, and starts the rotation
startImageAnimation = function() {
	//startimageContentElementId
	//startimageStaticContentElementId
	
	if(!$(startimageStaticContentElementId) || !$(startimageContentElementId)){
		midColDivs = $('rbugfix').getElementsByTagName("div");
		for(var i=0; i<midColDivs.length; i++){
			if(midColDivs[i].className == 'sectionFrame1' || midColDivs[i].className == 'sectionFrame2'){
				divs = midColDivs[i].getElementsByTagName("div");
				if($(startimageContentElementId)){
					startimageStaticContentElementId = divs[0].id;
				} else {
					startimageContentElementId = divs[0].id;
				}
			}
		}
	}
	
	if($(startimageStaticContentElementId) && $(startimageContentElementId)){
		$(startimageStaticContentElementId).style.display = 'none';
		$(startimageStaticContentElementId).style.height = startimageHeight;
		$(startimageStaticContentElementId).style.overflow = 'hidden';
		$(startimageStaticContentElementId).style.position = 'relative';
		
		ctElement = $(startimageContentElementId);
		ctElement.style.overflow = 'hidden';
		ctElement.style.display = 'block';
		ctElement.style.position = 'relative';
		ctElement.style.height = startimageHeight;
		var startimages = ctElement.getElementsByTagName('img');
		for (var i=0; i<startimages.length; i++) {
			startimages[i].style.display = 'none';
			startimages[i].id = 'startImageAnimation' + i;
		}
		
		startRotationEffect();
	}
}

if (window.attachEvent) {
	window.attachEvent("onload", startImageAnimation);
} else {
	window.addEventListener("load", startImageAnimation, false);
}


