/**
 * SITECHIPS 4
 * (c) qbus | websolutions (http://www.qbus-websolutions.de)
 *
 * @category   	Sitechips
 * @package		JavaScript
 * @subpackage	Module
 * @version    	v1
 * @license		http://www.opensource.org/licenses/mit-license.php
 */


/**
 * @param Object settings // setttings for slideshow
 * @example $('.classname').slideshow({transitionSpeed: 2000, displayDurration: 7000})
 */
(function($){
    $.fn.slideshow = function(settings){
        var s = {
			items: 'img',				// item list to slide
			transitionSpeed: 2000,		// fade time in ms
			displayDurration: 7000		// display item time in ms
		};
        if (settings) $.extend(s, settings);
		
		var element = $(this);
		list = $(this).find(s.items);
		
		$(list).eq(0).show();
		
		if ($(list).length > 1) {
			window.setTimeout('qbSildeshowNext(' + s.transitionSpeed + ',' + s.displayDurration + ')', s.displayDurration);
		};
		
        return this;
    };
})(jQuery);

var list = new Object();

/**
 * Helper Funtion for display Next Slide Items
 * @param Integer transitionSpeed
 * @param Integer displayDurration
 * 
 * @todo mla - This function has to be integrate into the plugin.
 */
var qbSildeshowNext = function (transitionSpeed, displayDurration){
	var c = '';
	$(list).each(function(i,e){
		if($(e).is(':visible'))	{
			c = $(e);
		};
	});
	
	if(c == '')	{
		$(list).fadeOut(transitionSpeed);
		$(list).eq(0).fadeIn(transitionSpeed);
	} else {
		$(c).fadeOut(transitionSpeed);
		
		if ($(c).next().is(':hidden') == true) {
			$(c).next().fadeIn(transitionSpeed);
		} else {
			$(list).eq(0).fadeIn(transitionSpeed);
		};
	};
	
	window.setTimeout('qbSildeshowNext('+transitionSpeed+','+displayDurration+')', displayDurration);
};
