// JavaScript Document


	  
	  
window.addEventListener ? window.addEventListener("load", so_init, false) : window.attachEvent("onload", so_init);

var d = document, imgs = new Array(), fadeFrom = 0, fadeTo = 1;

var delayBetweenImages = 4500;

var timer = null, nextImage = null;

//var heroImages = new Array("media/layout/slide1.jpeg", "/display_data/slide2.jpeg", "/display_data/rs_hero.jpeg", "/display_data/slide4.jpeg", "/display_data/slide5.jpeg", "/display_data/slide6.jpeg");

function getElementsByClassName(node, classname)
{
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function so_init() {
	if(!d.getElementById || !d.createElement) return;

	// set xOpacity on images
	imgs = $$("#heroImages .heroImg");
	links = $$("#heroImages .bumpbox");
	
	
	imgs[0].xOpacity = 0.99;
	links[0].xOpacity = 0.99;
	
	for(i = 1; i < imgs.length; i++) { imgs[i].xOpacity = 0; }
	for(i = 1; i < links.length; i++) { links[i].xOpacity = 0; }
	timer = setTimeout(so_xfade, delayBetweenImages);
}

// jump directly to home page image
function changeToImage(x) {
	imgs[fadeTo].style.display = "none";
	
	
	
		$('dot_'+fadeTo).className = 'heroDot off';
	
	
	fadeTo = x;

	
		$('dot_'+fadeTo).className = 'heroDot';
	

	// cancel current timer & and start going into new image user wants to jump to
	clearTimeout(timer);
	
	so_xfade();
}

function so_xfade() {
	//$$('.bedrijfsfilm')[0].tween('opacity', fadeTo == 0 ? 1 : 0);
	
	
		$('dot_'+fadeFrom).className = 'heroDot off';
		$('dot_'+fadeTo).className = 'heroDot';
	

	cOpacity = imgs[fadeFrom].xOpacity;
	nOpacity = imgs[fadeTo].xOpacity;
	
	cOpacity -= .05;
	nOpacity += .05;
	
	imgs[fadeTo].style.display = "block";
	
	 

	imgs[fadeFrom].xOpacity = cOpacity; setOpacity(imgs[fadeFrom]);
	imgs[fadeTo].xOpacity = nOpacity;	setOpacity(imgs[fadeTo]);

	// we've finished fading out the fadeFrom image, so hide it completely and figure out next image //'
	if(nOpacity < .99) {
		// still doing cross-fade...
		timer = setTimeout(so_xfade, 50);
	} else {

		imgs[fadeFrom].style.display = 'none';
		if (([fadeFrom] == 1) || ([fadeFrom] == 2) || ([fadeFrom] == 3) || ([fadeFrom] == 4) ) {
			links[fadeFrom-1].style.display = 'none';
			 
		}
		if (([fadeTo] == 1) || ([fadeTo] == 2) || ([fadeTo] == 3) || ([fadeTo] == 4) ) {
			links[fadeTo-1].style.display = 'block';
			 
		}
		
		fadeFrom = fadeTo;
		fadeTo = imgs[fadeFrom+1] ? fadeFrom + 1 : 0;

		imgs[fadeFrom].xOpacity = .99; setOpacity(imgs[fadeFrom]);
		imgs[fadeTo].xOpacity = 0; setOpacity(imgs[fadeTo]);
		
		timer = setTimeout(so_xfade, delayBetweenImages);
	}
}

function setOpacity(obj) {
	if(obj.xOpacity > .99) {
		obj.xOpacity = .99;
		return;
	}
	obj.style.opacity = obj.xOpacity;
	obj.style.MozOpacity = obj.xOpacity;
	obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}

