window.addEvent('domready',function() {
	/* settings */
	
	
	
	
	if($('teaser_banner_wrapper')){
	  var showDuration = 5000;
	  var container = $('teaser_banner_wrapper');
	  var images = container.getElements('div.teaser_banner');
	  var listitems = $('teaser_list').getElements('a');
	  var currentIndex = 0;
	  var currentIndex2 = 0;
	  var interval;
	  
	  /*Items und Events*/
	  
	  listitems[0].addClass('issel');
	  listitems[0].getParent().addClass('sel');
	  var y = 0;
	  listitems.each(function(listitem){
		  listitem.set('rel',y);
		  y++;
	  });
	  
	  images.addEvents({
		'mouseenter': function(){
			clearInterval(interval);	
		},
		'mouseleave': function(){
			interval = show.periodical(5000);	
		}				
	  });
	  
	  listitems.addEvents({
		'click': function(e){
			e.stop();
			clearInterval(interval);
			images.set('opacity',0);			
			$('ban' + this.get('rel')).fade('in');
			currentIndex = this.get('rel').toInt();
			currentIndex2 =  this.get('rel').toInt();					
			listitems.setStyle('background-color','#0e2230');
			listitems.removeClass('issel');
			listitems.getParent().removeClass('sel');
            this.setStyle('background-color','#6e7a86');
			this.addClass('issel');
			this.getParent().addClass('sel');
		},
	       'mouseenter': function(){
			if(!this.hasClass('issel')) this.setStyle('background-color','#6e7a86');
			clearInterval(interval);

		},
		'mouseleave': function(){
			if(!this.hasClass('issel')) this.setStyle('background-color','#0e2230');
			interval = show.periodical(5000);
			}
		});
	  
	  /*Banner auf transparent und laufende id = ban0, ban1 etc*/
	  
	  y = 0;
	  images.each(function(img,i){
		if(i > 0) img.set('opacity',0);
		img.set('id','ban' + y);
		y++;
	  });
	  
	  /* worker */
	  var show = function() {
		var myMorph = new Fx.Morph(images[currentIndex],{duration:'long'});
		myMorph.start({'opacity':0}).chain(function(){
			var trenner = new Element('div',{'class':'teaser_banner_trenner'})
		    trenner.inject($('teaser_banner_wrapper'),'top');
			trenner.tween('left',640);
			listitems[currentIndex2].setStyle('background-color','#0e2230');
			listitems[currentIndex2].removeClass('issel');
			var parent = listitems[currentIndex2].getParent();
			parent.removeClass('sel');
			images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].setStyle('opacity','1');
			var nextitem = listitems[currentIndex2 = currentIndex2 < listitems.length - 1 ? currentIndex2+1 : 0];
			nextitem.setStyle('background-color','#6e7a86');
			nextitem.addClass('issel');
			parent = nextitem.getParent();
			parent.addClass('sel');

		}).chain(function(){trenner.destroy()});
		  
		
	  };


     /* start once the page is finished loading */
	  
	   interval = show.periodical(showDuration);
	   
	   
	   
	 /*Counter */
	   if($('counter')){
			if($('strcounter')){
				var curdays = $('strcounter').get('value');
				$('counter').set('html',curdays);
			}
	   }




	}
});


