var bgshowClass=Class.create({
	initialize:function() {
		this.bg=$('bg');
		
		this.nr=1;
		this.nralt=0;
		this.nrmax=5;
		this.dimmpause=6000;
		this.dimmt=false;
		
		this.b1=document.createElement('div');
		this.b1.setAttribute('id','bild1');
		this.b1.style.position='absolute';
		this.b1.style.overflow='hidden';
		this.b1.style.display='block';
		this.bg.appendChild(this.b1);
		
		
		this.b2=document.createElement('div');
		this.b2.setAttribute('id','bild2');
		this.b2.style.position='absolute';
		this.b2.style.overflow='hidden';
		this.b2.style.display='block';
		this.bg.appendChild(this.b2);
		
		this.bildcontainer=this.b2;
		this.fadevon;
		
	},
	startTimer:function() {
		this.timer=window.setInterval('nextbild()',this.dimmpause);
	},
	initNavi:function() {
		var div=document.createElement('div');
		div.setAttribute('id','bgnavibox');
		
		var ul=document.createElement('ul');
		ul.setAttribute('id','bgnavi');
		
		for(var i=0;i<this.nrmax;i++) {
			var li=document.createElement('li');
			li.setAttribute('nr',(i+1));
			
			var p=document.createElement('p');
			p.innerHTML=(i+1);
			
			li.appendChild(p);
			ul.appendChild(li);
			
			Element.observe(li,'mouseover',function(event) {
				if(this.readAttribute('nr')!=bgshow.nr) this.setStyle({background:'#ff0'});
			});
			Element.observe(li,'mouseout',function(event) {
				if(this.readAttribute('nr')!=bgshow.nr) this.setStyle({background:'#999'});
			});
			Element.observe(li,'click',function(event) {
				if(!bgshow.dimmt && this.readAttribute('nr')!=bgshow.nr) bgshow.showBild(this.readAttribute('nr'));
			});
		}
		
		div.appendChild(ul);
		
		$('header').appendChild(div);
		
		this.navi=$('bgnavi');
	},
	setNavi:function() {
		if(this.nralt>0) {
			if(this.nralt==1) {
				this.navi.down().setStyle({background:'#999',cursor:'pointer'});
			} else {
				this.navi.down().next(this.nralt-2).setStyle({background:'#999',cursor:'pointer'});
			}
		}
		
		if(this.nr==1) {
			this.navi.down().setStyle({background:'#ff0',cursor:'default'});
		} else {
			this.navi.down().next(this.nr-2).setStyle({background:'#ff0',cursor:'default'});
		}
	},
	showBild:function(nr) {
		window.clearInterval(this.timer);
		
		this.nralt=this.nr;
		this.nr=nr;
		this.setBild();
		
		this.timer=window.setInterval('nextbild()',this.dimmpause);
	},
	nextbild:function() {
		this.nralt=this.nr;
		this.nr++;
		if(this.nr>this.nrmax) this.nr=1;
		this.setBild();
	},
	setBild:function() {
		if(this.bildcontainer==this.b1) {
			this.bildcontainer=this.b2;
			this.fadevon=0;
		} else {
			this.bildcontainer=this.b1;
			this.fadevon=1;
		}
		
		this.laden('images/show/Bild'+this.nr+'.jpg',1);
		
		//alert(this+" "+bgshow+" "+this.bildcontainer);
	},
	laden:function(bildsrc,anim) {
		imgPreloader=new Image();
		imgPreloader.onload=function() {
			Element.extend(this.bildcontainer);
			this.bildcontainer.setStyle({background:'url('+bildsrc+') center top no-repeat'}); 
			
			this.showImage(bildsrc,imgPreloader.width,imgPreloader.height,anim);
			
			if(Prototype.Browser.IE) imgPreloader.onload=function(){};
		}.bind(this)
		imgPreloader.src=bildsrc;
	},
	showImage:function(bildsrc,breit,hoch,anim) {
		this.bildcontainer.setStyle({
			/*background:'url('+bildsrc+') top center no-repeat',*/
			width:breit+'px',
			height:hoch+'px',
			left:'50%',
			marginLeft:-(breit/2)+'px'
		});
		
		this.bg.setStyle({
			width:breit+'px',
			height:hoch+'px',
			left:'50%',
			marginLeft:-(breit/2)+'px'
		});
		
		if(anim) {
			this.dimmt=true;
			new Effect.Opacity(this.b2,{from:this.fadevon,to:(this.fadevon==1?0:1),duration:1.5,afterFinish:function() { bgshow.dimmt=false; }});
		}
		
		this.setNavi();
	}
});


function nextbild() {
	bgshow.nextbild();
}


var soundClass=Class.create({
	initialize:function(t,p) {
		this.titel=t;
		this.parent=p;
		this.soundIsAn=true;
		
		this.init();
	},
	init:function() {
		if(!$('bgnavibox')) {
			var div=document.createElement('div');
			div.setAttribute('id','bgnavibox');
			
			$('header').appendChild(div);
			
			this.parent=div;
		}
		
		var a=document.createElement('a');
		a.setAttribute('id','soundbtn');
		a.setAttribute('href','javascript:void(0)');
		a.innerHTML="<b class='soundicon'></b>";
		
		Element.observe(a,'click',function(event) {
			event.stop();
			sound.schalten();
		});
		
		this.parent.appendChild(a);
		
	},
	schalten:function() {
		if(this.soundIsAn) {
			Sound.enable();
			Sound.play(this.titel,{replace:true});
			
			$('soundbtn').down().setStyle({backgroundPosition:'0 -20px'});
		} else {
			Sound.play('',{replace:true});
			Sound.disable();
			
			$('soundbtn').down().setStyle({backgroundPosition:'0 0'});
		}
		this.soundIsAn=!this.soundIsAn;
	}
});
