/*
	Author: Anthony Dickens
	Project: NintendoLife.com
*/
function blender () {
	this.timer = false;
	this.speed = 10;
}

//Methods
blender.prototype.blend = function (idFrom, idTo, speed) {
	if (speed > 0) {
		this.speed = speed;
	}
	var self = this;
	this.idFrom = idFrom;
	this.idTo = idTo;
	
	this.increment = Math.round(100 / this.speed);
	
	this.setOpacity(idFrom, 100);
	this.setOpacity(idTo, 0);
	
	document.getElementById(idFrom).style.zIndex = 5;
	document.getElementById(idTo).style.zIndex = 10;
	
	document.getElementById(idFrom).style.display = 'block';
	document.getElementById(idTo).style.display = 'block';
	
	//cf.event.attach(document.getElementById(idFrom), 'mouseover', function () { alert('test'); self.stopTimer(); });
	//document.getElementById(idFrom).onmouseout = function () { self.startTimer(); };
	
	this.startTimer();
}

blender.prototype.updateBlend = function () {
	if (element = document.getElementById(this.idTo)) {
		this.setOpacity(this.idTo, ((element.style.opacity * 100) + this.increment));
		this.setOpacity(this.idFrom, ((document.getElementById(this.idFrom).style.opacity * 100) - this.increment));
		if (element.style.opacity < 1) {
			this.startTimer();
		}
		else {
			document.getElementById(this.idFrom).style.display = 'none';
			this.stopTimer();
		}
	}
}

blender.prototype.setOpacity = function (idName, opacity) {
	if (object = document.getElementById(idName).style) {
		object.opacity = (opacity / 100);
		object.filter = opacity == 100 ? "" : "alpha(opacity=" + opacity + ")";
	}
}

blender.prototype.startTimer = function () {
	var _self = this;
	this.stopTimer();
	this.timer = setTimeout(function () { _self.updateBlend(); }, 1);
}

blender.prototype.stopTimer = function () {
	if (this.timer != false) {
		clearTimeout(this.timer);
		this.timer = false;
	}
}
