
	function animate()
	{
		this.animations = new Array();
		this.animating = false;
		this.interval = 30;	
	}
	
	animate.prototype.stopAll = function()
	{
		hiID = -1;
		this.animations = new Array();	
	}
	
	animate.prototype.stopAnimation = function( el, animType )
	{
		var l = this.animations.length;
		for( var i=0; i<l; i++ ) {
			if( this.animations[ i ].el == el
			 && this.animations[ i ].animType == animType ) {
			 	this.animations.splice( i, 1 );
			 	l--;
			 	i--;	
			}
		}
	}
	
	animate.prototype.addAnimation = function( el, animType, startTime, endTime, startValue, endValue )
	{
		var now = new Date();
		now = now.getTime();
		
		startTime += now;
		endTime += now;
		
		this.animations[ this.animations.length ] = { 'el': el,
													  'animType': animType,
													  'startTime': startTime,		
													  'endTime': endTime,
													  'startValue': startValue,
													  'endValue': endValue };
		if( !this.animating ) {
			this.animating = true;
			this.startLoop();
		}													  
	}
	
	animate.prototype.doScroll = function( anim, now )
	{
		var valx = anim.startValue[0]  
				+ ( ( anim.endValue[0] - anim.startValue[0] ) 
				  * ( ( now - anim.startTime ) 
				  	  / ( anim.endTime - anim.startTime ) ) );
		var valy = anim.startValue[1] 
				+ ( ( anim.endValue[1]  - anim.startValue[1]  ) 
				  * ( ( now - anim.startTime ) 
				  	  / ( anim.endTime - anim.startTime ) ) );
		anim.el.scrollTo( Math.floor( valx ), Math.floor( valy ) );
	}
	
	animate.prototype.doStylePixelValue = function( anim, now )
	{
		var val = anim.startValue  
				+ ( ( anim.endValue - anim.startValue ) 
				  * ( ( now - anim.startTime ) 
				  	  / ( anim.endTime - anim.startTime ) ) );
		anim.el.style[ anim.animType ] = ( Math.floor( val ) ) + 'px';
	}
	
	animate.prototype.doTransparency = function( anim, now )
	{
		var val = anim.startValue 
				+ ( ( anim.endValue - anim.startValue ) 
				  * ( ( now - anim.startTime ) 
				  	  / ( anim.endTime - anim.startTime ) ) );
		if( val == 0 ) {
			anim.el.style.display = 'none';
		}
		else {
			anim.el.style.display = 'block';	
		}
		anim.el.style.opacity = val;
		anim.el.style.filter = 'alpha(opacity=' + Math.floor( val * 100 ) + ');';
	}
	
	animate.prototype.getTransparency = function( el )
	{
		if( el.style.display == 'none' ) {
			return 0;
		}
		if( el.style.opacity.length ) {
			return 1 * el.style.opacity;
		}
		if( el.style.filter.length ) {
			var m = el.style.filter.match( /opacity=(\d+)/ );
			return m[ 1 ] / 100;
		}
		return 1;
	}
	
	animate.prototype.startLoop = function()
	{
		var self = this;
		var loop = function()
		{
			var now = new Date();
			now = now.getTime();
		
			var l = self.animations.length;
			for( var i=0; i<l; i++ ) {
				var anim = self.animations[ i ];
				if( anim.endTime <= now ) {				
					switch( anim.animType ) {
						case 'top':
						case 'left':
						case 'right':
						case 'bottom':
							self.doStylePixelValue( anim, anim.endTime );	
							break;
						case 'scroll':
							self.doScroll( anim, anim.endTime );	
							break;
						case 'transparency':
							self.doTransparency( anim, anim.endTime );	
							break;
					}
					
					self.animations.splice( i, 1 );
					l--;
					i--;
					continue;
				}
				if( anim.startTime <= now ) {			
					switch( anim.animType ) {
						case 'top':
						case 'left':
						case 'right':
						case 'bottom':
							self.doStylePixelValue( anim, now );	
							break;
						case 'scroll':
							self.doScroll( anim, now );	
							break;
						case 'transparency':
							self.doTransparency( anim, now );	
							break;
					}					
				}
			}
			
			self.animating = self.animations.length > 0;
			if( self.animating ) {				
				setTimeout( loop, self.interval );
			}			
			else {
				hiID = -1;
			}
		};
		setTimeout( loop, 1 );
	}
	
	var anim = new animate();
