/**
 * RA Schnitzer Website
 *
 * @author    Tom Klingenberg
 * @copyright copyright (c) 2008 lastflood GmbH Mainz
 */


fader = function()
{
	this.elements = '.header .fader .image';

	this.count   = 0;

	this.current = 0;

	this.fadeNext = function()
	{
		if (2 > this.count)
		{
			return;
		}

		// speed config
		var speed = 3000;
		var wait  = speed * 3;

		if (0 == this.current)
		{
			this.current = 1;
			window.setTimeout('headerFader.fadeNext();', wait);
			return;
		}

		// vars
		var curr  = this.current;
		var next  = (curr < this.count) ? curr + 1 : 1;

		var imgCurr = $(this.elements).eq(curr - 1);
		var imgNext = $(this.elements).eq(next - 1);

		// zorder
		imgCurr.css('z-index', '101');
		imgNext.css('z-index', '100');
		
		// fade out and in
		imgCurr.fadeOut(speed);
		imgNext.fadeIn(speed);

		// update current counter
		this.current = (this.current < this.count) ? this.current + 1 : 1;
	

		// set next fade
		window.setTimeout('headerFader.fadeNext();', speed + wait);

	}

	this.init = function()
	{
		this.count   = $(this.elements).length;

		$(this.elements).each(function (i) {
			var element = $(this);
			if (element.hasClass('init')) {				
				element.removeClass('init');
				element.hide();
			}
		});
		this.fadeNext();						
	}

	this.init();
}

var headerFader = true;

$(document).ready(function(){
	headerFader = new fader();	
	$('.scroll').jScrollPane();
});