


jQuery.fn.goslide = function(custom){

	if($(this).length == 0)
		return;

	var params = {
		timeout: 5000
	}

	if(custom != undefined)
		for(var i in params)
			if(custom[i] != undefined)
				params[i] = custom[i];

	var actIndex = 0;

	// Recupero tutti gli item list
	var $master = $(this).find('ul');
	var $elements = $(this).find('li');

	$master.css({
		position: 'relative',
		overflow: 'hidden',
		width: $(this).width()+'px',
		height: $(this).height()+'px'
	});

	$elements.css({
		position: 'absolute',
		overflow: 'hidden',
		width: $(this).width()+'px',
		height: $(this).height()+'px'
	});

	$elements.each(function(index){

		if(index == 0)
			$(this).css({
				left: '0px',
				top: '0px',
				zIndex: 100
			})
		else
			$(this).css({
				left: $(this).width()+'px',
				zIndex: 1
			})

	});


	slide();


	function slide(){

		var prevIndex = actIndex;
		actIndex++;
		if(actIndex >= $elements.length)
			actIndex = 0;
	
		$($elements[prevIndex]).css({
			zIndex: 2,
			display: 'block'
		});

		$($elements[actIndex]).css({
			zIndex: 1,
			left: '0px',
			display: 'block'
		});

		$($elements[prevIndex]).wait(params.timeout).fadeOut('slow', function(){
			$($elements[prevIndex]).css({
				left: $(this).width()+'px'
			});
			slide();
		});
	}

	
};

(function($) {
    $.fn.wait = function(option, options) {
        milli = 1000;
        if (option && (typeof option == 'function' || isNaN(option)) ) {
            options = option;
        } else if (option) {
            milli = option;
        }
        // set defaults
        var defaults = {
            msec: milli,
            onEnd: options
        },
        settings = $.extend({},defaults, options);
        if(typeof settings.onEnd == 'function') {
            this.each(function() {
                setTimeout(settings.onEnd, settings.msec);
            });
            return this;
        } else {
            return this.queue('fx',
            function() {
                var self = this;
                setTimeout(function() { $.dequeue(self); },settings.msec);
            });
        }

    }
})(jQuery);



