function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y));
	handle.removeEvents();
	scrollbar.removeEvents();
	if(steps <= 0){
		handle.setStyle('display','none');
		scrollbar.setStyle('display','none');
		return false;
	} else {
		handle.setStyle('display','block');
		scrollbar.setStyle('display','block');
	}
	var slider = new Slider(scrollbar, handle, {
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
			// Scrolls the content element in x or y direction.
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
		}
	}).set(0);
	if( !(ignoreMouse) ){
		// Scroll the content element when the mousewheel is used within the
		// content or the scrollbar element.
		$$(content, scrollbar).removeEvent('mousewheel');
		$$(content, scrollbar).addEvent('mousewheel', function(e){
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;
			slider.set(step);
		});
	}
	return true;
	// Stops the handle dragging process when the mouse leaves the document body.
	//$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}

function selectToolkit(id){
	$('verstuur_button').setStyle('display', 'block');
	$('reactie_textarea').value = '';
	$('reactie_textarea').focus();
	$('toolkit_id').value = id;
}

function insertAtCursor(myField, myValue) {
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

function initJs(){
	if($('column1') != null && $('scrollbar1') != null && $('handle1') != null){
		if(makeScrollbar($('column1'), $('scrollbar1'), $('handle1'))){
			$('scrollbar1').setStyle('background-image', 'none');
		} else {
			$('scrollbar1').setStyle('display', 'block');
			$('scrollbar1').setStyle('background-color', 'transparent');
		}
	}
	if($('column2') != null && $('scrollbar2') != null && $('handle2') != null){
		makeScrollbar($('column2'), $('scrollbar2'), $('handle2'));
		$('scrollbar2').setStyle('background-image', 'none');
	}
}

Shadowbox.init({
    language:   "nl",
    players:    ["img", "iframe", "qt"]
});
window.addEvent('domready', initJs);
