/*

To mark a menu item as "on" and stay as "on" until the other item is click.

When an <a> tag in <ul id="site-menu" /> is clicked, className "on" will be added to it,
and className "on" will be removed from the other <a> tags.

author: andrew chow - chowdrew at g mail
20070731
*/


// REQUIRE: _js/dom/abbr.js
// REQUIRE: _js/dom/event.js

function getAllItems() {
	return gt(ge('site-menu'), 'a');
}

function patchOnClick() {
	var allItems = getAllItems();
	for (var ii=0; ii<allItems.length; ii++) {
		allItems[ii].onclick = function() { itemOnClick(); };
	}
}

function markOffAllItems() {
	var allItems = getAllItems();
	for (var ii=0; ii<allItems.length; ii++) {
		allItems[ii].className = allItems[ii].className.replace(/ ?on/, '');
	}
}

function markOnOneItem(elem) {
	elem.className += ' on';
}


function itemOnClick(e) {
	var e = (window.event)?window.event:e;
	var src = (e.srcElement)?e.srcElement:e.target;
	markOffAllItems();
	markOnOneItem(src);
}

// addListener(self, "load", function() { patchOnClick(); });
