window.addEvent('domready', function() {
	// JS NUR FÜR STARTSEITE
	
	
	// NEWSTICKER ENDE ===============

	var slidesInterval = 10000;
	var slidesDuration = 1000;
	
	var sw = $(document.body).getElement('.stage-switcher-wrap');
	sw.setStyles({'width': sw.getSize().x.toInt(), 'margin-left': (sw.getSize().x.toInt() / 2) * -1});
	
	$$('.stage-item').each(function(el, index){
		if(el.getElement('h3')){
			el.getElement('h3').setStyles({'opacity': 0});
			el.getElement('h3').set('tween', { duration: slidesDuration / 2 });
		}

		if(el.getElement('.subtitle')){
			el.getElement('.subtitle').setStyles({'opacity': 0});
			el.getElement('.subtitle').set('tween', { duration: slidesDuration });
		}
	});
	
	var nS4 = new noobSlide({
		box: $('slidesStart'),
		items: $$('.stage-item'),
		size: 685,
		autoPlay: true,
		interval: slidesInterval,
		fxOptions: {
			duration: slidesDuration,
			transition: Fx.Transitions.Bounce.sineOut,
			wait: false
		},
		handles: $$('.stage-switcher a'),
		onWalk: function(currentItem,currentHandle){
			this.handles.removeClass('active');
			currentHandle.addClass('active');

			if(typeof(nS4) != 'undefined') { 
				if(typeof(nS4.titleFade) != 'undefined') { clearTimeout(nS4.titleFade); }
				if(typeof(nS4.paused)    != 'undefined') { clearTimeout(nS4.paused); }

				var heading = this.items[this.lastIndex].getElement('h3');
				if(heading) { heading.fade('out'); }
				var subtitle = this.items[this.lastIndex].getElement('.subtitle');
				if(subtitle) { subtitle.fade('out'); }
			}

			this.titleFade = (function(){ 
				var heading = this.getElement('h3');
				if(heading){
					heading.fade(.9);

					(function(){ 
						var subtitle = this.getElement('.subtitle');
						if(subtitle) { subtitle.fade(.9); }
						
					}).delay(0, this);
				}
				
			}).delay(slidesDuration, currentItem);
				
			this.lastIndex = this.currentIndex;
		}
	});
	
	nS4.lastIndex = 0;
	
	$(document.body).getElement('.stage-items').addEvent('mouseenter', function(){
		clearTimeout(nS4.paused);
		nS4.stop();
	});

	$(document.body).getElement('.stage-items').addEvent('mouseleave', function(){
		nS4.paused = (function(){ nS4.play(slidesInterval,"next",0); }).delay(slidesInterval/4);
	});
		
	// === AKKORDEON STARTSEITE ========================
	if($(document.body).getElement('.acc')){
		var myAccordion = new Fx.Accordion($$('.acc h3'), $$('.acc .acc-content-wrap'), {
			opacity: false, 
			duration: 500,
			link: 'ignore',
			fixedHeight: 150,
			initialDisplayFx: false, 
			display: 0,
			alwaysHide: false,
			onActive: function(toggler, element){
				toggler.addClass('act');
			},
			onBackground: function(toggler, element){
				toggler.removeClass('act');
			}
		});	
		$$('.acc h3').addEvent('mouseenter', function() { 
			ss = (function(){ this.fireEvent('click'); }).delay(300, this);
		});

		$$('.acc h3').addEvent('mouseleave', function() { clearTimeout(ss); });
	}	
	// =================================================
});
