function collectExternalLinks() {
	$$('.content a.external').each ( function(link) {
		link.onclick = function() {
			if ( this.href.indexOf('@') < 0 ) {
				window.open(this.href);
				return false;
			}
			return true;
		}	
	} );
}


function getActiveSubmenu() {
	if( $$('#topnav li.active ul')[0] ) {
		return $$('#topnav li.active ul')[0]; 
	}
	return null;
}

function getSubmenuForItem(item) {
	return item.down().next();
}

function showSubmenu(menu) {
	menu.setStyle( { display: 'block' } );
}

function hideSubmenu(menu) {
	menu.setStyle( { display: 'none' } );
}

function submenuMojo() {
	var activeSubmenu = getActiveSubmenu();
	if (null == activeSubmenu) {
		return;
	}
	showSubmenu(activeSubmenu);
	$$('#topnav li').each( function(el) {
		el.onmouseover = function() {
			/* 
			 * if the item has no submenu 
			 * or if the item's submenu is the active submenu 
			 * do nothing 
			 */
			if( !getSubmenuForItem(el) || getSubmenuForItem(el) == activeSubmenu || el.getAttribute("value") != "1") {
				return;
			}
			hideSubmenu(activeSubmenu);
		};
		el.onmouseout = function() {
			showSubmenu(activeSubmenu);
		};
	} );
}

// ----------------------------------------------------------------------

function initJS() {
	collectExternalLinks();
	submenuMojo();
}

document.observe(
	'dom:loaded',
	initJS
);
