function getAllElements(nodes){
	for(var i=0,x=[];i<nodes.length;i++) if(nodes[i].nodeType == 1) x.push(nodes[i]);	
	return x;
}

Array.prototype.indexOf = function(obj){
	for(var i=0;i<this.length;i++) if(this[i] == obj) return i;
	return -1;
}

/* Animate */

Animate = {
	sequences : [],
	register : function(o){
		return this.sequences.push(o) - 1;
	},
	destroy : function(id){
		this.sequences[id] = null;
	},
	findSeq : function(id){
		return this.sequences[id];
	},
	
	scrollheight : function(oHTML, value){
		oHTML.style.height = value + "px";
		oHTML.scrollTop = 100000;
	},
	
	scrolltop : function(oHTML, value){
		oHTML.scrollTop = value;
	},

	height : function(oHTML, value){
		oHTML.style.height = value + "px";
	},

	fade : function(oHTML, value){
		if(document.all) oHTML.style.filter = "alpha(opacity=" + parseInt(value*100) + ")";
		else oHTML.style.opacity = value;
	}
}

function Anim(oHTML, type, fromValue, toValue, animtype, frames, interval, onfinish, userdata){
	this.uniqueId = Animate.register(this);
	this.method = Animate[type];

	this.oHTML = oHTML;
	this.onfinish = onfinish;
	this.userdata = userdata;
	this.interval = interval;
	this.frames = frames;
	
	//Compile steps
	this.steps = [fromValue];
	this.step = 0;
	
	var steps = parseInt(frames);
	var scalex = (toValue - fromValue)/((Math.pow(steps,2)+2*steps+1)/(4*steps));
	for(var i=0;i<frames;i++){
		if(animtype == 0 && !value) var value = (toValue - fromValue)/frames; 
		else if(animtype == 1) var value = scalex*Math.pow(((steps-i))/steps,3); 
		else if(animtype == 2) var value = scalex * Math.pow(i/frames, 3); 

		//this.steps.push(Math.max(0, this.steps[this.steps.length-1] + value - (i==0?1:0)));
		this.steps.push(Math.max(0, this.steps[this.steps.length-1] + value)) - (i==0?1:0)
	}
	this.steps[this.steps.length-1] = Math.max(1, toValue-1);

	//Stop
	this.stop = function(){
		clearTimeout(this.timer);
		Animate.destroy(this.uniqueId);
	}

	//Play
	AnimateStep(0, this.uniqueId);
}
	
function AnimateStep(step, uniqueId){
	var o = Animate.findSeq(uniqueId);
	if(!o) return;
	
	try{o.method(o.oHTML, o.steps[step]);}catch(e){}

	if(step < o.frames) o.timer = setTimeout('AnimateStep(' + (step+1) + ', ' + uniqueId + ')', o.interval);
	else if(o.onfinish) o.onfinish(o.oHTML, o.userdata);
}
