// JavaScript Document
var doc = document;

function togglePulldown(id) {
	var h1=document.body.clientHeight;
	var h2=document.body.scrollHeight;

	if(h2>h1) { var ht=h2; } else { var ht=h1; }
	
	offset = _get_offset(doc.getElementById('pulldownselect'));

	doc.getElementById('pulldownbox').style.height = doc.getElementById('pulldown').offsetHeight + "px";
	doc.getElementById('pulldownbox').style.left = offset['x']+1+"px";
	doc.getElementById('pulldownbox').style.top = offset['y']+19+"px";
	doc.getElementById('pulldownbox').style.visibility = "visible";
	doc.getElementById('pulldown').style.visibility = "visible";
	moveDropdownDown("pulldown");
}

function selectItem(obj) {
	moveDropdownUp("pulldown");
	doc.getElementById('zoekencatpulldown').value = obj.name;
	doc.getElementById('pulldownselect').innerHTML = "";
	doc.getElementById('pulldownselect').innerHTML = obj.innerHTML;
	return false;
}
		
navTimer = null;
function moveDropdownDown(box) {
	
	clearTimeout(navTimer);
	var CurY = document.getElementById(box).offsetTop;
	var EndY = -1;
	var accelFactor = 12;
	var Yplus = 0;
	if (CurY < EndY) {
		Yplus = (Math.ceil((EndY - CurY) / accelFactor)) + 1;
	} else if (CurY > EndY) {
		Yplus = (Math.ceil((EndY - CurY) / accelFactor)) - 1;
	}
	document.getElementById(box).style.top = CurY+Yplus+"px";

	if (CurY != EndY) {
		navTimer = setTimeout("moveDropdownDown('"+box+"')",20);
	}
}
function moveDropdownUp(box) {
	clearTimeout(navTimer);
	var CurY = document.getElementById(box).offsetTop;
	var EndY = 	0 - document.getElementById(box).offsetHeight;
	var accelFactor = 7;
	var Yplus = 0;
	
	if (CurY < EndY) {
		Yplus = (Math.ceil((EndY - CurY) / accelFactor)) + 1;
	} else if (CurY > EndY) { 
		Yplus = (Math.ceil((EndY - CurY) / accelFactor)) - 1;
	}
	document.getElementById(box).style.top = (CurY+Yplus)+"px";
	
	if (CurY != EndY) {
		navTimer = setTimeout("moveDropdownUp('"+box+"')",20);
	} else {
		doc.getElementById(box).style.visibility = "hidden";
		doc.getElementById('pulldownbox').style.visibility = "hidden";
	}
}
		
		
function _get_offset(obj) {
	var offset;
	possx = findPosX(obj);
	possy = findPosY(obj);
	offset = {x: possx, y: possy};
	return offset;
}
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x) { curleft += obj.x; }
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) { curtop += obj.y; }
	return curtop;
}