function animator(){
	this.elms = new Object();
	
	this.addElement = function(f){
		this.elms[f.getUID()] = f;
		setTimeout("anim.animate('"+f.getUID()+"')",f.stepDelay);
	}
	
	this.removeElement = function(f){
		this.elms[f.getUID()] = null;
	}
	
	this.animate = function(id){
		elm = this.elms[id];
		if(elm && elm.animate()){
			setTimeout("anim.animate('"+elm.getUID()+"')",elm.stepDelay);
		}
	}
}
anim = new animator();
function changeElement(e1,e2){
	this.e1 = e1;
	this.e2 = e2;
	this.after = null;
	
	this.activateAfter = function(elm){
		this.after = elm;
	}
	
	this.start = function(){
		this.e1.parentNode.insertChildBefore(this.e1,this.e2);
		this.e1.parentNode.removeChild(this.e1);
		if(this.after) this.after.start()
	}
}

function turnOff(e1){
	this.e1 = e1;
	this.after = null;
	this.rem = false;
	
	this.remove = function(){
		this.rem = true;
	}
	
	this.activateAfter = function(elm){
		this.after = elm;
	}
	
	this.start = function(){
		this.e1.style.display='none';
		if(this.after){
			this.after.start();
		}
		
		if(this.rem){
			this.e1.parentNode.removeChild(this.e1);
		}
	}
}

function fader(elm){
	this.elm = elm;
	this.id = elm.id+'fader';
	this.stepDelay = 60;
	this.direction = 0;
	this.progress = 0;
	this.speed = 5;
	this.after = null;
	
	this.setDuration = function(ms){
		this.stepDelay = 33;
		this.speed = Math.max(1,parseInt(100/(ms/this.stepDelay)));
	}
	
	this.fadeIn = function(){
		this.direction = 1;	
		this.progress = 0;
		lightCore.setOpacity(this.elm,this.progress);
	}
	
	this.fadeOut = function(){
		this.direction = -1;
		this.progress = 100;
		lightCore.setOpacity(this.elm,this.progress);
	}
	
	this.start = function(){
		anim.addElement(this);
	}
	
	this.animate = function(){
	
		this.progress = this.progress+this.direction*this.speed;

		if(this.progress > 100) this.progress = 100;
		if(this.progress < 0) this.progress = 0;
		
		lightCore.setOpacity(this.elm,this.progress);
		
		if(this.progress==0 || this.progress==100){
			anim.removeElement(this);
			lightCore.clearOpacity(this.elm);
			
			if(this.after) this.after.start()
			return false;
		}else{
			return true;
		}
	}
	
	this.activateAfter = function(elm){
		this.after = elm;
	}
	
	this.getUID = function(){
		return this.id;
	}
}

function slider(elm){
	this.elm = elm;
	this.id = elm.id+'slide';
	
	// Public variables (settings)
	this.m_iSpeed           = 10;
	this.m_iCounterIncrease = 1;
	this.m_iDegrees         = 90;
	
	// Private variables
	this.m_iToX    = null; // X value to slide to.
	this.m_iToY    = null; // Y value to slide to.
	this.m_iFromX  = null;
	this.m_iFromY  = null;
	
	this.m_iIntervalId = null;
	this.m_iCounter    = null;

   // Private functions
   this.start = function(iToX, iToY){
	   this.stopSlide();
	   this.m_iCounter = 1;
	
	   // Save the div start position
	   this.m_iFromX = (document.layers) ? this.elm.left : this.elm.offsetLeft;
	   this.m_iFromY = (document.layers) ? this.elm.top  : this.elm.offsetTop;
	
	   // Set to positions
	   this.m_iToX = (iToX == null) ? this.m_iFromX : iToX;
	   this.m_iToY = (iToY == null) ? this.m_iFromY : iToY;
	   
	   // If div is already there
	   if(this.m_iFromX == this.m_iToX && this.m_iFromY == this.m_iToY)
	      this.m_iCounter = this.m_iDegrees;
	
		anim.addElement(this);
	}
	
	this.getUID = function(){
		return this.id;
	}
	
   	this.stopSlide = function(){
		if(this.m_iIntervalId != null){
		   window.clearInterval(this.m_iIntervalId);
		   this.m_iIntervalId = null;
		}
	}
	
	this.activateAfter = function(elm){
		this.after = elm;
	}
	
	this.animate = function(){
	   var iInc = Math.sin( (this.m_iCounter/90)*(Math.PI/2) );
	
	   var oDiv = null;
	   oDiv = this.elm;
	   if(document.all || document.getElementById) // IE & NS6
	      oDiv = this.elm.style;
	
	   oDiv.left = this.m_iFromX + (iInc * (this.m_iToX - this.m_iFromX));
	   oDiv.top  = this.m_iFromY + (iInc * (this.m_iToY - this.m_iFromY));
	
	   this.m_iCounter += this.m_iCounterIncrease;
	
	   if(this.m_iCounter < this.m_iDegrees) return true;
	   else{
	      if(this.m_iDegrees == 90 || this.m_iDegrees == 270){
	         oDiv.left = this.m_iToX; 
	         oDiv.top  = this.m_iToY;
	      }
	      else if(this.m_iDegrees == 180 || this.m_iDegrees == 360){
	         oDiv.left = this.m_iFromX; 
	         oDiv.top  = this.m_iFromY;
	      }
	      this.stopSlide();
	      return false;
	   }
	}
}