window.addEvent('domready', function() {


	// === NEWS-SLIDER ========================
	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: $('newsslides'),
		items: $$('.stage-item'),
		size: 522,
		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(1);

					(function(){ 
						var subtitle = this.getElement('.subtitle');
							if(subtitle) { subtitle.fade(1); }
							
						}).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);
	});		
	// =================================================
});
