/**
 * SOE Platform - DOM utility class.
 * @class DOM
 * @requires
 * @author Sean White
 * @constructor none
 */

var fx={
 queue : false,
 queueStep: 0,
 queueItems : [],
 addQueueItem : function(obj,FX){
	//alert("Add queue Item queue");
	if(!obj.current)
	{
		obj.current=0;
	}
	if(!obj.currentPos)
	{
		obj.currentPos=[0,0];
	} 	
	
 	this.queueItems.push(FX);
	
	
 }
 ,
 startFxQueue : function(){
 	
	//alert("Start effects queue" + this.queueStep);
	
 	this.queueItems[0]();
	this.queueStep=this.queueStep+1;
	
 }
 ,
 nextFxQueueItem : function(){
 	
	if(this.queueStep<this.queueItems.length)
	{
		//alert("next effect" + this.queueStep);
  		this.queueItems[this.queueStep]();
		this.queueStep=this.queueStep+1;
	}
	else
	{
		//alert("finished effects");
	}
	
 }
 ,
 fader : function(elem,startRGB,endRGB,finalColor,steps,intervals,powr) {

	if (elem.bgFadeInt) window.clearInterval(elem.bgFadeInt);
	var actStep = 0;
	elem.bgFadeInt = window.setInterval(
		function() {
			elem.style.backgroundColor = "rgb("+
				fx.easeInOut(startRGB[0],endRGB[0],steps,actStep,powr)+","+
				fx.easeInOut(startRGB[1],endRGB[1],steps,actStep,powr)+","+
				fx.easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)+")";
			actStep++;
			if (actStep > steps) {
			elem.style.backgroundColor = finalColor;
			window.clearInterval(elem.bgFadeInt);
			}
		}
		,intervals)
},

 fade : function(elem,startRGB,endRGB,steps,intervals,powr) {
	if (elem.bgFadeMemInt) window.clearInterval(elem.bgFadeMemInt);
	var actStep = 0;
	elem.bgFadeMemInt = window.setInterval(
		function() {
			elem.currentbgRGB = [
				fx.easeInOut(startRGB[0],endRGB[0],steps,actStep,powr),
				fx.easeInOut(startRGB[1],endRGB[1],steps,actStep,powr),
				fx.easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)
				];
			elem.style.backgroundColor = "rgb("+
				elem.currentbgRGB[0]+","+
				elem.currentbgRGB[1]+","+
				elem.currentbgRGB[2]+")";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.bgFadeMemInt);
		}
		,intervals)
},

 reSize: function(elem,start,end,steps,intervals,powr,type) {
	if (elem.ChangeMemInt) window.clearInterval(elem.ChangeMemInt);
	var actStep = 0;
	
	elem.ChangeMemInt = window.setInterval(
		function() {
			elem.current = fx.easeInOut(start,end,steps,actStep,powr);
			if(type=="height")
			{
				elem.style.height = elem.current+"px";
			}
			else
			{
				elem.style.width = elem.current+"px";
			}
			
			actStep++;
			if (actStep > steps)
			{
				//alert("finished");
			 	window.clearInterval(elem.ChangeMemInt);
				if(fx.queue)
				{
					fx.nextFxQueueItem();
				}
			}
		}
		,intervals)

},

 move : function(elem,startPos,endPos,steps,intervals,powr) {
	if (elem.posChangeMemInt) window.clearInterval(elem.posChangeMemInt);
	var actStep = 0;
	
	elem.posChangeMemInt = window.setInterval(
		function() {
			elem.currentPos = [
				fx.easeInOut(startPos[0],endPos[0],steps,actStep,powr),
				fx.easeInOut(startPos[1],endPos[1],steps,actStep,powr)
				];
				
				
			elem.style.left = elem.currentPos[0]+"px";
			elem.style.top = elem.currentPos[1]+"px";
			actStep++;
			if (actStep > steps) 
			{
				window.clearInterval(elem.posChangeMemInt);
				if(fx.queue)
				{
					fx.nextFxQueueItem();
				}
			}

		}
		,intervals)

},

 easeInOut : function(minValue,maxValue,totalSteps,actualStep,powr) {

	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(stepp)
}


}
	
	















