/* =========================================================

// jquery.innerfade.js

// Datum: 2007-01-29
// Firma: Medienfreunde Hofmann & Baldes GbR
// Autor: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com

// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/

// ========================================================= */


(function($) {

$.fn.innerfade = function(options) {

	this.each(function(){ 	
		
		var settings = {
			animationtype: 'fade',
			speed: 'normal',
			timeout: 2000,
			type: 'sequence',
			containerheight: 'auto',
			runningclass: 'innerfade'
		};
		
		if(options)
			$.extend(settings, options);
		
		var elements = $(this).children();
	
		$(this).css('position', 'relative');

		$(this).css('height', settings.containerheight);
		$(this).addClass(settings.runningclass);
		
		var largo = elements.length;
		for ( var i = 0; i < largo; i++ ) {
			$(elements[i]).css('z-index', String(largo-i)).css('position', 'absolute');
			$(elements[i]).hide();
		};
	
		setTimeout(function(){
			$.innerfade.next(elements, settings, 1, 0);
		}, settings.timeout);
		$(elements[0]).show();
			
		
	});
};


$.innerfade = function() {}
$.innerfade.next = function (elements, settings, current, last) {

	
	$(elements[last]).fadeOut(settings.speed);
	$(elements[current]).fadeIn(settings.speed);
	
	
	if ( ( current + 1 ) < elements.length ) {
		current = current + 1;
		last = current - 1;
	} else {
		current = 0;
		last = elements.length - 1;
	};
		
	setTimeout((function(){$.innerfade.next(elements, settings, current, last);}), settings.timeout);
};
})(jQuery);

