// jquery.slider.js
// 2010-05-28, www.deitron.de

(function($) {

    $.fn.slider = function() {

        return this.each(function() {   

            $.slider(this);
        });
    };

    $.slider = function(container) {

		//var elements = $(container).children().sort(function() { return 0.5 - Math.random(); });
		var elements = $(container).children();
		var length   = elements.length;
		var width    = $(container).css('width');
		var i        = 0;

		$.slider.init = function() {
			
			//elements.css({ left: width });
			elements.css({ display: 'none' });
			
			//elements.eq(i).css({ left: '0' });
			elements.eq(i).css({ display: 'block' });
			
			//setTimeout(function() { $.slider.next(); }, 5000, null);		
		};

		$.slider.prev = function() {

			var current = elements.eq(i);
			var prev    = elements.eq(i = (i == 0) ? length - 1 : i - 1);

			current.hide();
			prev.show();
	
			/*
			current.animate({ left: width }, 1000, function() {

				current.css({ left: '-' + width });
			});
			
			prev.animate({ left: '0' }, 1000, function() {
			
				setTimeout(function() { $.slider.prev(); }, 5000, null);					
			});
			*/			
		};
		
		$.slider.next = function() {

			var current = elements.eq(i);
			var next    = elements.eq(i = (i == length - 1) ? 0 : i + 1);

			current.hide();
			next.show();

			/*
			current.animate({ left: '-' + width }, 1000, function() {

				current.css({ left: width });
			});
			
			next.animate({ left: '0' }, 1000, function() {
			
				setTimeout(function() { $.slider.next(); }, 5000, null);					
			});	
			*/		
		};
		
		if (length > 0) {
			
			$.slider.init();
		}
	};

})(jQuery);
