

document.observe("dom:loaded", function(){
	// If home tab is selected, hide marketing corner
	if ($('home').className != 'selected') {
		$('home').observe('mouseover',  function () { $('marketing_corner').style.display = 'inline'; });
		$('home').observe('mouseout',  function () { $('marketing_corner').style.display = 'none'; });
	}
	
	/* IE 6 fix for selected nav item */
	// Run through navs, if link is selected change the CSS
	$$('#links').each(function(item) {
		var link = item.getElementsByClassName('selected');
		if (typeof (link[0]) != 'undefined') {
			// There should only ever be one selected link
			link[0].style.backgroundPosition = '0px -36px';
		}
	} );
	
	/* Add jargon popups to links */
	$$('.jargon').each(function(element) {
		element.href = 'javascript:void(0)';
		var jargon = new HelpBalloon({ title: element.rel, icon: element, dataURL: '/jargon.php?title=' + element.rel, fixedPosition: 1, useEvent: ['mouseover']});
		element.observe('mouseout', function(){ 
			jargon.hide();
		});

	} );

	/* Side navigation sliding */
	// Run through side nav and add onClicks
	$$('.listWrapper').each(function(item){
		var title = item.getElementsByClassName('title');
		var list = item.getElementsByClassName('list');
		title = title[0];

		list = list[0];
		if (typeof(list) != 'undefined')
		{
			if (!title.hasClassName('selected')) {
			  list.hide();
			}
		}
		
		title.observe('click', function(){
			if (typeof (list) != 'undefined') {
				Effect.toggle(list, 'blind', {scaleX: true, duration: 0.5}); 
			}
			
		} );
	} );
} );

function renderMenu()
{
	for( var i in aNav ) {
		var item = i;

		if ( typeof(aMenuLinks[item]) != 'undefined' ) {
			aMenu[item] = ms.addMenu(document.getElementById(item));
			for( var j in aMenuLinks[item] ) {
				if ( typeof(aMenuLinks[item][j].title) != 'undefined' ) {
					aMenu[item].addItem(aMenuLinks[item][j].title, aMenuLinks[item][j].link); 
				}
			}
		}
	}
}

function init() {
	if (TransMenu.isSupported()) {
		TransMenu.initialize();
		// hook all the highlight swapping of the main toolbar to menu activation/deactivation
		// instead of simple rollover to get the effect where the button stays hightlit until
		// the menu is closed.
		 for( var item in aNav )
	     {
			if ( typeof(aMenuLinks[item]) != 'undefined' ) {
				aMenu[item].onactivate = new Function("document.getElementById('" + item + "').className = 'hover';");
				aMenu[item].ondeactivate = new Function("document.getElementById('" + item + "').className = '';");
			 }
		 }
	}

	for(i in aNav ) {
		if (i == 'home') {
			continue;
		}
		$(i).href = aNav[i].link;
	};
}
