utilities.prototype.animate = {
	framesPerSec : 15,
	elementArray : new Array (),
	animationArray : new Array (),
	setEvent : function () {
		this.event          = arguments[0].replace(/"/g,"\\\"");
		this.event          = this.event.replace(/'/g,"\\\'");
		this.time           = (arguments[1]/this.framesPerSec)*1000;
		setTimeout("eval(\""+this.event+"\")",this.time);
	},
	newAnimation : function () {
		this.animation      = {
			stopped : false,
			repeat : false,
			events : new Array(),
			addEvent : function (event) {
				this.events.push(event);
			},
			go : function () {
				util.util.animate.startAnimation(this);
			},
			stop : function () {
				this.stopped = true;
			}
		}
		return this.animation;
	},
	startAnimation : function (animation,repeated) {
		if (repeated) {
			this.arrayNum   = animation;
			animation       = util.animate.animationArray[animation];
		}
		if (animation.stopped == false) {
			this.repeat         = animation.repeat;
			this.events         = animation.events;
			this.duration       = animation.duration;
			this.element        = animation.element;
			this.nextEA         = util.animate.elementArray.length;
			util.animate.elementArray[this.nextEA] = this.element;
			
			for (var i=0; i<this.events.length; i++) {
				this.event      = this.events[i];
				
				switch (this.event.effect) {
					case "fade":
						util.animate.setEvent("util.animate.fade(util.animate.elementArray["+this.nextEA+"],"+this.event.opacity+","+this.event.duration+")",this.event.startFrame);
						break;
					case "move":
						util.animate.setEvent("util.animate.move(util.animate.elementArray["+this.nextEA+"],"+(this.event.top ? this.event.top : "null")+","+(this.event.left ? this.event.left : "null")+","+this.event.duration+")",this.event.startFrame);
						break;
					case "scale":
						util.animate.setEvent("util.animate.scale(util.animate.elementArray["+this.nextEA+"],"+(this.event.newWidth ? this.event.newWidth : "null")+","+(this.event.newHeight ? this.event.newHeight : "null")+","+this.event.duration+")",this.event.startFrame);
						break;
					case "action":
						util.animate.setEvent(this.event.action,this.event.startFrame);
						break;
				}
			}
			if (this.repeat) {
				if (repeated == null) {
					util.animate.animationArray.push(animation);
				}
				this.time       = (this.duration/util.animate.framesPerSec)*1000;
				setTimeout("util.animate.startAnimation("+(this.arrayNum ? this.arrayNum : (util.animate.animationArray.length-1))+",true)",this.time);
			}
		}
	},
	animateThis : function (animation) {
		animation.element = this;
		util.animate.startAnimation(animation);
	},
	setPosition : function () {
		if (!this.nodeType) {
			if (this[0] && this[0].nodeType) {
				for (var i=0; i<this.length; i++) {
					this[i].setPosition(arguments[0],arguments[1]);
				}
				return true;
			}
		}
		
		if (this.nodeType) {
			this.element    = this;
			this.newY       = arguments[0];
			this.newX       = arguments[1];
		}
		else {
			arguments[0]    = eval(arguments[0]);
			this.element    = arguments[0].nodeType ? arguments[0] : $(arguments[0]);
			this.newY       = arguments[1];
			this.newX       = arguments[2];
		}
		var styles          = {
			top : this.newY != null ? this.newY+"px" : null,
			left : this.newX != null ? this.newX+"px" : null
		};
		
		this.element.setStyles(styles);
	},
	setWidth : function () {
		if (!this.nodeType) {
			if (this[0] && this[0].nodeType) {
				for (var i=0; i<this.length; i++) {
					this[i].setWidth(arguments[0]);
				}
				return true;
			}
		}
		
		if (this.nodeType) {
			this.element    = this;
			this.newWidth   = arguments[0];
		}
		else {
			arguments[0]    = eval(arguments[0]);
			this.element    = arguments[0].nodeType ? arguments[0] : $(arguments[0]);
			this.newWidth   = arguments[1];
		}
		this.element.setStyles({width: this.newWidth+"px"});
	},
	setHeight : function () {
		if (!this.nodeType) {
			if (this[0] && this[0].nodeType) {
				for (var i=0; i<this.length; i++) {
					this[i].setHeight(arguments[0]);
				}
				return true;
			}
		}
		
		if (this.nodeType) {
			this.element    = this;
			this.newHeight  = arguments[0];
		}
		else {
			arguments[0]    = eval(arguments[0]);
			this.element    = arguments[0].nodeType ? arguments[0] : $(arguments[0]);
			this.newHeight  = arguments[1];
		}
		this.element.setStyles({height: this.newHeight+"px"});
	},
	setOpacity : function () {
		if (!this.nodeType) {
			if (this[0] && this[0].nodeType) {
				for (var i=0; i<this.length; i++) {
					this[i].setOpacity(arguments[0]);
				}
				return true;
			}
		}
		
		if (this.nodeType) {
			this.element    = this;
			this.newOpacity = arguments[0];
		}
		else {
			arguments[0]    = eval(arguments[0]);
			this.element    = arguments[0].nodeType ? arguments[0] : $(arguments[0]);
			this.newOpacity = arguments[1];
		}
		this.element.setStyles({opacity: this.newOpacity});
	},
	setBackground : function () {
		if (!this.nodeType) {
			if (this[0] && this[0].nodeType) {
				for (var i=0; i<this.length; i++) {
					this[i].setBackground(arguments[0]);
				}
				return true;
			}
		}
		
		if (this.nodeType) {
			this.element    = this;
			this.newColor   = arguments[0];
		}
		else {
			arguments[0]    = eval(arguments[0]);
			this.element    = arguments[0].nodeType ? arguments[0] : $(arguments[0]);
			this.newColor   = arguments[1];
		}
		this.element.setStyles({backgroundColor: "#"+this.newColor});
	},
	setFontColor : function () {
		if (!this.nodeType) {
			if (this[0] && this[0].nodeType) {
				for (var i=0; i<this.length; i++) {
					this[i].setFontColor(arguments[0]);
				}
				return true;
			}
		}
		
		if (this.nodeType) {
			this.element    = this;
			this.newColor   = arguments[0];
		}
		else {
			arguments[0]    = eval(arguments[0]);
			this.element    = arguments[0].nodeType ? arguments[0] : $(arguments[0]);
			this.newColor   = arguments[1];
		}
		this.element.setStyles({color: "#"+this.newColor});
	},
	move : function () {
		if (!this.nodeType) {
			if (this[0] && this[0].nodeType) {
				for (var i=0; i<this.length; i++) {
					this[i].move(arguments[0],arguments[1],arguments[2]);
				}
				return true;
			}
		}
	
		if (this.nodeType) {
			this.element    = this;
			this.newY       = arguments[0];
			this.newX       = arguments[1];
			this.steps      = arguments[2];
		}
		else {
			this.element    = arguments[0].nodeType ? arguments[0] : $(arguments[0]);
			this.newY       = arguments[1];
			this.newX       = arguments[2];
			this.steps      = arguments[3];
		}
		
		//add element to array
		this.nextEA         = util.animate.elementArray.length;
		util.animate.elementArray[this.nextEA] = this.element;
		
		//current
		this.currentX       = this.element.offsetLeft;
		this.currentY       = this.element.offsetTop;
		
		//the difference between current and new
		this.diffX          = this.currentX>this.newX ? 0-(this.currentX-this.newX) : this.currentX<this.newX ? this.newX-this.currentX : 0;
		this.eachX          = this.diffX/this.steps;
		
		this.diffY          = this.currentY>this.newY ? 0-(this.currentY-this.newY) : this.currentY<this.newY ? this.newY-this.currentY : 0;
		this.eachY          = this.diffY/this.steps;
		
		for (var i=0; i<=this.steps; i++) {
			if (this.diffX || this.diffY) {
				this.nextY = this.newY != null ? parseInt(this.currentY)+parseInt((parseInt(this.eachY)*i)) : null;
				this.nextX = this.newX != null ? parseInt(this.currentX)+parseInt((parseInt(this.eachX)*i)) : null;
				util.animate.setEvent("util.animate.setPosition(\"this.elementArray["+this.nextEA+"]\","+this.nextY+","+this.nextX+")",i);
			}
		}
		if (this.nextX != this.newX || this.nextY != this.newY) {
			util.animate.setEvent("util.animate.setPosition(\"this.elementArray["+this.nextEA+"]\","+this.newY+","+this.newX+")",this.steps);
		}
	},
	scale : function () {
		if (!this.nodeType) {
			if (this[0] && this[0].nodeType) {
				for (var i=0; i<this.length; i++) {
					this[i].scale(arguments[0],arguments[1],arguments[2]);
				}
				return true;
			}
		}
		
		if (this.nodeType) {
			this.element    = this;
			this.newWidth   = arguments[0];
			this.newHeight  = arguments[1];
			this.steps      = arguments[2];
		}
		else {
			this.element    = arguments[0].nodeType ? arguments[0] : $(arguments[0]);
			this.newWidth   = arguments[1];
			this.newHeight  = arguments[2];
			this.steps      = arguments[3];
		}
		
		//add element to array
		this.nextEA         = util.animate.elementArray.length;
		util.animate.elementArray[this.nextEA] = this.element;
		
		//current
		this.currentWidth   = this.element.currentStyle ? this.element.currentStyle["width"] : window.getComputedStyle(this.element,"").getPropertyValue("width");
		this.currentWidth   = this.currentWidth.replace(/[a-zA-Z]{2}/,"",this.currentWidth);
		
		this.currentHeight  = this.element.currentStyle ? this.element.currentStyle["height"] : window.getComputedStyle(this.element,"").getPropertyValue("height");
		this.currentHeight  = this.currentHeight.replace(/[a-zA-Z]{2}/,"",this.currentHeight);
		
		//the difference between current and new
		this.diffW          = this.newWidth != null ? this.currentWidth>this.newWidth ? 0-(this.currentWidth-this.newWidth) : this.currentWidth<this.newWidth ? this.newWidth-this.currentWidth : 0 : null;
		this.eachW          = this.newWidth != null ? this.diffW/this.steps : null;
		
		this.diffH          = this.newHeight != null ? this.currentHeight>this.newHeight ? 0-(this.currentHeight-this.newHeight) : this.currentHeight<this.newHeight ? this.newHeight-this.currentHeight : 0 : null;
		this.eachH          = this.newHeight != null ? this.diffH/this.steps : null;
		
		for (var i=0; i<=this.steps; i++) {
			if (this.newWidth) {
				this.nextW = parseInt(this.currentWidth)+parseInt((parseInt(this.eachW)*i));
				util.animate.setEvent("util.animate.setWidth(\"this.elementArray["+this.nextEA+"]\","+this.nextW+")",i);
			}
			else {
				this.nextW = null;
			}
			if (this.newHeight) {
				this.nextH = parseInt(this.currentHeight)+parseInt((parseInt(this.eachH)*i));
				util.animate.setEvent("util.animate.setHeight(\"this.elementArray["+this.nextEA+"]\","+this.nextH+")",i);
			}
			else {
				this.nextH = null;
			}
		}
		if (this.nextH != this.newHeight || this.nextW != this.newWidth) {
			if (this.newWidth && this.diffW) { util.animate.setEvent("util.animate.setWidth(\"this.elementArray["+this.nextEA+"]\","+this.newWidth+")",this.steps); }
			if (this.newHeight && this.diffH) { util.animate.setEvent("util.animate.setHeight(\"this.elementArray["+this.nextEA+"]\","+this.newHeight+")",this.steps); }
		}
	},
	fade : function () {
		if (!this.nodeType) {
			if (this[0] && this[0].nodeType) {
				for (var i=0; i<this.length; i++) {
					this[i].fade(arguments[0],arguments[1]);
				}
				return true;
			}
		}
		
		if (this.nodeType) {
			this.element    = this;
			this.newOpacity = arguments[0];
			this.steps      = arguments[1];
		}
		else {
			this.element    = arguments[0].nodeType ? arguments[0] : $(arguments[0]);
			this.newOpacity = arguments[1];
			this.steps      = arguments[2];
		}
		
		//add element to array
		this.nextEA         = util.animate.elementArray.length;
		util.animate.elementArray[this.nextEA] = this.element;
		
		//current
		this.currentOpacity = this.element.currentStyle ? this.element.currentStyle["opacity"] : window.getComputedStyle(this.element,"").getPropertyValue("opacity");
		this.currentOpacity = this.currentOpacity ? this.currentOpacity*100 : 100;
		
		this.diffOpac       = this.currentOpacity>this.newOpacity ? 0-(this.currentOpacity-this.newOpacity) : this.currentOpacity<this.newOpacity ? this.newOpacity-this.currentOpacity : 0;
		this.eachOpac       = this.diffOpac/this.steps;
		
		for (var i=0; i<=this.steps; i++) {
			this.nextO = (parseInt(this.currentOpacity)+parseInt((parseInt(this.eachOpac)*i)))/100;
			util.animate.setEvent("util.animate.setOpacity(\"this.elementArray["+this.nextEA+"]\","+this.nextO+")",i);
		}
		if (this.nextO != this.newOpacity) {
			if (this.newOpacity) { util.animate.setEvent("util.animate.setOpacity(\"this.elementArray["+this.nextEA+"]\","+(parseInt(this.newOpacity)/100)+")",this.steps); }
		}
	},
	gradColor : function () {
		if (!this.nodeType) {
			if (this[0] && this[0].nodeType) {
				for (var i=0; i<this.length; i++) {
					this[i].gradBackground(arguments[0],arguments[1],arguments[2],arguments[3]);
				}
				return true;
			}
		}
		
		if (this.nodeType) {
			this.element      = this;
			this.type         = arguments[0];
			this.currentColor = arguments[1];
			this.newColor     = arguments[2];
			this.steps        = arguments[3];
		}
		else {
			this.element      = arguments[0].nodeType ? arguments[0] : $(arguments[0]);
			this.type         = arguments[1];
			this.currentColor = arguments[2];
			this.newColor     = arguments[3];
			this.steps        = arguments[4];
		}
		
		//add element to array
		this.nextEA         = util.animate.elementArray.length;
		util.animate.elementArray[this.nextEA] = this.element;
		
		this.currentColor     = util.color(this.currentColor);
		this.newColor         = util.color(this.newColor);
		
		this.diffRed          = this.currentColor[0]>this.newColor[0] ? 0-(this.currentColor[0]-this.newColor[0]) : this.currentColor[0]<this.newColor[0] ? this.newColor[0]-this.currentColor[0] : 0;
		this.eachRed          = this.diffRed/this.steps;
		this.diffGreen        = this.currentColor[1]>this.newColor[1] ? 0-(this.currentColor[1]-this.newColor[1]) : this.currentColor[1]<this.newColor[1] ? this.newColor[1]-this.currentColor[1] : 0;
		this.eachGreen        = this.diffGreen/this.steps;
		this.diffBlue         = this.currentColor[2]>this.newColor[2] ? 0-(this.currentColor[2]-this.newColor[2]) : this.currentColor[2]<this.newColor[2] ? this.newColor[2]-this.currentColor[2] : 0;
		this.eachBlue         = this.diffBlue/this.steps;
		
		for (i=0; i<this.steps; i++) {
			this.nextRed      = Math.round(this.currentColor[0]+(this.eachRed*i));
			this.nextGreen    = Math.round(this.currentColor[1]+(this.eachGreen*i));
			this.nextBlue     = Math.round(this.currentColor[2]+(this.eachBlue*i));
			this.nextColor    = util.color(new Array(this.nextRed,this.nextGreen,this.nextBlue),"RGB");
			switch (this.type) {
				case "font":
					util.animate.setEvent("util.animate.setFontColor(\"this.elementArray["+this.nextEA+"]\",\""+this.nextColor+"\")",i);
					break;
				case "background":
					util.animate.setEvent("util.animate.setBackground(\"this.elementArray["+this.nextEA+"]\",\""+this.nextColor+"\")",i);
					break;
			}
		}
		if (this.nextRed != this.newColor[0] || this.nextGreen != this.newColor[1] || this.nextBlue != this.newColor[2]) {
			switch (this.type) {
				case "font":
					util.animate.setEvent("util.animate.setFontColor(\"this.elementArray["+this.nextEA+"]\",\""+util.color(new Array(this.newColor[0],this.newColor[1],this.newColor[2]),"RGB")+"\")",this.steps);
					break;
				case "background":
					util.animate.setEvent("util.animate.setBackground(\"this.elementArray["+this.nextEA+"]\",\""+util.color(new Array(this.newColor[0],this.newColor[1],this.newColor[2]),"RGB")+"\")",this.steps);
					break;
			}
		}
	}
};

utilities.prototype.dom.nodeMethods.push({method: 'setOpacity', func: util.animate.setOpacity});
utilities.prototype.dom.nodeMethods.push({method: 'setWidth', func: util.animate.setWidth});
utilities.prototype.dom.nodeMethods.push({method: 'setHeight', func: util.animate.setHeight});
utilities.prototype.dom.nodeMethods.push({method: 'setPosition', func: util.animate.setPosition});
utilities.prototype.dom.nodeMethods.push({method: 'setBackground', func: util.animate.setBackground});
utilities.prototype.dom.nodeMethods.push({method: 'setFontColor', func: util.animate.setFontColor});
utilities.prototype.dom.nodeMethods.push({method: 'move', func: util.animate.move});
utilities.prototype.dom.nodeMethods.push({method: 'scale', func: util.animate.scale});
utilities.prototype.dom.nodeMethods.push({method: 'fade', func: util.animate.fade});
utilities.prototype.dom.nodeMethods.push({method: 'gradColor', func: util.animate.gradColor});
utilities.prototype.dom.nodeMethods.push({method: 'animateThis', func: util.animate.animateThis});

//utilities.prototype.dom.addAnimate = function (element) {
//	if (element) {
//		if (element.nodeType) {
//			element.setOpacity  = util.animate.setOpacity;
//			element.setWidth    = util.animate.setWidth;
//			element.setHeight   = util.animate.setHeight;
//			element.setPosition = util.animate.setPosition;
//			element.move        = util.animate.move;
//			element.scale       = util.animate.scale;
//			element.fade        = util.animate.fade;
//			element.gradColor   = util.animate.gradColor;
//			element.animateThis = util.animate.animateThis;
//		}
//		else {
//			for (var i=0; i<element.length; i++) {
//				element.move  = function (newY, newX, time) {
//					for (var i=0; i<this.length; i++) {
//						util.dom.addAnimate(this[i]);
//						this[i].move(newY, newX, time);
//					}
//				};
//				element.scale = function (newWidth, newHeight, time) {
//					for (var i=0; i<this.length; i++) {
//						util.dom.addAnimate(this[i]);
//						this[i].scale(newWidth, newHeight, time);
//					}
//				};
//				element.fade  = function (newOpacity, time) {
//					for (var i=0; i<this.length; i++) {
//						util.dom.addAnimate(this[i]);
//						this[i].fade(newOpacity, time);
//					}
//				};
//				element.gradColor = function (type,currentColor,newColor,time) {
//					for (var i=0; i<this.length; i++) {
//						util.dom.addAnimate(this[i]);
//						this[i].gradColor(type,currentColor,newColor,time);
//					}
//				};
//			}
//		}
//	}
//}