window.onload = function() {
	if($('home_carousel')) {
		headerSlideshow = new Slideshow('home_carousel', {
			hu: 'images/headers/', 
			images: ['oogst.jpg', 'willem_de_zwijger.jpg', 'atlantis_mechanica.jpg', 'cyrano.jpg'], 
		 	type: 'fade',
		 	duration: [2200, 3600]
		});
	}
	
	
	//sponsor scroll
	var busy = false; 
	var index = 0;
	var gallery = $('sponsors');
	if( gallery != null )
	{
	    var myTransition = new Fx.Transition(Fx.Transitions.Cubic);
	    var galleryFx = gallery.effects({duration: 800, transition: myTransition.easeOut});
    	
	    var galleryImgs = $$('#sponsors img');
	    if (galleryImgs.length > 0) galleryImgs.each(function(image) {
		    image.remove();
	    });
    	
	    var index = Math.floor(Math.random()*galleryImgs.length)
    	
	    if($('sponsor_small')) {
	  		//vuile browser hack helaas :(
	    	browser=navigator.appName;
	    	if(browser == 'Microsoft Internet Explorer') {
	    		height = 120;
	    	}
	    	else {
		    	height = 70;
	    	}
	    }
	    else {
		    height = 104;
	    }
	    showNextImage();
	}
	function showNextImage() {
		if (!busy) {
			busy = true;
						
			if (galleryImgs.length > 0) galleryImgs.each(function(image) {
				image.setStyle('visibility', 'hidden');
			});
			
			galleryImgs[index].inject(gallery);
			galleryImgs[index].setStyles({
				'position': 'absolute',
				'left': 0,
				'right': 0,
				'visibility': 'visible'
			});
			
			gallery.setStyle('visibility', 'visible');
			
			newX = (galleryImgs[index].width / 2) - 99;
			newY = height - (galleryImgs[index].height / 2);
			gallery.setStyle('top', newY);
			
			galleryFx.start({
				'right': [-301, newX]
			}).chain(function(){
				this.start.delay(5000, this, {
					'right': 300
				});
			}).chain(function(){
				busy = false;
				if((index + 1) == galleryImgs.length) {
					index = 0;
				}
				else {
					index++;
				}
				gallery.setStyle('visibility', 'hidden');
				showNextImage.delay(100);
			});
		}
	}
};
