// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// Scroll images in projecten controller
var div;
var timer;
function scroll(direction,amount) {
 	if(!div) return;
  div.scrollLeft += (amount * direction);
}
function startscroll(id, direction, amount) {
  div = document.getElementById(id);
  if(timer) clearInterval(timer);
  
  timer = setInterval('scroll(' + direction + ',10)',10);
}
function stopscroll() {
  if(timer) clearInterval(timer);
}

// Automatische image scroller
var auto_direction=1;
function autoScroll(amount) {
	var div=$('image-strip');
	div.scrollLeft += (amount*auto_direction);
	if ((div.scrollWidth-div.scrollLeft==div.offsetWidth && auto_direction > 0)  || (div.scrollLeft == 0 && auto_direction < 0 )) {
		auto_direction=auto_direction*-1;
	}
}

function startAutoscroll() {
	i=$('image-strip');
	i.scrollLeft=0;
	setInterval('autoScroll(1)',50);
}

// Suckerfish hover 
hoverList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("topnav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
	  		}
	  		node.onmouseout=function() {
	  			this.className=this.className.replace(" over", "");
	  		}
	   	}
		}
	}
}

// Afstemming hoogte divs
stretchDiv = function() {
	l=$('left');
	r=$('right');
	t=$('text');
	lh = l.getHeight();
	rh = r.getHeight();
	if (lh > rh) t.setStyle({height: (lh-270)+'px'})
}
window.onload = function() {
	hoverList();
	stretchDiv();
	if ($('image-strip')) startAutoscroll();
};