/*
 * ACCIDENT GALLERY.COM
 *
 * Class: movingobject.js
 * Version: 1.0.0
 * Desc:	An object that holds the
 *		behavioral information of
 *		an animated element.
 */

var MovingObject = function(idParam) {
	var _id		= null;			// the value returned by this instance's getElementById()
	var inScene	= null;			// flag representing the state of the object at render time
	var xTween	= null;			// Tween properties
	var yTween	= null;
	var wTween	= null;
	var hTween	= null;
	var rTween	= null;
	var gTween	= null;
	var bTween	= null;
	var aTween	= null;

	// CONSTRUCTOR
	function _construct(idParam) {
		_id = idParam;			// constructor binds _id to incoming param idParam
	}

	// METHODS
	function loadMotionX(t) {
		xTween = t;			// load tween for x-coordinate
	}
	function loadMotionY(t) {
		yTween = t;			// load tween for y-coordinate
	}
	function loadMotionW(t) {
		wTween = t;			// load tween for width size
	}
	function loadMotionH(t) {
		hTween = t;			// load tween for height size
	}
	function loadMotionRGB(tR,tG,tB) {
		rTween = tR;
		gTween = tG;
		bTween = tB;
	}
	function loadMotionA(t) {
		aTween = t;
	}
	function placeInScene() {
		inScene = true;			// place this instance into the current scene
	}
	function removeFromScene() {
		inScene = false;		// remove this instance from the current scene
	}
	function getState() {
		return inScene;
	}
	function parseColor() {
		null;				// this will parse the color values
	}
	function parseAlpha() {
		null;				// this will parse the alpha value
	}
	function render(eTime) {
		var running = false;		// presume that animation has stopped and prove this false

		/* CONDITIONAL ANIMATION
		 *
		 * First check to see if the tween exists.
		 * If it exists, check to see if the tween is still in the scene (has not completed animating).
		 * If it is still animating, set running to true and update the property controlled by the tween.
		 * If it has completed animating, do nothing and skip to the next tween.
		 *
		 */

			if(xTween != null) {
				if(xTween.getState()) {
					running = true;
					var xMove = xTween.interpolate(eTime);
					if(xMove != undefined) {
						_id.style.left = xMove + "px";
					}
				} else {
					if(xTween.getExecuteAfter() != null) {
						var runNext = xTween.getExecuteAfter();
						runNext();
					}
					xTween = null;
				}
			}
			if(yTween != null) {
				if(yTween.getState()) {
					running = true;
					var yMove = yTween.interpolate(eTime);
					if(yMove != undefined) {
						_id.style.top = yMove + "px";
					}
				} else {
					if(yTween.getExecuteAfter() != null) {
						var runNext = yTween.getExecuteAfter();
						runNext();
					}
					yTween = null;
				}
			}
			if(wTween != null) {
				if(wTween.getState()) {
					running = true;
					var wMove = wTween.interpolate(eTime);
					if(wMove != undefined) {
						_id.style.width = wMove + "px";
					}
				} else {
					if(wTween.getExecuteAfter() != null) {
						var runNext = wTween.getExecuteAfter();
						runNext();
					}
					wTween = null;
				}
			}
			if(hTween != null) {
				if(hTween.getState()) {
					running = true;
					var hMove = hTween.interpolate(eTime);
					if(hMove != undefined) {
						_id.style.height = hMove + "px";
					}
				} else {
					if(hTween.getExecuteAfter() != null) {
						var runNext = hTween.getExecuteAfter();
						runNext();
					}
					hTween = null;
				}
			}

			/*if((rVal != null) && (gVal != null) && (bVal != null)) {
				if(_id.style.color.indexOf("#") != (-1)) {
					var hex = "#" + (rVal << 16) | (gVal << 8) | bVal;
					_id.style.color = hex;
				} else {
					var rgb = "rgb(" + rVal + "," + gVal + "," + bVal + ")";
					_id.style.color = rgb;
				}
			}*/

			if(aTween != null) {
				if(aTween.getState()) {
					running = true;
					var aMove = aTween.interpolate(eTime);
					if(aMove != undefined) {
						_id.style.opacity = (aMove / 100) + "";
						_id.style.filter = "alpha(opacity=" + aMove + ")";
					}
				} else {
					if(aTween.getExecuteAfter() != null) {
						var runNext = aTween.getExecuteAfter();
						runNext();
					}
					aTween = null;
				}
			}

		/* CONDITIONAL TERMINATION
		 *
		 * First check to see if this object is still in the scene (has not completed animating).
		 * If it is still animating, do nothing and let Animator trigger this render() method again.
		 * If it has completed animating, remove this object from the scene.
		 *
		 */
		if(running == false) {
			removeFromScene();
		}
	}

	// CLASS PROPERTIES
	this._id = _id;
	this.xTween = xTween;
	this.yTween = yTween;
	this.wTween = wTween;
	this.hTween = hTween;
	this.rTween = rTween;
	this.gTween = gTween;
	this.bTween = bTween;
	this.aTween = aTween;
	this.inScene = inScene;

	// CLASS METHODS
	this._construct = _construct;
	this.loadMotionX = loadMotionX;
	this.loadMotionY = loadMotionY;
	this.loadMotionW = loadMotionW;
	this.loadMotionH = loadMotionH;
	this.loadMotionRGB = loadMotionRGB;
	this.loadMotionA = loadMotionA;
	this.placeInScene = placeInScene;
	this.getState = getState;
	this.render = render;

	_construct(idParam);
}