function Animation (oElement){
	this.Element = oElement
	this.AnimationInterval = null;
}
function string2Number(cStr){
	var nNumber = (cStr.replace(/\D{0,}/g,'') * 1)
	return nNumber
}
function makeLighter(cHexValue) {
  var r=Math.min(Math.round(HexToR(cHexValue)*1.07),255);
  var g=Math.min(Math.round(HexToG(cHexValue)*1.07),255);
  var b=Math.min(Math.round(HexToB(cHexValue)*1.07),255);
  var cHex = RGBtoHex(r,g,b)
  return cHex;
}
function makeDarker(cHexValue) {
  var r=Math.round(HexToR(cHexValue)*0.913);
  var g=Math.round(HexToG(cHexValue)*0.913);
  var b=Math.round(HexToB(cHexValue)*0.913);
  var cHex = RGBtoHex(r,g,b)
  return cHex;
}
function HexToR(h) { return parseInt((cutHex(h)).substring(0,2),16) }
function HexToG(h) { return parseInt((cutHex(h)).substring(2,4),16) }
function HexToB(h) { return parseInt((cutHex(h)).substring(4,6),16) }
function cutHex(h) { return (h.charAt(0)=="#") ? h.substring(1,7) : h}
function RGBtoHex(R,G,B) {return toHex(R)+toHex(G)+toHex(B)}
function toHex(N) {
 if (N==null) return "00";
 N=parseInt(N); if (N==0 || isNaN(N)) return "00";
 N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
 return "0123456789ABCDEF".charAt((N-N%16)/16)
      + "0123456789ABCDEF".charAt(N%16);
}
Animation.prototype.colorFade = function(cHexColor, nSpeed ,nFadeDegree,nMaxFades){
	var obj = this
	this.ColorFadeObject = new Object();
	this.ColorFadeObject.originalHexValue = cHexColor;
	this.ColorFadeObject.maxFadeDegree = nFadeDegree;
	this.ColorFadeObject.currentFadeDegree = 0;
	this.ColorFadeObject.maxFades = nMaxFades;
	this.ColorFadeObject.fadeCounter = 0;
	this.AnimationInterval = setInterval(function(){obj.doColorFade();}, nSpeed)
}
Animation.prototype.doColorFade = function(){
	var cCurrentBackgroundColor = this.Element.style.backgroundColor;
	if(cCurrentBackgroundColor == ''){
		cCurrentBackgroundColor = this.ColorFadeObject.originalHexValue
	}
	if(this.ColorFadeObject.fadeCounter < this.ColorFadeObject.maxFades){
		if(this.ColorFadeObject.currentFadeDegree < this.ColorFadeObject.maxFadeDegree){
			this.Element.style.backgroundColor = makeLighter(cCurrentBackgroundColor)
		}else{
			this.Element.style.backgroundColor = makeDarker(cCurrentBackgroundColor)
		}
		this.ColorFadeObject.currentFadeDegree++;
		if(this.ColorFadeObject.currentFadeDegree ==  (this.ColorFadeObject.maxFadeDegree * 2)){
			this.ColorFadeObject.currentFadeDegree=0;
		}
		this.ColorFadeObject.fadeCounter++
	}else{
		clearInterval(this.AnimationInterval)
		this.Element.style.backgroundColor = 'transparent'
	}
}
Animation.prototype.pulse = function(nSpeed , nGrowthRatePercent, nGrowthSizePercent, nTotalPulses){
	var obj = this
	var nPercentMultiplier = ((nGrowthSizePercent/100)+1);
	this.PulseObject = new Object();
	this.PulseObject.originalWidth = this.Element.offsetWidth
	this.PulseObject.originalHeight = this.Element.offsetHeight
	this.PulseObject.totalPulses = nTotalPulses
	this.PulseObject.pulseCounter = 0;
	this.PulseObject.growthRatePercent = nGrowthRatePercent;
	this.PulseObject.desiredWidthMax = Math.round(this.PulseObject.originalWidth * nPercentMultiplier)
	this.PulseObject.desiredHeightMax = Math.round(this.PulseObject.originalHeight * nPercentMultiplier)
	this.PulseObject.desiredWidthMin = Math.round(this.PulseObject.originalWidth - (this.PulseObject.originalWidth * (nGrowthSizePercent/100)))
	this.PulseObject.desiredHeightMin = Math.round(this.PulseObject.originalHeight - (this.PulseObject.originalHeight * (nGrowthSizePercent/100)))
	this.Element.style.width = this.PulseObject.originalWidth
	this.Element.style.height = this.PulseObject.originalHeight
	this.AnimationInterval = setInterval(function(){obj.doPulse();}, nSpeed)
}
Animation.prototype.doPulse = function(){
	var nCurrentWidth = string2Number(this.Element.style.width)
	var nCurrentHeight = string2Number(this.Element.style.height)
	if(this.PulseObject.pulseCounter <= this.PulseObject.totalPulses){
		if(nCurrentWidth <= this.PulseObject.desiredWidthMax){
			this.Element.style.width =Math.round(nCurrentWidth + (nCurrentWidth * (this.PulseObject.growthRatePercent /100)))
			this.Element.style.height = Math.round(nCurrentHeight + (nCurrentHeight * (this.PulseObject.growthRatePercent /100)))
		}else if(nCurrentWidth >= this.PulseObject.desiredWidthMin){
			this.Element.style.width = Math.round(nCurrentWidth - (nCurrentWidth * (this.PulseObject.growthRatePercent /100)))
			this.Element.style.height = Math.round(nCurrentHeight - ( nCurrentHeight * (this.PulseObject.growthRatePercent /100)))
			//clearInterval(this.pulseInterval);
		}
		this.PulseObject.pulseCounter++
	}else{
		clearInterval(this.AnimationInterval);
	}
}
Animation.prototype.wiggle = function(nSpeed , nWigglePixels, nTotalWiggles){
	var obj = this
	this.WiggleObject = new Object();
	this.WiggleObject.originalMargin = (this.Element.style.marginLeft != '' ? string2Number(this.Element.style.marginLeft) : 0);
	this.WiggleObject.maxMarginLeft = this.WiggleObject.originalMargin - nWigglePixels
	this.WiggleObject.maxMarginRight = this.WiggleObject.originalMargin + nWigglePixels
	this.Element.style.marginLeft = this.WiggleObject.originalMargin
	this.WiggleObject.totalWiggles = nTotalWiggles
	this.WiggleObject.wiggleCounter = 0;
	this.AnimationInterval = setInterval(function(){obj.doWiggle();}, nSpeed)
}
Animation.prototype.doWiggle = function(){
	var nCurrentMargin= string2Number(this.Element.style.marginLeft);
	if(this.WiggleObject.wiggleCounter <= this.WiggleObject.totalWiggles){
		if(nCurrentMargin <= this.WiggleObject.maxMarginLeft){
			this.Element.style.marginLeft = nCurrentMargin + 1
		}else{
			this.Element.style.marginLeft = nCurrentMargin - 1
		}
		this.WiggleObject.wiggleCounter++
	}else{
		clearInterval(this.AnimationInterval);
	}
}
Animation.prototype.slideDiv = function(nSpeed,nGrowthInPixels){
	var obj = this
	if(!this.SlideObject)
		this.SlideObject = new Object();
	this.Element.style.overflow = 'hidden'
	this.SlideObject.growthRate = nGrowthInPixels
	this.onAnimationComplete = null
	if(this.Element.style.display == 'none'){
		this.SlideObject.currentHeight = 0
		if(typeof(this.SlideObject.originalHeight) == 'undefined'){
			this.SlideObject.originalHeight = string2Number(this.Element.style.height);
		}
		this.SlideObject.targetHeight = this.SlideObject.originalHeight
		this.Element.style.height = this.SlideObject.currentHeight + 'px'		
		this.AnimationInterval = setInterval(function(){obj.doSlideDiv('open');}, nSpeed)
	}else{
		this.SlideObject.originalHeight = string2Number(this.Element.style.height);
		this.SlideObject.currentHeight = this.SlideObject.originalHeight
		this.SlideObject.targetHeight = 0
		this.Element.style.height = this.SlideObject.currentHeight + 'px'
		this.AnimationInterval = setInterval(function(){obj.doSlideDiv('close');}, nSpeed)
	}
}
Animation.prototype.doSlideDiv = function(cOpenClose){
	if(cOpenClose == 'open'){
		this.Element.style.display = '';
		var nNewHeight  = (this.SlideObject.currentHeight + this.SlideObject.growthRate);
		this.SlideObject.currentHeight = (nNewHeight > this.SlideObject.originalHeight ? this.SlideObject.originalHeight : nNewHeight);
		this.Element.style.height = this.SlideObject.currentHeight + 'px'
		if(this.SlideObject.currentHeight >= this.SlideObject.targetHeight){
			clearInterval(this.AnimationInterval);
			if(this.onAnimationComplete != null){
				this.onAnimationComplete(this.Element);
			}			
		}
	}else{
		this.SlideObject.currentHeight = (this.SlideObject.currentHeight - this.SlideObject.growthRate)
		if(this.SlideObject.currentHeight < 0){
			this.SlideObject.currentHeight = 0			
		}
		this.Element.style.height = this.SlideObject.currentHeight + 'px'
		if(this.SlideObject.currentHeight <= this.SlideObject.targetHeight){
			this.Element.style.display = 'none'
			this.Element.style.height = this.SlideObject.originalHeight
			clearInterval(this.AnimationInterval);
			if(this.onAnimationComplete != null){
				this.onAnimationComplete(this.Element);
			}			
		}
	}
}
Animation.prototype.slideTo = function(cLocation, nSpeed, nPixelShift){
	var obj = this
	if(!this.SlideObject)
		this.SlideObject = new Object();
	this.Element.style.overflow = 'hidden'
	this.onAnimationComplete = null;
	var arrWindowSize = getWindowSize();
	this.targetY = ((Math.floor(arrWindowSize[0]/2)) - (string2Number(this.Element.style.width) / 2 ))
	this.AnimationInterval = setInterval(function(){obj.doSlideTo(cLocation,nPixelShift);}, nSpeed)
}
Animation.prototype.doSlideTo = function(cLocation,nPixelShift){
	if(cLocation == 'center'){
		var nLeft = (string2Number(this.Element.style.left) + nPixelShift);
		this.Element.style.left = nLeft + 'px'
		if(nLeft >= this.targetY){
			clearInterval(this.AnimationInterval);
		}
	}
}