menuFx = new Fx;

function hideSubmenus(no_fade){
	$$('.submenu').each(function(item){
		item.setStyle('display', 'none');
	});
	if(!no_fade){
		//menuFx = new Fx.Tween('content', {duration: 500, link: 'cancel'}).start('opacity', $('content').getStyle('opacity'), 1);
	}
}

function openSubmenu(id){
	hideSubmenus(1);
	if($(id) != null){
		$(id).setStyle('display', 'block');
		//menuFx = new Fx.Tween('content', {duration: 200, link: 'cancel'}).start('opacity', $('content').getStyle('opacity'), 0.4);
	}
}

function createImageRotators(){
	if($('sponsor_rotator') != null){
		var images = $('sponsor_rotator').getChildren();
		if(images.length > 1){
			var i = 0;
			for(i = 0; i < images.length; i++){
				if(i > 0){
					images[i].setStyle('opacity', 0);
				} else {
					images[i].setStyle('opacity', 1);
					images[i].setProperty('alt', 'on');
				}
			}

			setInterval(function(){
				var i = 0;
				for(i = 0; i < images.length; i++){
					if(images[i].getProperty('alt') == 'on'){
						//images[i].setStyle('opacity', 0);
						new Fx.Morph(images[i], {duration: 2000} ).start({ 'opacity': [1,0]});
						images[i].setProperty('alt', 'off');
						if(i == images.length-1){
							//images[0].setStyle('opacity', 1);
							new Fx.Morph(images[0], {duration: 2000} ).start({ 'opacity': [0,1]});
							images[0].setProperty('alt', 'on');
						} else {
							//images[i+1].setStyle('opacity', 1);
							new Fx.Morph(images[i+1], {duration: 2000} ).start({ 'opacity': [0,1]});
							images[i+1].setProperty('alt', 'on');
						}
						break;
					}
				}
			}, (5000));
		}
	}
}

function initJs(){
	$$('#topmenu img').each(function(item){
		item.addEvent('mouseenter', function(){
			openSubmenu('sub' + item.getProperty('id'));
		})
	});
	$$('#sidemenu img').each(function(item){
		item.addEvent('mouseenter', function(){
			openSubmenu('sub' + item.getProperty('id'));
		})
	});
	$$('.submenu').each(function(item){
		item.addEvent('mouseleave', function(){
			hideSubmenus();
		})
	});
	
	createImageRotators();

	heightfix();
}

function heightfix(){
	var size = $('content').getSize();
	if(size.y <= 400){
		$('content').setStyle('height', '400px');
	} else {
		if($('stopwatch') != null) $('stopwatch').setStyle('margin-top', (size.y + 47) + 'px');
	}
}

Shadowbox.init({
	language:   "nl",
	players:    ["img"]
});

window.addEvent('domready', initJs);
window.addEvent('load', heightfix);

