
var pendingAnimStamp = new Object();

function TweenGranule(obj, prop, val, stamp){
	var animId = obj + "::" + prop;
	if(stamp < pendingAnimStamp[animId]){return}	//  Is there a newer tween animating the same object and property?
													//  if so, lets just stop this pointless charade.
	if(stamp >= pendingAnimStamp[animId]){			//  ooh, it looks like we're a new tween
		pendingAnimStamp[animId] = stamp;			//  lets let the previous tween know they arent needed.
	}		
	ge(obj).style[prop] = val + "px";
}

function Tween(obj, prop, end, millis, gran){	
	var frames = millis / gran;
	var animId = obj + "::" + prop;
	
	stamp = new Date().getTime();
	pendingAnimStamp[animId] = stamp;
		
	var currVal = getStyle(obj, prop);
	currVal = parseInt(currVal.split("px")[0]);		

	for( var i = frames; i >= 0; i--){
		thisVal = (((currVal - end)/frames) * i) + end 	
        setTimeout("TweenGranule('" + obj + "','" + prop + "',"+thisVal+","+stamp+")",millis - (i * gran));
	}
    setTimeout("TweenGranule('" + obj + "','" + prop + "',"+end+","+stamp+")",millis);
    if( ge(obj).onComplete ){
		setTimeout("ge('" + obj + "').onComplete();", millis);
		setTimeout("ge('" + obj + "').onComplete = false;", millis+1);
	}		
}


function changeOpac(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 == 100){object.filter = '';}
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}








function getStyle(el,styleProp)
{
var x = document.getElementById(el);
if (x.currentStyle)
var y = x.currentStyle[styleProp];
else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
return y;
}

