/*
wsd_cycle.js Version 1.1
Build date: 14-11-2011
Last update: 22-11-2011 (Version 1.1)
© Webspacedesign (www.webspacedesign.nl)
*/

(function($){ 
	$.fn.wsd_cycle = function(options) {
		
		var options = options || {};

		if(typeof(options.interval) == 'undefined') options.interval = 1000;
		if(typeof(options.duration) == 'undefined') options.duration = 1000;

		var wrapper = $(this[0]);

		// Set wrapper position
		if( $(wrapper).css('position') == 'static' ) $(wrapper).css('position','relative');

		// Set children position and hide all but first item
		$(wrapper).children().css('position','absolute').not(":first").hide();

		if($(wrapper).css('height') == '0px') $(wrapper).css('height',$(wrapper).children().css('height'));
		
		function fadeContent(current){
			var eqn = ( current == $(wrapper).children().length - 1 ) ? 0 : (current + 1);
			$(wrapper).children(":visible").delay(options.interval).fadeOut(options.duration);
			$(wrapper).children().eq(eqn).delay(options.interval).fadeIn(options.duration,function(){
				fadeContent($(this).index());
			});
		}
		
		// init
		fadeContent(0);
	};
})(jQuery);
