jQuery(document).ready(function() {
	elemA = jQuery('#headerImageSecuence_A');
	elemB = jQuery('#headerImageSecuence_B');
	elemC = jQuery('#headerImageSecuence_C');
	gwbb_options.basePath = elemA.attr('src').replace(/\(0\)/, "()");
	
	//preload
	for(var i = gwbb_options.lastImagePointer; i<gwbb_options.imageCount; i++) {
		jQuery(new Image()).load().attr('src',gwbb_getImagePath(i));
	}
	
	setTimeout('gwbb_doSlideshow(elemA,elemB,elemC)',gwbb_options.timeToNextSlide-1000);
})

var gwbb_options = {
		data: new Array(),
		basePath : '',
		timeoutid: null,
		stop: false,//a stop signal - for faster switching between slideshow and click-event
		lastImagePointer: 2,
		imageCount: 17,
		timeToNextSlide: 10000,
		timeoutDuration: 100,
		fadingDuration: 500,//slideshow-fadeIn
	};

function gwbb_doSlideshow(elemA,elemB,elemC) {
	lastImage = gwbb_options.lastImagePointer;
	gwbb_options.lastImagePointer = (lastImage+3)%gwbb_options.imageCount;
	
	imageA = gwbb_getImagePath( (lastImage+1)%gwbb_options.imageCount );
	imageB = gwbb_getImagePath( (lastImage+2)%gwbb_options.imageCount );
	imageC = gwbb_getImagePath( (lastImage+3)%gwbb_options.imageCount );
	
	window.setTimeout('gwbb_changeImage(elemA,imageA)',0);
	window.setTimeout('gwbb_changeImage(elemB,imageB)',150);
	window.setTimeout('gwbb_changeImage(elemC,imageC)',300);
	window.setTimeout('gwbb_doSlideshow(elemA,elemB,elemC)',gwbb_options.timeToNextSlide);
}

function gwbb_getImagePath(nr) {
	return gwbb_options.basePath.replace(/\(\)/, '('+Number(nr)+')');
}

function gwbb_changeImage(domobj,changeTo) {
	domobj.fadeTo(gwbb_options.fadingDuration,0.01, function() {
		domobj.attr('src',changeTo);
		//jQuery('#welcome_message').html(jQuery('#welcome_message').html()+'<br />'+changeTo);
		domobj.fadeTo(gwbb_options.timeoutDuration,0.02,function() {
			domobj.fadeTo(gwbb_options.fadingDuration,1);
		});
	});
}
