/**
 * Hack the menu to produce rounded corners.
 */
var Navigation = new function () {

	var MARKUP = "" +
		"<table>" +
			"<tbody>" + 
				"<tr>" +
					"<td class=\"nw\"></td>" +
					"<td class=\"n\"></td>" +
					"<td class=\"ne\"></td>" +
				"</tr>" +
				"<tr>" +
					"<td class=\"w\"></td>" +
					"<td class=\"c\"></td>" +
					"<td class=\"e\"></td>" +
				"</tr>" +
				"<tr>" +
					"<td class=\"sw\"></td>" +
					"<td class=\"s\"></td>" +
					"<td class=\"se\"></td>" +
				"</tr>" +
			"</tbody>" +
		"</table>";
		
	/*
	 * Fires when DOMContentLoaded is triggered. 
	 * Note that Firefox uses CSS rounded corners. 
	 */
	this.ondom = function () {
		
		if ( !Client.isGecko ) {
			
			var nav = document.getElementById ( "nav" );
			var tmp = document.createElement ( "div" );
			
			nav.className = "mod";
			tmp.innerHTML = MARKUP;
			var table = tmp.firstChild;
			
			var links = nav.getElementsByTagName ( "a" );
			var i = 0, link;
			
			while ( link = links.item ( i++ )) {
				
				/**
				 * The "seo" links are invisible navigation links, supposed 
				 * to help Google decipher the structure of the site.
				 */
				if ( link.className != "seo" ) {
				
					var clone = table.cloneNode ( true );
					var span = link.getElementsByTagName ( "span" ).item ( 0 );
					var width = span.offsetWidth;
					if ( Client.isExplorerOld ) {
						width -= 11; // for some reason...
					}
					var tdc = clone.getElementsByTagName ( "td" ).item ( 4 );
					tdc.style.width = width + "px";
					link.appendChild ( clone );
					
					/*
					 * TODO: Implement visible focus using CSS
					 */
					if ( Client.isExplorer ) {
						link.hideFocus = true;
					}
					
					/*
					 * There is a CSS rendering bug in the current Chrome release: 
					 * The SPAN inside the A eliminates padding on the A! This 
					 * places the table too far below the A. We can hack it like 
					 * this, but the menu is no longer cool looking in WebKit 
					 * without script enabled, so please check this again later.
					 */
					if ( Client.isOldWebKit ) {
						clone.style.top = "-17px";
					}
				}
			}
		}
	}
	
	/*
	 * Register action on the DOMContentLoaded event. 
	 * Mozilla handles this stuff without scripting.
	 */
	if ( !Client.isGecko && !Client.isOpera ) {
		Manager.ondom ( this );
	}
}
