// BANNER FADER

function bannerFader(container,id,cellheight,pausetime,fadetime) {
	this.container = container;
	this.id = id;
	this.pauseTime = pausetime;
	this.fadeTime = fadetime;
	this.framesPerSec = 20;
	this.transparencyStep = 100 / ((this.fadeTime / 1000) * this.framesPerSec);
	this.zIndexRangeStart = 101;
	this.int_z = 100;
	this.int_alpha= 0;
	this.int_anim_timeout = -1;
	this.current_id = -1;
	this.bln_is_first = true;
	
	this.setTransparency = function (percentage) 
	{
		
		var Fader = e(this.id + "-" +  this.current_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.showNextImage = function () 
	{
		this.current_id++;
		
		
		if(!e(this.id.split("testimonial_fader").join("img-fader") + "-" +  this.current_id)){
			this.current_id = 1;
		}
		
		//updateImageLink(this.current_id);
		
		var fader_value = e(this.id.split("testimonial_fader").join("img-fader") + "-" +  this.current_id);
		var Fader = e(this.id + "-" +  this.current_id);
		this.int_z++;
		Fader.style.zIndex = this.int_z;
		
		
		if (this.bln_is_first ){
			
			this.bln_is_first  = false;
			this.setTransparency(100) 
			this.onFadeComplete();
		} else {
			this.setTransparency(0) 
			this.int_alpha = 0;
			this.fadeCurrentIn();
		}
	}
	
	
	this.fadeCurrentIn = function(){
		this.int_alpha+=5
		this.int_alpha = Math.min(100,this.int_alpha);
		this.setTransparency(this.int_alpha) 
		if (this.int_alpha == 100){
			this.onFadeComplete();
		} else {		
		var _self = this;
			var int_dummy =  setTimeout(function(){ _self.fadeCurrentIn(); },  1000 / this.framesPerSec);
		}
	}
	
	this.onFadeComplete = function(){
		var _self = this;
		var int_dummy = setTimeout(function(){ _self.showNextImage(); }, 1 * this.fadeTime);		
	}
}



function weatherFader(container,time,frames) {
	this.container = container;
	this.time = time;
	this.num_frames = frames;
	this.start_frame = 0;
	this.previous_frame = 1;
	
	this.animationTimeout = null;
	this.framesPerSec = 20;
	this.transparencyStep = 100 / ((this.time / 4000) * this.framesPerSec);
	this.fadeUp = false;
	this.animateForward = true;
	this.currTransparency = 100;
	
	
	this.setTransparency = function (percentage) 
	{	
		var Fader = document.getElementById(this.container + this.start_frame);
	
		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) {
			this.goNextFrame();
		} 
		
		if (this.currTransparency == 100) {	
			var _self = this;
			this.animationTimeout = setTimeout(function(){ _self.animateFader(); }, this.time);
			
			return;
			
		} else {
			var _self = this;
			this.animationTimeout = setTimeout(function(){ _self.animateFader(); }, 1000 / this.framesPerSec);
		}
	}
  
	
	this.goNextFrame = function() {		
		if (document.getElementById(this.container + this.start_frame)) {
				document.getElementById(this.container + this.start_frame).className="hide";	
			}
		
		if  (this.start_frame != this.num_frames) {
			this.start_frame++;
			this.setTransparency(0);
			if (document.getElementById(this.container + this.start_frame)) {
				document.getElementById(this.container + this.start_frame).className="show";
			}
			
			this.setTransparency(0);
		}
		else {
			this.start_frame = 1;
			if (document.getElementById(this.container + this.start_frame)) {
				document.getElementById(this.container + this.start_frame).className="show";
			}
		}	
	}
	this.animateFader();
}
