/*  Returns if the current browser is an iE.
**/

function isIe()
{
	return  0/*@cc_on || @_jscript_version > 4 @*/;
}

function LetterAnimation(height,offset,letter)
{
	this.image = letter;
	this.topOffset = offset;
	this.maxY = height;
		
	this.animating = true;
		
	this.init = function()
	{
		this.initialDelay = 500;

		this.currentY = 0;
		this.delay = 40;
		this.delayVariance = 40;
		this.stepY = 6;

		this.reflectFactor = .6;
		this.reflectY = this.maxY - this.reflectFactor * this.maxY;

		this.blendSteps = 20;
		this.blendStep = 0;
		this.blendDelay = 70;
		this.blendFactor = .7;

	}
	
	this.resetImage = function()
	{
		this.image.style.top = this.topOffset+'px';
		this.setOpacity(1);
	}
	
	this.setOpacity = function(opacity)
		{
			if(isIe())
				this.image.parentNode.style.filter = 'alpha(opacity:'+ (opacity * 100)+')';

				else
					this.image.parentNode.style.opacity = opacity;
		}
	
	this.animateDown = function()
	{
		if(!this.animating)
			return;
			
		this.currentY += this.stepY;
		
		if(this.currentY > this.maxY)
			this.currentY = this.maxY;
			
		this.image.style.top = (this.currentY+this.topOffset)+'px';
		
		if(this.currentY < this.maxY)
		{
			window.setTimeout('animation.animateDown()', this.delay);
			this.delay--;
		}
			
		else
			if(this.reflectY < this.maxY - 5)
			{
				this.animateUp();
			}	
			
			else
			{
				window.setTimeout('animation.blendOut()', this.delay);
			}
	}
	
	this.animateUp = function()
	{
		if(!this.animating)
			return;
			
		this.currentY -= this.stepY;
		
		this.image.style.top = (this.currentY+this.topOffset)+'px';
		
		if(this.currentY < this.reflectY)
			this.currentY = this.reflectY;
		
		if(this.currentY > this.reflectY)
		{
			window.setTimeout('animation.animateUp()', this.delay);
			this.delay+=1.5;
		}
			
			else
			{
				this.reflectY = this.maxY-(this.maxY-this.reflectY) * this.reflectFactor;
				window.setTimeout('animation.animateDown()', this.delay);
			}
		
	}
	
	this.blendOut = function()
	{
		if(!this.animating)
			return;
		
		this.setOpacity(1 - this.blendFactor * this.blendStep / this.blendSteps);
			
			if(this.blendStep < this.blendSteps)
			{
				this.blendStep++;
				window.setTimeout('animation.blendOut()', this.blendDelay);
			}
	}
	
	this.image.parentNode.animation = this;
	
	this.image.parentNode.onmouseover = function()
	{
		this.animation.animating = false;
		this.animation.init();
		this.animation.resetImage();
	}
	
	this.image.parentNode.onmouseout = function()
	{
		this.animation.animating = true;
		this.animation.animateDown();
	}
	
	this.init();
	
	window.setTimeout('animation.animateDown()', this.initialDelay);
	
	
}
