//jQuery(document).ready(function() {

/*
jQuery.noConflict();
alert(jQuery('.abrechnung201102start').length);
*/

pgStartAnimation = function(do_delay) {
	var $imgs = $('.abrechnung201102start img');
	if ($imgs.length < 2) return;
	if (do_delay) {
		window.setTimeout(function() {
			pgStartAnimation(false);
		},2000);
		return;
	}
	
	var $oldAct = $('.abrechnung201102start img.active').removeClass('active');
	var $nextAct = $oldAct.next();
	
	if (!$nextAct.length) {
		$nextAct = $imgs.first();
	}
	
	$nextAct.addClass('active');
	
	
	
	$oldAct.fadeOut(600);
	$nextAct.fadeIn(600);
	
	
	var iv = window.setInterval(function() {
		if (!$nextAct.queue('fx').length && !$nextAct.queue('fx').length) {
			window.clearInterval(iv);
			pgStartAnimation(true);
		}
	},100);
	
	
};

pgInitAnimation = function() {
	var $img = $('.abrechnung201102start img');
	if (!$img.length) return;

	var imgList = $img.attr('data').split('~');
	
	var newCSS = { position: 'absolute'};
	$img.attr('src',imgList.shift()).css(newCSS).addClass('active');
	
	newCSS.visibility = 'hidden';
	
	while (imgList.length) {
		var $newImg = $img.clone();
		$newImg.attr('src',imgList.shift())
			.css(newCSS)
			.insertAfter($img);
		$img = $newImg;
	}
	
	$('.abrechnung201102start img').hide().first().show();
	$('.abrechnung201102start img').css('visibility','visible');
	
	window.setTimeout(function() {
		pgStartAnimation(true);
	},3000);
	
};


//window.onload = function() {
$(document).ready(function() {
	pgInitAnimation();
});

