// ============================================================»UTF8«
// Animation
// ==================================================================

// Image
var images = new Array();
images[0] = { source: '/img/bdsimex/animation/gruppe_01.gif' };
images[1] = { source: '/img/bdsimex/animation/gruppe_02.gif' };
images[2] = { source: '/img/bdsimex/animation/gruppe_03.gif' };
images[3] = { source: '/img/bdsimex/animation/gruppe_04.gif' };




// DOM ready
$(function () {

// Image-Loader	
$("ul#animation li").each(function(index,el){	
		var img = new Image();
		$(img).load(function () {
				$(this).css('display','none');
				$(el).append(this);
				$(this).fadeIn();
		}).error(function () {
			$(el).remove();
		}).attr('src', images[index]["source"]);		
		$(el).fadeOut(0);
	});	
	
	startAnimation();

});


var isRunning=false;
var currentElement=null;


function startAnimation() {
	isRunning=true;
	runAnimation();
}

function runAnimation() {
	if(isRunning) {
		var nextElement=currentElement ? currentElement.next() : null;
		if(!nextElement || nextElement.length==0) { nextElement=$("ul#animation li:first"); }	
		if(!nextElement) { isRunning=false; }	/* strange error */
				
		// Hide the current element
		if(currentElement) { currentElement.fadeOut("slow"); }
		
		// Show the new Element
		if(nextElement) { nextElement.fadeIn("slow").animate({opacity: 1.0}, 5000, runAnimation); }
		
		// Set the new currentElement
		currentElement = nextElement;
	}
}

function stopAnimation() {
	isRunning=false;	
}
