


function mbxAnimator()
{
	// Declare class attributes
	this.animationElements = new Array();

	// Declare class functions
	this.tick = tick;
	this.addElement = addElement;


	// Start the clock... 32fps ~ (1000/32)
	var mbxAnimRunner = null;
	mbxAnimRunner = setInterval("mbxAnim.tick()", 32);
	
	var tempObj = null;

	function tick(){
		for(var i=0;i<this.animationElements.length;i++)
		{
			tempObj = document.getElementById(this.animationElements[i].id);
			
//alert(tempObj);
			var removeMe = true;
			
			if(this.animationElements[i].width != null && this.animationElements[i].width != parseInt(tempObj.clientWidth))
			{
				tempObj.style.width = getNewVal(this.animationElements[i].width, parseInt(tempObj.clientWidth)) + "px";
				removeMe = false;
			}


			if(this.animationElements[i].height != null && this.animationElements[i].height != parseInt(tempObj.clientHeight))
			{
				tempObj.style.height = getNewVal(this.animationElements[i].height, parseInt(tempObj.clientHeight)) + "px";
				removeMe = false;
			}
			
			
			if(this.animationElements[i].top != null && this.animationElements[i].top != parseInt(tempObj.style.top))
			{
				tempObj.style.top = getNewVal(this.animationElements[i].top, parseInt(tempObj.style.top)) + "px";
				removeMe = false;
			}


			if(this.animationElements[i].left != null && this.animationElements[i].left != parseInt(tempObj.style.left))
			{
				tempObj.style.left = getNewVal(this.animationElements[i].left, parseInt(tempObj.style.left)) + "px";
				removeMe = false;
			}


			if(typeof tempObj.style.opacity == "string") { // mozilla compliant
				if(this.animationElements[i].opacity != null && this.animationElements[i].opacity != tempObj.style.opacity * 100)
				{
					
					tempObj.style.opacity = getNewVal(this.animationElements[i].opacity, parseInt(tempObj.style.opacity * 100)) / 100;
					removeMe = false;
//				alert(tempObj.style.opacity);
				}
			} else {
			//here use document.getElementById(id).filters.alpha.opacity
				if(this.animationElements[i].opacity != null && this.animationElements[i].opacity != parseInt(tempObj.filters.alpha.opacity))
				{
					
					tempObj.filters.alpha.opacity = getNewVal(this.animationElements[i].opacity, parseInt(tempObj.filters.alpha.opacity));
					removeMe = false;
//				alert(tempObj.style.opacity);
				}

//				if(this.animationElements[i].opacity != null && this.animationElements[i].opacity != parseInt(tempObj.filters.alpha.opacity))
///				{
//					tempObj.filters.alpha.opacity = getNewVal(this.animationElements[i].opacity, parseInt(tempObj.filters.alpha.opacity ));
//					removeMe = false;
//				}
			}


			if(this.animationElements[i].left != null && this.animationElements[i].left != parseInt(tempObj.style.left))
			{
				tempObj.style.left = getNewVal(this.animationElements[i].left, parseInt(tempObj.style.left)) + "px";
				removeMe = false;
			}



			
			if(this.animationElements[i].margin != null && this.animationElements[i].margin != parseInt(tempObj.margin))
			{
				tempObj.style.margin = getNewVal(this.animationElements[i].margin, parseInt(tempObj.margin)) + "px";
				removeMe = false;
			}


			if(removeMe)
				this.animationElements[i] = null;
		}
		
		var newArray = new Array();
		for(var i=0;i<this.animationElements.length;i++)
		{
			if(this.animationElements[i] != null)
				newArray[newArray.length] = this.animationElements[i];
		}
		this.animationElements = newArray;

		
	}


	function getNewVal(targetVal, currentVal){

		var newVal = parseInt(currentVal - ((currentVal-targetVal)*0.1));

		if(newVal == currentVal)
			if(targetVal > currentVal)
				return currentVal + 1;
			else
				return currentVal - 1;
		
		return newVal;

	
	
//		return currentVal+1;
	}
	
	function addElement(id, leftPos, rightPos, width, height, top, bottom, zIndex, pxSize, margin)
	{
//		alert(id);
		var added = false;
		for(var i=0;i<this.animationElements.length;i++)
		{
			if(this.animationElements[i].id == id)
			{
				this.animationElements[i] = new mbxAnimationTargetDescriptor(id, leftPos, rightPos, width, height, top, bottom, zIndex, pxSize, margin);
				added = true;
			}
		}
		if(!added)
			this.animationElements[this.animationElements.length] = new mbxAnimationTargetDescriptor(id, leftPos, rightPos, width, height, top, bottom, zIndex, pxSize, margin);

//		document.getElementById(id).style.zIndex = zIndex;
	}
	
	// function updateElement target

}



function mbxAnimationTargetDescriptor(id, leftPos, rightPos, width, height, top, bottom, pxSize, margin, opacity)
{
	this.id = id;
	this.left = leftPos;
	this.right = rightPos;
	this.width = width;
	this.height = height;
	this.top = top;
	this.bottom = bottom;
	this.fontSize = pxSize;
	this.margin = margin;
	this.opacity = opacity;
}


var mbxAnim = new mbxAnimator();







