function HomeImageLoop(_elementId, _options) {

	this.element = document.getElementById(_elementId);
	if (!this.element) {
		return;
	}

	if (_options) {
		var i;
		for (i in _options) {
			this.options[i] = _options[i];
		}
	}

	this._create();
}

HomeImageLoop.prototype = {
	"options" : {
		"fadeDelay" : 2000,
		"fadeTime" : 1000,
		"zIndex" : 150
	},

	_create: function() {
		if (this.element.childNodes.length < 2) {
			return;
		}
		this.index = 0;

		$(this.element).find('img').each(
			function() {
				var preload = new Image;
				preload.src = this.src;
			}
		);

		var self = this;
		$(this.element).hover(function() { self._stopLoop(); }, function() { self._runLoop(); });

		this._runLoop();
	},

	_doFade : function() {
		var currentElement = this.element.childNodes[this.index++];

		this.index %= this.element.childNodes.length;

		var nextElement = this.element.childNodes[this.index];

		$(currentElement).fadeTo(this.options.fadeTime, 0);
		$(nextElement).css({'opacity': 0, 'z-index' : this.options.zIndex++}).show().fadeTo(this.options.fadeTime, 1);

		this._runLoop(true);
	},

	_stopLoop : function() {
		if (this.loopId) {
			clearTimeout(this.loopId);
			this.loopId = false;
		}
	},

	_runLoop : function(addFadeTime) {
		if (this.loopId) return;

		var self = this;

		var fDelay = this.options.fadeDelay;
		if (addFadeTime) {
			fDelay += this.options.fadeTime;
		}

		this.loopId = setTimeout(function() {self.loopId = false; self._doFade(); }, fDelay);
	}

};
