function animateProperty(animateObject){
	var object = animateObject.object;
	//set array is none
	if (object.animateProperties == undefined){
		object.animateProperties = Array();
	}
	//check if key exists or not in array
	if (object.animateProperties[animateObject.cssProperty] == undefined){
		object.animateProperties[animateObject.cssProperty] = animateObject;
		object.animateProperties[animateObject.cssProperty].start();
	}else{
		object.animateProperties[animateObject.cssProperty].reConfigure(animateObject);
		object.animateProperties[animateObject.cssProperty].start();
	}
	return object.animateProperties[animateObject.cssProperty];
}
function animateProperties(){
	this.name = "animateProperties";
	this.object = null;
	this.cssProperty = null;
	this.time = 100;
	this.from = 0.00;
	this.to = 0.00;
	this.current = null;
	this.progress = 0;
	this.ppms = 0.00;
	this.ppFrame = 0.00;
	this.msPerFrame = 10;
	this.forceUnits = "";
	this.onComplete = null;
	this.configure = function(object,cssProperty,time,to,from){
		this.object = object;
		this.cssProperty = cssProperty;
		this.time = time;
		if (from != null){
			this.from = from;
		}else{
			this.from = this.getProperty();
		}
		this.current = this.from;
		this.to = to;
		this.ppms = 0;
		this.calulateppms();
	}
	this.reConfigure = function(animateProperties){
		this.time = animateProperties.time;
		this.from = animateProperties.from;
		this.to = animateProperties.to;
		if (this.from == null){
			this.from = this.getProperty();
		}
		this.current = this.from;
		this.calulateppms();
	}
	this.calulateppms = function(){
		this.difference = Math.abs(this.from - this.to);
		this.ppms = this.difference / this.time;
		this.ppFrame = this.ppms * this.msPerFrame;
	}
	this.reOccur = false;
	this.start = function(){
		if (this.reOccur == false){
			if (this.difference > 0){
				this.reOccur = true;
				this.loop();
			}else{
			}
		}else{
		}
	}
	this.end = function(){
		this.current = this.to;
		this.from = this.to;
		this.reOccur = false;
	}
	this.loop = function(){
		var animateProperties = this;
		var ppFrame = ((this.ppFrame * (1.1 - this.progress)) * 2);
		if (this.from > this.to){
			// If from > to, We decriment
			this.current -= ppFrame;
			if (this.current <= this.to){
				this.end();
			}
		}else if (this.from < this.to){
			// If fron < to, We incriment
			this.current += ppFrame;
			if (this.current >= this.to){
				this.end();
			}
		}
		this.progress = 1 - (Math.abs(this.to - this.current) / Math.abs(this.difference));
		
		var madeVar = this.makeCssVar();
		if( Object.prototype.toString.call(madeVar) === '[object Object]' ) {
			madeVar.func();
		}else{
			var execString = "animateProperties.object.style."+this.cssProperty+" = '"+madeVar+"'";
			eval(execString);
		}
		if (this.reOccur){
			setTimeout(function(){
				animateProperties.loop();
				animateProperties = undefined;
			},this.msPerFrame);
		}
		if ((this.onComplete) && (!(this.reOccur))){
			var caller = this.onComplete.caller;
			eval("caller."+this.onComplete.funcName+"();");
		}
	}
	this.makeCssVar = function(){
		if (this.forceUnits !== ""){
			return this.current + this.forceUnits;
		}
		switch (this.cssProperty){
			case "height":
			case "width":
			case "top":
			case "left":
			case "bottom":
				return this.current+"px";
			break;
			case "opacity":
				return this.current;
			break;
			default:
				var string = Object.prototype.toString.call();
				if (string = "[object Object]"){
					var object = this;
					return{
						func:function(){
							eval("object.object."+object.cssProperty.functionName+"("+object.current+");");
						}
					}
				}else{
					alert(this.cssProperty+" Not implamented in makeCssVar.");
				}
			break;
		}
	}
	this.getProperty = function(){
		if (this.current !== null){
			return this.current;
		}else{
			var returnVar = 0;
			switch (this.cssProperty){
				case "top":
					returnVar = this.object.offsetTop;
				break;
				case "left":
					returnVar = this.object.offsetLeft;
				break;
				case "height":
					returnVar = this.object.offsetHeight;
				break;
				case "width":
					returnVar = this.object.offsetWidth;
				break;
				case "opacity":
					return 0;
				break;
				default:
					if (Object.prototype.toString.call(this.cssProperty) == "[object Object]"){
						var object = this.object;
						var execString = "object."+this.cssProperty.getCurrentFunction+"();"
						var returnVar = eval(execString);
						return returnVar;
					}else{
						alert(string+" Not implamented in getProperty.");
					}
				break;
			}
			return returnVar;
		}
	}
}
var onResizeFunctions = Array();
function appendToOnResize(funcName,caller,priority){
	if (caller == undefined){
		caller = null;
	}
	if (priority == undefined){
		priority = getArrayMinumumUnset(onResizeFunctions);
	}
	while (onResizeFunctions[priority] !== undefined){
		priority++;
	}
	onResizeFunctions[priority] = Array(caller,funcName);
	var newArray = Array();
	var i = 0;
	while (i <= onResizeFunctions.length){
		if (undefined !== onResizeFunctions[i]){
			newArray[i] = onResizeFunctions[i];
		}
		i++;
	}
	onResizeFunctions = newArray;
	newArray = null;
	
}
window.onresize = function(){
	for (index in onResizeFunctions){
		var evalVar = "";
		var funcArray = onResizeFunctions[index];
		if (funcArray[0] == null){
			evalVar = funcArray[1]+"();"
		}else{
			var caller = funcArray[0];
			evalVar = "caller."+funcArray[1]+"();";
		}
		eval(evalVar);
	}
}
var onLoadFunctions = Array();
function appendToOnLoad(funcName,caller,priority){
	if (caller == undefined){
		caller = null;
	}
	if (priority == undefined){
		priority = getArrayMinumumUnset(onLoadFunctions);
	}
	while (onLoadFunctions[priority] !== undefined){
		priority++;
	}
	onLoadFunctions[priority] = Array(caller,funcName);
	var newArray = Array();
	var i = 0;
	while (i <= onLoadFunctions.length){
		if (undefined !== onLoadFunctions[i]){
			newArray[i] = onLoadFunctions[i];
		}
		i++;
	}
	onLoadFunctions = newArray;
	newArray = null;
	
}
window.onload = function(){
	for (index in onLoadFunctions){
		var evalVar = "";
		var funcArray = onLoadFunctions[index];
		if (funcArray[0] == null){
			evalVar = funcArray[1]+"();"
		}else{
			var caller = funcArray[0];
			evalVar = "caller."+funcArray[1]+"();";
		}
		eval(evalVar);
	}
}
function getArrayMinumumUnset(array){
	var i = 0;
	while (array[i] !== undefined){
		i++;
	}
	return i;
}
window.size = function(){
	var w = 0;
	var h = 0;
	var th = 0;
	var tw = 0;
	//IE
	if(!window.innerWidth){
		//strict mode
		if(!(document.documentElement.clientWidth == 0)){
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}else{//quirks mode
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}else{//w3c
		w = window.innerWidth;
		h = window.innerHeight;
	}
	var body = document.body,
    html = document.documentElement;
	var th = Math.max(
		body.scrollHeight,
		body.offsetHeight,
		html.clientHeight,
		html.scrollHeight,
		html.offsetHeight
	);
	return {width:w,height:h,totalHeight:th,totalWidth:tw};
}
window.viewportSize = function(){
	var elem = (document.compatMode === "CSS1Compat") ? 
		document.documentElement :
		document.body;
	return {height:elem.clientHeight,width:elem.clientWidth}
}

window.getScroll = function(){
    var x = 0, y = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        y = window.pageYOffset;
        x = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        y = document.body.scrollTop;
        x = document.body.scrollLeft;
    } else if( document.documentElement && 
    ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        y = document.documentElement.scrollTop;
        x = document.documentElement.scrollLeft;
    }
	return {x:x,y:y}
};
var onScrollFunctions = Array();
function appendToOnScroll(funcName,caller,priority){
	if (caller == undefined){
		caller = null;
	}
	if (priority == undefined){
		priority = getArrayMinumumUnset(onScrollFunctions);
	}
	while (onScrollFunctions[priority] !== undefined){
		priority++;
	}
	onScrollFunctions[priority] = Array(caller,funcName);
	var newArray = Array();
	var i = 0;
	while (i <= onScrollFunctions.length){
		if (undefined !== onScrollFunctions[i]){
			newArray[i] = onScrollFunctions[i];
		}
		i++;
	}
	onScrollFunctions = newArray;
	newArray = null;
}
window.onscroll = function(){
	for (index in onScrollFunctions){
		var evalVar = "";
		var funcArray = onScrollFunctions[index];
		if (funcArray[0] == null){
			evalVar = funcArray[1]+"();"
		}else{
			var caller = funcArray[0];
			evalVar = "caller."+funcArray[1]+"();";
		}
		eval(evalVar);
	}
	return true;
}








var debugEnable = true;
var debugDiv = null;
function debug(text){
	if (debugEnable){
		if (!(debugDiv)){
			debugDiv = document.getElementById("debug");
		}
		if (debugDiv){
			debugDiv.innerHTML = debugDiv.innerHTML += text + "<br/>";
		}
	}
}
function clearDebug(){
	if (debugEnable){
		if (debugDiv){
			debugDiv.innerHTML = "";
		}
	}
}




function doFunctionIn(array,funcName){
	for (index in array){
		eval("array[index]."+funcName+"();");
	}
}

function addPreZeros(string,totalLength){
	var txt = new String(string);
	var appendCount = totalLength - txt.length;
	var appendString = "";
	var num = 0;
	while (num < appendCount){
		txt = num + txt;
		num++;
	}
	return txt;
}
