var slideshow = $.Class.create({

	node: null,
	store: null,
	index: null,
	total: 0,
	wait: 3000,
	time: 1500,

	initialize: function( node ) {

		this.node = node;
		this.total = this.node.children('img').length;
		this.store = this.node.children('img');

		$(this.store[this.getIndex()]).show();

	},

	start: function () {

		var mthis = this;

		setTimeout(function(){mthis.change()},this.wait);

	},

	change: function () {

		var mthis = this;
		var imgold = $(this.store[this.index]);
		var img = $(this.store[this.getIndex()]);

		img.fadeIn(this.time,function() {

			imgold.fadeOut(mthis.time);
			setTimeout(function(){mthis.change()},mthis.wait);

		});

		/*
		$(this.store[this.index]).fadeOut(mthis.time, function() {

			$(mthis.store[mthis.getIndex()]).fadeIn(mthis.time,function() {

				setTimeout(function(){mthis.change()},mthis.wait);

			});

		});
		*/

	},

	getIndex: function () {

		var index = this.index;

		while (this.index === index) {

			this.index = Math.floor(Math.random() * this.total);

		}

		return this.index;

	}

});
