function Slide(imgPath) {
	this.imgObj = new Image();
	this.imgObj.onload = this.didLoad.bind(this);
	this.imgObj.src = imgPath;
}
Slide.prototype = {
	imgObj: null,
	loaded: false,
	didLoad: function() {
		document.getElementById("messages").innerHTML += "Loaded: " + this.imgObj.src + "<br/>";
		this.loaded = true;
	}
};


function ObjectSlider(container, objectGenerator) {
	this.container = container;
	this.generator = objectGenerator;
}
ObjectSlider.prototype = {
	currentObject: -1,
	nextObject: -1,
	objects: [],
	slideWillChange: null,
	
	initObjects: function(setCurrent) {
		this.currentObject = setCurrent;
		this.nextObject = this.currentObject + 1;
		if (this.nextObject >= this.objects.length) {
			this.nextObject = 0;
		}
		
		var current = this.generator(this.objects[this.currentObject]);
		$('fotoframe').appendChild(current);
		if (this.slideWillChange) {
			this.slideWillChange(this.objects[this.currentObject]);
		}
		
		if (this.objects.length > 1) {
			var next = this.generator(this.objects[this.nextObject]);
			Element.addClassName(next, "next");
			$('fotoframe').appendChild(next);
		}
	},
	addObjects: function(newObjects, setCurrent) {
		for (i=0; i<newObjects.length; i++) {
			this.objects[this.objects.length] = newObjects[i];
		}
		
		if (this.currentObject < 0) {
			this.initObjects((!setCurrent) ? 0 : setCurrent);
		}
	},
	nextObject: function(e) {
		var slides = $$("#fotoframe .slide");
		var current = slides[slides.length - 2];
		var next = slides[slides.length - 1];
		
		var anim = new Animator({
			onComplete: function() {
				current.parentNode.removeChild(current);
			}
		});
		anim.addSubject(
			new CSSStyleSubject(current, "left: -640px")
		);
		anim.addSubject(
			new CSSStyleSubject(next, "left: 0")
		);
		anim.play();
		
		this.currentObject = this.nextObject;
		document.location = '#' + this.currentObject;
		this.nextObject = (this.nextObject + 1 >= this.objects.length) ? 0 : (this.nextObject + 1);
		
		if (this.slideWillChange) {
			this.slideWillChange(this.objects[this.currentObject]);
		}
		
		var newNext = this.generator(this.objects[this.nextObject]);
		Element.addClassName(newNext, "next");
		$('fotoframe').appendChild(newNext);
		
		e.preventDefault();
		
		return false;
	}
};

/* Remember:
http://entreprexplorer.blogspot.com/2005/09/technical-post-ie6-show-picture-bug.html
*/