// JavaScript Document
function Blender(elemId, freq, timeout, wait, fade) {
	this.elem = $(elemId);
	this.elem2 = $$("#" + elemId + " div")[0];
	this.freq = 1000/freq;
	this.timeout = timeout * 1000;
	this.wait = wait * 1000;
	this.fade = fade * 1000;
	this.loaded = false;
	this.init = false;
	this.abstOben = 0; /*136 ist Rand Content */
	this.dt = 0;
	this.st = 0;
	this.gt = function() {return (new Date()).getTime();};
	this.ival = false;
	
	this.loaded = function() {
		this.loaded = true;
	} 
	this.stop = function() {
		this.elem.setStyle('display','none');
		this.elem2.setStyle('display','none');
		
		window.clearInterval(this.ival);   
	}
	this.start = function() {
		var self = this;
		this.ival = window.setInterval(function(){self.blend()}, this.freq);
	}
	this.adjust = function(elem) {
		var e = $(elem);
		if(e) {
			this.elem2.setStyle('height','0px');
			this.elem.setStyle('top','0'); /* 136px */
		}
	}
	this.redisplay = function(){
		this.init = false;
		this.start();
	};
	this.blend = function() {
		if(!this.init) {
			this.init = true;
			if(this.wait<=0) {
				this.wait *= -1;
			}
			this.st = this.gt();
			this.elem.setStyle('display','block');
			this.elem.setStyle('opacity','1');
			this.elem2.setStyle('display','block');
			this.elem2.setStyle('opacity','1');
			var vccCookie = Cookie.write('intro', 'yes');
		}
		
		this.adjust("header");
		this.dt = this.gt()-this.st;
		if(this.timeout!=0 && this.timeout<this.dt) {
			this.stop(); return;
		} 
		if(this.loaded) {
			this.timeout = 0;
		}
		if( this.wait <= 0 ) {
			this.dt += this.wait;
			
			if(this.fade-this.dt<=0) {
				this.stop();
			} else {
				this.no = (1-this.dt/this.fade);
				this.elem2.setStyle('opacity',this.no);
			}
		} else if(this.dt>this.wait) {
			this.wait *= -1;
		}
	}
	if(Cookie.read('intro')==='yes') {
		this.start();
		//alert("Cookie gesetzt");
		//this.stop();
	} else {
		this.start();
		//alert("Kein Cookie gesetzt");
	}
}
