/**
 * @author Martin Kleppe
 */

var SubNavigation = {

	/**
	 * Centers sub navigation.
	 * @param {String} mainPage Selected navigation element id
	 */
	initialize: function(mainPage) {
		
		// get main and sub menu element
		var entryMain = $(mainPage).parentNode;
		var entrySub = $("navsub");

		if (entryMain){

			// get center position of main menu element		
			var centerMain = entryMain.offsetLeft + Math.round(entryMain.offsetWidth /2);
			
			// compute total width of menu elements
			var width = 0;
			$A(entrySub.getElementsByTagName("li")).each(function(i) {width += i.offsetWidth;});

			// compute center position
			var pos = centerMain - Math.round(width/2);
			
			// make sure subnav does not extend borders
			pos = Math.max(0, pos);
			pos = Math.min(entrySub.offsetWidth - width, pos);

			// assign padding to first list element
			entrySub.getElementsByTagName("li")[0].style.paddingLeft = pos + "px";
		}
	}
};


