/**
 * @author Larsson
 * @copyright 2009
 **/
 
 var slide = function(id) {
 	this.obj		= id;
 	this.flag		= "up";
 	this.speed		= null;
 	this.height		= null;
 	this.moveing	= false;
 	this.startHeight= null;
 	this.startTime	= null;
 	this.endHeight	= null;
 	var self		= this;
 	
 	this.up = function(endHeight, speed, callback)	{
 		if(this.moveing)
 			return;
 			
 		this.time		= new Date();
 		this.speed		= speed;
 		this.moveing	= true;
 		this.endHeight	= endHeight;
 		this.startTime	= this.time.valueOf();
 		this.flag		= "up";
 		this.moveing	= true;
 		
	 	this.applyHeight(callback);	
 	}
 	
 	this.down = function(endHeight, speed, callback, startHeight)	{
 		if(this.moveing)
 			return;
 			
 		this.time		= new Date();
 		this.speed		= speed;
 		this.moveing	= true;
 		this.endHeight	= endHeight;
 		this.startTime	= this.time.valueOf();
 		this.flag		= "down";
 		this.moveing	= true;
 		
 		this.startHeight = (startHeight ? this.obj.offsetHeight : null);
	 	this.applyHeight(callback);	 		
 	}
 	
 	this.toggle = function(startHeight, endHeight, speed, callback1, callback2)	{	 
 		if(this.flag == "up")
			this.down(endHeight, speed, callback2);
		else
			this.up(endHeight, speed, callback1);
 	}
 	
 	this.applyHeight = function(callback)	{
 		this.time	= new Date();
 		this.height	= Math.round((this.time.valueOf() - this.startTime)/5000 * this.speed);
		
 		if(this.startHeight)	{
 			this.height = this.height + this.startHeight;
 		}	
 	
		if(this.flag == "down") 	{
			this.height = Math.min(this.endHeight, this.height);
		}
		else if(this.flag == "up")
			this.height = Math.max(this.endHeight - this.height, 0);
 	
 		this.obj.style.height = this.height + "px";
 		
 		if(((this.height < this.endHeight) && this.flag == "down") || ((this.height > 0) && this.flag == "up"))	{
	 		setTimeout(function()	{
	 			self.applyHeight(callback);
	 		}, 1);
 		}
	 	else	{
 			this.moveing = false;
 			if(callback)
 				callback();
				
 			return true;
		}
 	}
 }
 
/*
Event.domReady.add(function()	{
	var hej = window.hej = new slide(document.getElementById("slider"));
});
 
document.onclick = function() {
	hej.toggle(0, document.getElementById("slideContainer").offsetHeight, 2000);
};
*/