/**
 * Slidetexts for jQuery
 *
 * v0.1
 *
 * Copyright (c) 2009 Total Support
 * By: Theo Nobel
 *
 */

/**
 * Configuration options:
 *
 * pauseSeconds  integer  number of seconds between each photo to be displayed
 * initHideAll   boolean, if we need to set initial values to hidden=true
 */

jQuery.fn.slidetexts = function(options){
	
	var defaults = {
			pauseSeconds: 2,
			initHideAll: true
	};	
	
	var options = $.extend(defaults, options);

	var target  = this;
	var items   = $(target).children();
	var first 	= $(target).children(':first');
	var last 	= $(target).children(':last');
	
	var hideAll = function(){
		$(items).hide();
	};
	
	
	$(target).show();
	
	
	var makeSlideText  = function(current){
		if(options.initHideAll===true){
			hideAll();
		}
		current.fadeIn(function(){
			//fadein
		}).animate({opacity: 1},options.pauseSeconds*1000, function(){
			
			if($(current).attr("id")  == $(last).attr("id")){
				makeSlideText($(first));
			}else{
				makeSlideText($(current).next());
			}
		}).fadeOut(function(){
			//fadeout	
		});		
	};
	makeSlideText(first);
	
};
