/**
 * Carousel - loop elements using fading effect
 *
 * Usage example:
 * <div id="carousel">
 *   <img ... /> <img ... /> <img ... /> ...
 * </div>
 *
 * <script type="text/javascript">
 * document.ready(function() {
 *   new Carousel($('#carousel'), 5000, 'slow');
 * });
 * </script>
 */
var Carousel = function(parent, interval, speed) {
	var _this = this;
	var elements = parent.get(0).getElementsByTagName('*');
	
	this.next = function() {
		window.setTimeout(function() { _this.fx() }, interval);
	}
	
	this.fx = function() {
		this.current = $(elements[elements.length - 1]);
		this.current.fadeOut(speed, function() {
			_this.current.insertBefore(elements[0]);
			_this.current.show();
			_this.next();
		});
	}
	
	this.next();
}


