/**
 * Scrolls the division menu horizontally.
 */
DivisionMenuScroll = {

	/**
	 * Scrolls to the left.
	 */
	init: function()
	{
		/* 'disable' the left button by default */
		setOpacity($("scroll-left"), 0.5);
		$("scroll-left").style.cursor = "default";

		/* save scrollwidth */
		DivisionMenuScroll._menu = $$("#scroll-container > ul")[0];
		DivisionMenuScroll._firstLevelNodes = $$("#scroll-container > ul > li");
		DivisionMenuScroll._scrollWidth = DivisionMenuScroll._getScrollWidth();

		/* mark the last visible list item as 'last' */
		addElementClass(DivisionMenuScroll._firstLevelNodes[6], "last");
		removeElementClass(DivisionMenuScroll._firstLevelNodes[DivisionMenuScroll._firstLevelNodes.length-1], "last");
	}, // function scrollLeft

	/**
	 * Scrolls to the left.
	 */
	scrollLeft: function()
	{
		/* do not execute when not yet intialized */
		if (!DivisionMenuScroll._menu)
		{
			return;
		}

		/* scroll to the left */
		MochiKit.Visual.Move(DivisionMenuScroll._menu, {"x": 0, "mode": "absolute"});

		/* 'disable' the left button, 'enable' the right button */
		setOpacity($("scroll-left"), 0.5);
		$("scroll-left").style.cursor = "default";
		setOpacity($("scroll-right"), 1);
		$("scroll-right").style.cursor = "pointer";

		/* mark the last visible list item as 'last' */
		addElementClass(DivisionMenuScroll._firstLevelNodes[6], "last");
		removeElementClass(DivisionMenuScroll._firstLevelNodes[DivisionMenuScroll._firstLevelNodes.length-1], "last");
	}, // function scrollLeft

	/**
	 * Scrolls to the right.
	 */
	scrollRight: function()
	{
		/* do not execute when not yet intialized */
		if (!DivisionMenuScroll._menu)
		{
			return;
		}

		/* scroll to the right */
		MochiKit.Visual.Move(DivisionMenuScroll._menu, {"x": DivisionMenuScroll._scrollWidth, "mode": "absolute"});

		/* 'disable' the right button, 'enable' the left button */
		setOpacity($("scroll-left"), 1);
		$("scroll-left").style.cursor = "pointer";
		setOpacity($("scroll-right"), 0.5);
		$("scroll-right").style.cursor = "default";

		/* mark the most right list item as 'last' */
		removeElementClass(DivisionMenuScroll._firstLevelNodes[6], "last");
		addElementClass(DivisionMenuScroll._firstLevelNodes[DivisionMenuScroll._firstLevelNodes.length-1], "last");
	}, // function scrollRight

	/**
	 * Returns the number of pixels to scroll.
	 * 
	 * Note: returns a negative number!
	 * 
	 * @return	int
	 */
	_getScrollWidth: function()
	{
		/* calculate width by number of list items */
		var listItems = $$("#scroll-container > ul > li");
		var menuWidth = (listItems.length * 120);

		/* save the menu width to make sure the floats work as expected */
		DivisionMenuScroll._menu.style.width = menuWidth + "px";

		/* return only the number of pixels to scroll */
		return elementDimensions($("scroll-container")).w - menuWidth;
	} // function _getScrollWidth

}; // function DivisionMenuScroll
