imgLoaded = {};
currentTime = new Date();

function doImageRotation(divId, imgCount, imgName)
{
	rotateImage(divId, nextRotationImg, imgName);	
	nextRotationImg = nextRotationImg == imgCount ? 1 : nextRotationImg+1;
	if(firstRotation != undefined)
	{
		window.clearInterval(firstRotation);
		firstRotation = undefined;
		imgRotation = window.setInterval("doImageRotation('slideWrapper', 10, 'images/seite%no%.jpg')", 6000);
	}
}

function rotateImage(divId, imgNo, imgName)
{
	var nextName = imgName.replace(/%no%/, imgNo);
	nextName += "?"+currentTime.getTime();
	
	if(imgLoaded[""+imgNo+""] !== true)
	{
		var img = new Image();
		$(img).attr('src', nextName).load(function() {
			addRotationImage(divId, nextName)
			imgLoaded[""+imgNo+""] = true;
		});
	}
	else
	{
		addRotationImage(divId, nextName)
	}
}

function addRotationImage(divId, imgName)
{
	$('#'+divId).height(1185).prepend("<div class='slide'><img src='"+imgName+"' height='591' width='327' alt=''></div>");
	$('#'+divId).animate({bottom: '-=594'}, 2000, 'easeInOutQuad', function() {
		$('#'+divId).height(591);
		$('#'+divId+' .slide:last').remove();
		$('#'+divId).css("bottom", 0);
	});
}

function doSlideshow(str_divId, imgCount, imgName)
{
	changeImage(str_divId, nextStartImg, imgName);	
	nextStartImg = nextStartImg == imgCount ? 1 : nextStartImg+1;
	
	if(firstSlide != undefined)
	{
		window.clearInterval(firstSlide);
		firstSlide = undefined;
		window.setInterval("doSlideshow('slideshow', 6, 'images/start%no%.jpg')", 6000);
	}
}

function changeImage(str_divId, imgNo, imgName)
{
	var nextName = imgName.replace(/%no%/, imgNo);
	nextName += "?"+currentTime.getTime();
	
	if(imgLoaded[""+imgNo+""] !== true)
	{
		var img = new Image();
		$(img).attr('src', nextName).load(function() {
			addImage(str_divId, nextName)
			imgLoaded[""+imgNo+""] = true;
		});
	}
	else
	{
		addImage(str_divId, nextName)
	}
}

function addImage(str_divId, imgName)
{
	$('#'+str_divId).prepend("<div class='slide'><img src='"+imgName+"' height='295' width='647' alt=''></div>");
	$('#'+str_divId+' .slide:last').fadeOut(1000, function() {
		$('#'+str_divId+' .slide').not('#'+str_divId+' .slide:first').remove();
	});
}
