var Scroller = {
	
	init: function() {
   	// horizontal slider control
   	Scroller.groupscroller = new Control.Slider('handle', 'track', {
   		onSlide: function(v) { Scroller.scrollHorizontal(v, $('scrollable'), Scroller.groupscroller);  },
   		onChange: function(v) { Scroller.scrollHorizontal(v, $('scrollable'), Scroller.groupscroller); }
   	});
		
	},
	
	// scroll the element horizontally based on its width and the slider maximum value
	scrollHorizontal: function(value, element, slider) {
		element.scrollLeft = Math.round(value/slider.maximum*(element.scrollWidth-element.offsetWidth));
	},
	
	setScrollableWidth: function(screenlist) {
	   var children = screenlist.immediateDescendants().length;
	   var width = (children * 143);
	   screenlist.style.width = width + 'px';
	   
   	// disable horizontal scrolling if text doesn't overflow the div
   	if (children <= 6) {
         // groupscroller.setDisabled();
         $('track').hide();
   	} else {
   	   $('track').show();
   	}
	},
	
	switchToCategory: function(nr) {
	   var screenlist = $('scrollable-cat-'+nr);
	   Scroller.setScrollableWidth(screenlist);
	   $$('#scrollable ul').each( function(e){ e.hide() });
	   screenlist.show();
	}
	
}

// Event.observe(window, 'load', Scroller.init);