/**
 * @requires jQuery
 * Slide the background image
 */
 
/* Create the namespace */
if (typeof Dansa === 'undefined') {
	var Dansa = {};
}

/* Create the background class */
Dansa.Slider = function (el) {

	var t = this;
	this.el = el;
	this.images = [];

	this.el.find('img').each(function (n) {
		this.el = $(this);
		this.active = n ? false : true;
		t.images.push(this);
	});

	$.each(this.images, function (n) {
		var nextEl = ((n + 1) >= t.images.length) ? 0 : n + 1;
		this.nextEl = t.images[nextEl];
		this.hideMe = function() {
			this.active = false;
			this.el.fadeOut();
		}		
		this.showMe = function() {
			this.active = true;
			this.el.fadeIn();
		}
	});

	this.changeImg = function () {
		$.each(t.images, function () {
			if (this.active) {
				this.hideMe();
				this.nextEl.showMe();
				return false;
			}
		});		
	}
	
	setInterval(this.changeImg, 8000);

};
