/*************************************

jFade 1.0.0 - Fader Script für jQuery
Carsten Ruppert 2009-03-11

Copyright 2009 HEAD. MARKETING-PARNTER

*************************************/

function jFade(nodeid,nodename,autorun){
	var jfade = this;
	
	this.nodeid = undefined;
	this.nodename = undefined;
	this.container = undefined;
	this.autorun = false;
	
	this.stack = new Array();
	this.speed = 4000;
	this.animspeed = 800;
	this.current = 0;
	
	
	this.run = function(){
		setTimeout(this.animate,this.speed);
		return;
		}
	this.getElements = function(){
		var child;
		for(var i = 0; i < this.container.childNodes.length; i++){
			child = this.container.childNodes[i];
			if(child.nodeName.toLowerCase() == this.nodename){
				this.stack[this.stack.length] = child;
				child.style.position = 'absolute';
				child.style.top = '0';
				child.style.left = '0';
				if(this.stack.length > 1){
					child.style.display = 'none';
					}
				}
			}
		return;
		}
	this.animate = function(){
		var next = jfade.current + 1 == jfade.stack.length ? 0 : jfade.current + 1;
		$(jfade.stack[jfade.current]).fadeOut(jfade.animspeed);
		$(jfade.stack[next]).fadeIn(jfade.animspeed);
		jfade.current = next;
		jfade.run();
		return;
		}

	if(nodeid){
		this.nodeid = nodeid;
		this.nodename = nodename;
		this.autorun = autorun;
		if(this.container = document.getElementById(this.nodeid)){
			this.container.style.position = 'relative';
			this.getElements();
			if(this.stack.length > 0){
				if(this.autorun){
					this.run();
					}
				}else{
				return false;
				}
			}
		}
	}
