var homeBlend = {
  "init" : function(orArray, speed) {
		this.order   = orArray;
		this.current = 1;
		this.last    = 0;
		this.blendSpeed = speed;
		this.inuse = false;

		this.changeOpac(100, this.order[0]);
		for(i = 1; i < this.order.length; i++)
			this.changeOpac(0, this.order[i]);
	},
	"toggle" : function() {
			  
		document.getElementById(this.order[this.last]).style.zIndex=100;

		this.shiftDisplay(this.order[this.current]);
		this.shiftOpacity(this.order[this.last], this.blendSpeed);

		this.last = this.current;
		this.current++;
		if(this.current > this.order.length - 1)
			this.current = 0;
	},
	"toggleBack" : function() {
			  
		this.current = this.last;
		this.last--;
		if(this.last < 0)
			this.last = this.order.length - 1;

		document.getElementById(this.order[this.current]).style.zIndex=100;

		this.shiftDisplay(this.order[this.last]);
		this.shiftOpacity(this.order[this.current], this.blendSpeed);
	},
	"opacity" : function(id, opacStart, opacEnd, millisec) {
		//speed for each frame
		var speed = Math.round(millisec / 100);
		var timer = 0;

		this.inuse = true;
		//determine the direction for the blending, if start and end are the same nothing happens
		if(opacStart > opacEnd) {
			for(i = opacStart; i >= opacEnd; i--) {
				exec = "homeBlend.changeOpac(" + i + ",'" + id + "');";
				if(i == opacEnd)
					exec = exec + 'homeBlend.inuse = false;';
				setTimeout(exec,(timer * speed));
				timer++;
			}
		}
		else if(opacStart < opacEnd) {
			for(i = opacStart; i <= opacEnd; i++)
			{
				exec = "homeBlend.changeOpac(" + i + ",'" + id + "');";
				if(i == opacEnd)
					exec = exec + 'homeBlend.inuse = false;';
				setTimeout(exec,(timer * speed));
				timer++;
			}
		}
	},
	"changeOpac" : function(opacity, id) {
		var object = document.getElementById(id).style; 
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
		if(opacity == 0)
			 object.display = 'none';
		else
			 object.display = '';
	},
	"shiftOpacity" : function(id, millisec) {
		//if an element is invisible, make it visible, else make it invisible
		if(document.getElementById(id).style.opacity == 0) {
			this.opacity(id, 0, 100, millisec);
		} else {
			this.opacity(id, 100, 0, millisec);
		}
	},
	"shiftDisplay" : function(id) {
		var obj = document.getElementById(id);
		if(obj.style.display == 'none') {
		  obj.style.display = '';
		  obj.style.zIndex = '';
		  this.changeOpac(100, id);
		}
		else {
		  obj.style.display = 'none';
		  obj.style.zIndex = '';
		  this.changeOpac(0, id);
		}
	}
}
