// movingDistance should be same width (incl padding/border/margin) as the width of a panel (.actueelresultitem)
function loadScroller(scrollerId, movingDistance)
{
	var $scroller			= $("#" + scrollerId);
	var $container			= $("#" + scrollerId + " .bslScrollContainer");
	var $panels				= $("#" + scrollerId + " .bslScrollContainer > div");
	
	var totalPanels			= $panels.size();


	$panels.css({'float': 'left','position': 'relative'});
    
	$scroller.data("currentlyMoving", false);

	if ($panels.length > 0)
	{
		$container
			.css('width', ($panels[0].offsetWidth * $panels.length) + 100)
			.css('left', "0px");
	}

	// Set up "Current" panel and next and prev
	var curPanel = 1;

	//direction true = right, false = left
	function bslScrollChange(direction) {
	   
	    //if not at the first or last panel
		if((direction && !(curPanel < totalPanels)) || (!direction && (curPanel <= 1))) { return false; }	
        
        //if not currently moving
        if (($scroller.data("currentlyMoving") == false)) {
            
			$scroller.data("currentlyMoving", true);
			
			var next         = direction ? curPanel + 1 : curPanel - 1;
			var leftValue    = $container.css("left");
			var movement	 = direction ? parseFloat(leftValue, 10) - movingDistance : parseFloat(leftValue, 10) + movingDistance;
		
			$container
				.stop()
				.animate({
					"left": movement
				}, function() {
					$scroller.data("currentlyMoving", false);
				});
			
			curPanel = next;
			
			//remove all previous bound functions
			$("#bslScrollPanel_"+(curPanel+1)).unbind();	
			
			//go forward
			$("#bslScrollPanel_"+(curPanel+1)).click(function(){ bslScrollChange(true); });
			
            //remove all previous bound functions															
			$("#bslScrollPanel_"+(curPanel-1)).unbind();
			
			//go back
			$("#bslScrollPanel_"+(curPanel-1)).click(function(){ bslScrollChange(false); }); 
			
			//remove all previous bound functions
			$("#bslScrollPanel_"+curPanel).unbind();
		}
	}
	
	$("#bslScrollPanel_"+(curPanel+1)).click(function(){ bslScrollChange(true); });
	$("#bslScrollPanel_"+(curPanel-1)).click(function(){ bslScrollChange(false); });
	
	//when the left/right arrows are clicked
	$("#" + scrollerId + " .bslScrollButtonRight").click(function(){ bslScrollChange(true); });
	$("#" + scrollerId + " .bslScrollButtonLeft").click(function(){ bslScrollChange(false); });
}

