
function diamond(elemRef, xPos, yPos, intervalStep, oldNum) {
	var me = this;
	this.elem = getEl(elemRef);

	this.start = function() {
		this.elem.parentNode.style.left = xPos + 'px';
		this.elem.parentNode.style.top = yPos + 'px';
		this.elem.index = 0;
		this.elem.oldImage = 'Images/' + getEnd(this.elem.src, "Images/");
		this.elem.opacStep = 4;
		if (this.elem.filters) // IE
			this.elem.filters.alpha.opacity = 0;
		else // W3C
			this.elem.style.opacity = 0.0;
		this.elem.oldNum = oldNum;
		this.intervalID = setInterval(function() {me.fadeDiamond()}, intervalStep); // Has got to be me!
		this.elem.onclick = function() {me.checkClick()};

		this.fadeDiamond = function() {
			if (this.elem.index >= 100) {
				this.elem.index = 0;
				this.elem.opacStep = isIE ? 5 : 4.6;
				this.elem.parentNode.style.backgroundImage = 'url(' + this.elem.oldImage + ')';
				do {
					var num = (Math.floor(Math.random() * parseInt(8)) + 1);
				} while (this.elem.oldNum == num);
				this.elem.oldNum = num;
				this.elem.src = 'Images/Diamond' + num + '.jpg';
				this.elem.oldImage = 'Images/Diamond' + num + '.jpg';
			} else {
				this.elem.opacStep = this.elem.opacStep * 0.965;
				this.elem.index += this.elem.opacStep;
			}
			if (this.elem.filters) // IE
				this.elem.filters.alpha.opacity = this.elem.index;
			else // W3C
				this.elem.style.opacity = this.elem.index/101;
		}
		this.checkClick = function() {
			if (this.intervalID == null) {
				this.intervalID = setInterval(function() {me.fadeDiamond()}, intervalStep); // Has got to be me!
				this.elem.alt = 'Click to stop';
				this.elem.title = 'Click to stop';
			} else {
				clearInterval(this.intervalID);
				this.intervalID = null;
				this.elem.alt = 'Click to start';
				this.elem.title = 'Click to start';
			}
		}
	}
}


