	//************************************************************************************************************//
	//************************************************************************************************************//
	//
	//
	//  DIMENSION4 STUDIOS TWEEN MOTION CLASS
	//  
	//       Copyright 2009-2010
	//
	//
	//************************************************************************************************************//
	//************************************************************************************************************//


	var timeRef = new Array();			// timer reference array:

	function ease_class_const(num)
	{
		this.easeIn = (num-1)*2 + 4000;
		this.easeOut = (num-1)*2 + 4000 + 1;
	}

	var Back = new ease_class_const(1);
	var Bounce = new ease_class_const(2);
	var Circ = new ease_class_const(3);
	var Cubic = new ease_class_const(4);
	var Elastic = new ease_class_const(5);
	var Expo = new ease_class_const(6);
	var Linear = new ease_class_const(7);
	var Quad = new ease_class_const(8);
	var Quart = new ease_class_const(9);
	var Quint = new ease_class_const(10);
	var Sine = new ease_class_const(11);

	var SineVals = new Array();
	var SineInVals = new Array();

	function AssignEaseArrays()
	{
		var rtd = Math.PI/180;
		var samples = 1000;
		var incs = 90 / samples;

		// ease.SineOut
		for(x=0;x<samples;x++)
		{
			SineVals[x] = Math.sin(x*incs*rtd);
		}
		// ease.SineIn
		for(x=0;x<samples;x++)
		{
			SineInVals[x] = 1-Math.cos(x*incs*rtd);
		}
	}

	AssignEaseArrays();



	function tween_dummy_function()
	{

	}

	function TweenJS(sectionID, secondsLong, varArray)
	{
		window.clearTimeout(timeRef[sectionID]);

		var fps = 30;
		var intervals = secondsLong * fps;
		var timeWait = 1000 / fps;
		var delay = 0;

		if(varArray['delay']){delay = varArray['delay'];}

		// Increment Delay:
		delay *= 1000;

		// get current values:
		var currentStyle = document.getElementById(sectionID).style;
		ox = parseInt(currentStyle.left);
		oy = parseInt(currentStyle.top);
		owidth = parseInt(currentStyle.width);
		oheight = parseInt(currentStyle.height);

		// we have not yet found an opacity value:
		var foundOpac = 0;
		// check for older IE opacity:
		if(currentStyle.filter){oalpha = parseInt(currentStyle.filter.substr(22,currentStyle.filter.length-22-1))/100;foundOpac=1;}
		// check for Konquerer opacity:
		if(currentStyle.KHTMLOpacity){oalpha = currentStyle.KHTMLOpacity;foundOpac=1;}
		// check for older Mozilla opacity:
		if(currentStyle.MozOpacity){oalpha = currentStyle.MozOpacity;foundOpac=1;}
		// check for standardized opacity:
		if(currentStyle.opacity){oalpha = currentStyle.opacity;foundOpac=1;}
		
		// if no opacity found yet, set default to 1:
		if(!foundOpac){oalpha = 1;}

		if(typeof varArray['x'] == 'undefined'){varArray['x']=ox;}
		if(typeof varArray['y'] == 'undefined'){varArray['y']=oy;}
		if(typeof varArray['width'] == 'undefined'){varArray['width']=owidth;}
		if(typeof varArray['height'] == 'undefined'){varArray['height']=oheight;}
		if(typeof varArray['ease'] == 'undefined'){varArray['ease']=0;}
		if(typeof varArray['easeParams'] == 'undefined'){varArray['easeParams']="";}
		if(typeof varArray['onComplete'] == 'undefined'){varArray['onComplete']=tween_dummy_function;}
		if(typeof varArray['onCompleteParams'] == 'undefined'){varArray['onCompleteParams']="";}
		if(typeof varArray['alpha'] == 'undefined'){varArray['alpha']=oalpha;}

		var diffx = parseInt(varArray['x']) - ox;
		var diffy = parseInt(varArray['y']) - oy;
		var diffwidth = parseInt(varArray['width']) - owidth;
		var diffheight = parseInt(varArray['height']) - oheight;
		var diffalpha = varArray['alpha'] - oalpha;

		var curVal = (1/intervals)*1000;
		var valInc = curVal;

		// begin the tweening process:
		timeRef[sectionID] = window.setTimeout("TweenLoop(\'" + sectionID + "\',0," + intervals + ", " + timeWait + ", " + ox + ", " + oy + ", " + owidth + ", " + oheight + ", " + oalpha + ", " + varArray['x'] + ", " + varArray['y'] + ", " + varArray['width'] + ", " + varArray['height'] + ", " + varArray['alpha'] + ", " + varArray['ease'] + ", \'" + varArray['easeParams'] + "\', " + varArray['onComplete'] + ", \'" + varArray['onCompleteParams'] + "\', " + diffx + ", " + diffy + ", " + diffwidth + ", " + diffheight + ", " + diffalpha + ", " + valInc + ", " + curVal + ")",delay);
	}

	function TweenLoop(sectionID,curIt,maxIt,timeWait,ox,oy,owidth,oheight,oalpha,dx,dy,dwidth,dheight,dalpha,ease,easeParams,onComplete,onCompleteParams,diffx,diffy,diffwidth,diffheight,diffalpha,valInc,curVal)
	{
		// push the current val into an integer:
		cVal = parseInt(curVal);

		// set up a placeholder variable:
		var pArray = new Array();

		switch(ease)
		{
		// sine easing out:
		case Sine.easeOut:
			pArray = SineVals;
			break;
		// sine easing in:
		case Sine.easeIn:
			pArray = SineInVals;
			break;
		// default easing (linear):
		case 0:

			break;
		}

		if(cVal>999){cVal=999;}

		if(diffx){cx=ox+parseInt(pArray[cVal] * diffx);}
		if(diffy){cy=oy+parseInt(pArray[cVal] * diffy);}
		if(diffwidth){cwidth=owidth+parseInt(pArray[cVal] * diffwidth);}
		if(diffheight){cheight=oheight+parseInt(pArray[cVal] * diffheight);}
		if(diffalpha){calpha=oalpha+pArray[cVal] * diffalpha;}

		var currentStyle = document.getElementById(sectionID).style;

		if(diffx){currentStyle.left = cx + "px";}
		if(diffy){currentStyle.top = cy + "px";}
		if(diffwidth){currentStyle.width = cwidth + "px";}
		if(diffheight){currentStyle.height = cheight + "px";}
		if(diffalpha)
		{
			currentStyle.filter = "alpha(style=0,opacity=" + (calpha*100) + ")";
			currentStyle.KHTMLOpacity = calpha;
			currentStyle.MozOpacity = calpha;
			currentStyle.opacity = calpha;
		}

		// Increment the current Iteration:
		curIt++;

		// Increment current val:
		curVal += valInc;

		// If maximum Iterations not met, Go again:
		if(curIt<=maxIt)
		{
			// Recurse:
			timeRef[sectionID] = window.setTimeout("TweenLoop(\'" + sectionID + "\', " + curIt + ", " + maxIt + ", " + timeWait + ", " + ox + ", " + oy + ", " + owidth + ", " + oheight + ", " + oalpha + ", " + dx + ", " + dy + ", " + dwidth + ", " + dheight + ", " + dalpha + ", " + ease + ", \'" + easeParams + "\', " + onComplete + ", \'" + onCompleteParams + "\', " + diffx + ", " + diffy + ", " + diffwidth + ", " + diffheight + ", " + diffalpha + ", " + valInc + ", " + curVal + ")",timeWait);
		}
		else
		{
			// make sure all values are at their destination now:
			if(diffx){currentStyle.left = dx + "px";}
			if(diffy){currentStyle.top = dy + "px";}
			if(diffwidth){currentStyle.width = dwidth + "px";}
			if(diffheight){currentStyle.height = dheight + "px";}

			// If there was an "onComplete" passed:
			if(onComplete)
			{
				// If there were parameters passed for the "onComplete" function:
				if(onCompleteParams)
				{
					//alert(onCompleteParams);
					var tarr = onCompleteParams.split(",");
					onCompleteParams = "";
					for(x=0;x<tarr.length;x++)
					{
						if(isNaN(tarr[x])){tarr[x] = "\"" + tarr[x] + "\"";}
						onCompleteParams += tarr[x];
						if(x<tarr.length-1){onCompleteParams += ",";}
					}
					// call the function with parameters:
					eval('onComplete(' + onCompleteParams + ')');
				}
				else
				{
					// call the function with no parameters:
					onComplete();
				}
			}
		}
	}
