window.addEvent('domready',function(){
	
	// fontfade
	if(AKTIVNAV[0] == 'home'){
		var fadenr = 0;
		(function() {
			$('ffade_0').set("tween", {
				onComplete: function() {
					fadenr++;
					txtfade('ffade_1', fadenr);
				}
				,duration: 2000
			}).fade(1, 0);
		}).delay(2000);
	}
	
	/*
	// Using the MooDropMenuClass
	var dropMenu = new MooDropMenu($('nav'),{
		onOpen: function(el){
			el.fade('in')
		},
		onClose: function(el){
			el.fade('out');
		},
		onInitialize: function(el){
			el.fade('hide').set('tween',{duration:1000});
		}
	});
	
	// The simple way
	$('nav').dropMenu();
	*/
	
	// The more advanced way
	$('nav').dropMenu({
		onOpen: function(el){
			$(el).set("tween", {
				onComplete: function() {}
				,duration: 10
			}).fade('in');
		},
		onClose: function(el){
			$(el).set("tween", {
				onComplete: function() {}
				,duration: 10
			}).fade('out');
		},
		onInitialize: function(el){
			el.fade('hide').set('tween',{
				onComplete: function() {}
				,duration:10
			});
		}
		,mouseoutDelay: 100
		,mouseoverDelay: 0
	});
	if($('content')) makeScrollbar($('content'), $('scrollbar'), $('handle'));
});

function txtfade(el, nr){
	$(el).set("tween", {
		onComplete: function() {
			(function() {
				$(el).set("tween", {
					onComplete: function() {
						nr++;
						if(!$defined($('ffade_' + nr))) nr = 0;
						txtfade('ffade_' + nr, nr);
					}
					,duration: 2000
				}).fade(1, 0);
			}).delay(2000);
		}
		,duration: 1000
	}).fade(0, 1);
}

function makeScrollbar(content, Xscrollbar, handle, horizontal, ignoreMouse){
	steps=0;
	p=0;
	steps = (horizontal ? (content.getScrollSize().x - content.getSize().x) : (content.scrollHeight+p - content.getSize().y))
	
	if (steps > 0) {
		Xscrollbar.setStyle('display', 'block');
		handle.setStyle('display', 'block');
	}else {
		Xscrollbar.setStyle('opacity', '0');
		handle.setStyle('opacity', '0');
	}
	slider = new Slider(Xscrollbar, handle, {
		steps: steps,
		mode: (horizontal ? 'horizontal' : 'vertical'),
		onChange: function(step){
			var x = (horizontal ? step : 0);
			var y = (horizontal ? 0 : step);
			content.scrollTo(x, y);
		}
	}).set(0);
	if (!(ignoreMouse)) {
		$$(content, Xscrollbar).addEvent('mousewheel', function(e){
			e = new Event(e).stop();
			var step = slider.step - (e.wheel / 2) * 30;

			slider.set(step);
		});
	}
	$(document.body).addEvent('mouseleave', function(){
		slider.drag.stop();
	});
}
