function e(id){
	return document.getElementById(id);
}

function callFader(container,id,cellheight,pausetime,fadetime) {
	this.container = container;
	this.id = id;
	this.animationTimeout = null;
	this.cellHeight = cellheight;
	this.pauseTime = pausetime;
	this.fadeTime = fadetime;
	this.framesPerSec = 20;
	this.transparencyStep = 100 / ((this.fadeTime / 1000) * this.framesPerSec);
	this.fadeUp = false;
	this.animateForward = true;
	this.currTransparency = 100;
	
	
	this.setTransparency = function (percentage) 
	{
		var Fader = document.getElementById(this.id);
		if(!Fader){return false;}
		if (Fader.filters != null) {
			if (typeof Fader.filters == "[object]") { //if IE6+
				Fader.filters[0].opacity = percentage;
			} else { //else if IE5.5-
				Fader.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+percentage+")";
			}
		} else if (Fader.style.MozOpacity) {
			Fader.style.MozOpacity = percentage / 101;
		} else if (Fader.style.KhtmlOpacity) {
			Fader.style.KhtmlOpacity = percentage / 100;
		}
	}

	
	this.animateFader = function ()
	{	
		clearTimeout(this.animationTimeout);
		
		if (this.fadeUp == false) {
		
			this.currTransparency -= this.transparencyStep;
			
			if (this.currTransparency <= 0) {
				this.fadeUp = true;
				this.currTransparency = 0;
			}
		} else {
			this.currTransparency += this.transparencyStep
			if (this.currTransparency >= 100) {
			  this.fadeUp = false;
				this.currTransparency = 100;
			}
		}
		
		this.setTransparency(this.currTransparency);
		
		if (this.currTransparency == 0) {
			if (this.animateForward == true) {
				this.showNextImage(); 
			} else {
				this.showPrevImage();
			}
		}
		if (this.currTransparency == 100) {	
			
			var _self = this;
			this.animationTimeout = setTimeout(function(){ _self.animateFader(); }, this.pauseTime);
			
			return;
		} else {
			var _self = this;
			this.animationTimeout = setTimeout(function(){ _self.animateFader(); }, 1000 / this.framesPerSec);
		}
	}
	
	
	
	this.showNextImage = function () 
	{
		var Fader = document.getElementById(this.container);
		if(!Fader){return false;}
		var topMargin = 0;
		if (Fader.style.marginTop != '') {
			topMargin = parseInt(Fader.style.marginTop.replace('px', ''));
		}
		var reset_height =  0 - Fader.offsetHeight + this.cellHeight;

		if (Math.abs(topMargin-reset_height) < 15) {	
			topMargin = 0;
		} else {
			topMargin -= this.cellHeight;
		}
		Fader.style.marginTop = topMargin + 'px';
	}
	
	
	
	this.jumpToNextImage = function ()
	{
		clearTimeout(this.animationTimeout);
		var _self = this;
		this.showNextImage();
		this.setTransparency(100);
		this.animateForward = true;
		this.animationTimeout = setTimeout(function(){ _self.animateFader(); }, this.pauseTime);
	}

		
		
		
	this.jumpToPrevImage = function () 
	{
		clearTimeout(this.animationTimeout);
		var _self = this;
		this.showPrevImage();
		this.setTransparency(100);
		this.animateForward = false;
		this.animationTimeout = setTimeout(function(){ _self.animateFader(); }, this.pauseTime);
	}	
	
	
	
	this.showPrevImage = function () 
	{
		var Fader = document.getElementById(this.container);
		if(!Fader){return false;}
		var topMargin = 0;
		if (Fader.style.marginTop != '') topMargin = parseInt(Fader.style.marginTop.replace('px', ''));
		if (topMargin == 0) {
			topMargin = 0 - Fader.offsetHeight + this.cellHeight;
		} else {
			topMargin += this.cellHeight;
		}
		Fader.style.marginTop = topMargin + 'px';
	}
}
