// handles 3rd level direction of main navigation, depending on window size
document.observe("dom:loaded", function() {
	function mainNaviOverflowHander() {
		var winWidth = parseInt(document.viewport.getDimensions().width);
		var pmMarginLeft = parseInt($('PrimaryNavigation').getStyle('margin-left'));
		var pmWidth = parseInt($('PrimaryNavigation').getWidth());
		var totalWidth = pmMarginLeft + pmWidth + 193 + 20; //193px fixed with of 3rd level, 20px tolerance
		if (totalWidth < winWidth) {
			$$(".PrimaryNavigationLast").each(function(elmt) { elmt.addClassName('lastElementRight') }); 
		}else{
			$$(".PrimaryNavigationLast").each(function(elmt) { elmt.removeClassName('lastElementRight') }); 
		}
	}
	// do this once on load...
	mainNaviOverflowHander();
	// ... and on every window resize
	Event.observe(document.onresize ? document : window, "resize", function() {mainNaviOverflowHander();});	
});
