function SlideShow(container, delay, tweenDuration, onChangeFunction, stopit) {
		
		this.list = container;
		this.delay = delay;
		this.tweenDuration = tweenDuration;
		this.children = container.getElements(this.list.getFirst().tagName);
		this.currentIndex = 0;
		this.children.setStyle("opacity", 0);
		this.count = this.children.length;
		this.position = this.currentIndex+1;
		this.ended = 0;

		
		this.play = function() {
			this.children[0].setStyle("opacity", 1);
			this.next.periodical(this.delay, this)
			this.onChange();
			}
		
		this.next = function () {
		    if (!stopit || this.currentIndex+1 <= this.children.length) {
		    	//alert("index:"+(this.currentIndex+1)+"Length:"+this.children.length);
				this.fadeOut();
				this.fadeIn();
				}
			}
		
		this.fadeIn = function () {
			if (!this.ended) {
				if (!stopit) this.currentIndex = this.currentIndex+1 == this.children.length ? 0 : ++this.currentIndex;
				else this.currentIndex = this.currentIndex+1;
				this.position = this.currentIndex + 1;
				new Fx.Morph(this.children[this.currentIndex], {duration : this.tweenDuration, wait : false }).start({"opacity": 1});
				this.onChange.bind(this).run();
				}
			}
			
		this.fadeOut = function () {
			if (!stopit || this.currentIndex+1 < this.children.length) new Fx.Morph(this.children[this.currentIndex], {duration : this.tweenDuration, wait : false }).start({"opacity": 0});
			else this.ended = 1;
			}
		
		this.getCount = function () {
			return this.count;
			}
		this.getPosition = function () {
			return this.position;
			}
		this.getItem = function () {
			return this.children[this.currentIndex];
			
			}
		this.onChange = function () {
			onChangeFunction.bind(this).run();
			}
		}
	
	window.addEvent("domready", function () {
		slideShow = new SlideShow ($("slide"), 2000, 1000, updateSlideIndicator, 1);
		slideShow.play();
		});
	function updateSlideIndicator() {
		var img = this.getItem().getElement("img");
		// var captionStr = img.get("alt") == null ? img.get("title") == null ? img.get("src").split("/").getLast() : img.get("title") : img.get("alt")
		//$("currentPosition").set("text", this.getPosition());
		//$("totalCount").set("text", this.getCount());
		//$("caption").set("text", captionStr);
		}
		
