function menu_hide_tabs() {
	// if(console && console.log) { console.log("menu_hide_tabs() called"); }
	var menu = document.getElementById("row_bar");
	if(menu) {
		var list = document.getElementById("row_bar").getElementsByTagName("li");
		for(var i=0,ic=list.length;i<ic;i++) {
			var anchor = list[i].getElementsByTagName("a")[0];
			if(anchor) {
				anchor.setAttribute("class","unselected");
				anchor.setAttribute("className","unselected"); // for IE
			}
		}
	}
}

function menu_tabs_setup() {
	if(!document.getElementsByTagName) { return; }
	menu_hide_tabs();
    
    var _body_element = document.getElementsByTagName("body"); // access [0] - we should have only one <body> tag
    if(_body_element && _body_element.length > 0 && _body_element[0] && _body_element[0].getAttribute) { 
        var _menu_tab = _body_element[0].getAttribute("menu_tab");
        if(_menu_tab && _menu_tab.length > 0 && _menu_tab >= 0) {
            menu_tab_show(_menu_tab);
        }
    }
}

function menu_tab_show(tab) {
	// if(console && console.log) { console.log("menu_tab_show("+tab+")"); }
	
	if(tab && tab >= 0) {
		var list = document.getElementById("row_bar").getElementsByTagName("li");
		for(var i=0,ic=list.length;i<ic;i++) {
			var anchor = list[i].getElementsByTagName("a")[0];
			var relAttribute = String(anchor.getAttribute("rel"));
			if(anchor.getAttribute("href") && (relAttribute.toLowerCase().match("menu"))) {
				var nameAttribute = anchor.getAttribute("name");
				// alert(nameAttribute);
				if(nameAttribute.toLowerCase().match("m_"+tab+"_")) {
					// alert("menu_tab_show("+tab+") matched");
					
					anchor.setAttribute("class","selected");
					anchor.setAttribute("className","selected"); // for IE
					// anchor.getAttributeNode("class").value = "selected_anchor"; // does not work in IE for 'a' tags
					
					// anchor.style.cssText = "color:#290909;"; // works in IE, but as colour is specific and this is a shared .js file, not a good solution
					
					if(i<(ic-1)) {
						list[i].setAttribute("class","separator selected");
						list[i].setAttribute("className","separator selected");
					} else {
						list[i].setAttribute("class","selected");
						list[i].setAttribute("className","selected");
					}
				} else {
					anchor.setAttribute("class","unselected");
					anchor.setAttribute("className","unselected"); // for IE
					
					// anchor.style.cssText = ""; // for IE
					
					if(i<(ic-1)) {
						list[i].setAttribute("class","separator unselected");
						list[i].setAttribute("className","separator unselected");
					} else {
						list[i].setAttribute("class","unselected");
						list[i].setAttribute("className","unselected");
					}
				}
			}
		}
	}
	return true;
}

function attach_event(obj,evt,fnc,useCapture) {
	if(obj.addEventListener) {
		obj.addEventListener(evt,fnc,useCapture);
		return true;
	} else if (obj.attachEvent) {
		return obj.attachEvent("on"+evt,fnc);
	} else {
		obj["on"+evt]=fnc;
	}
	return true;
}

if(typeof(Event) != "undefined" && typeof(Event.observe) != "undefined") {
    // alert("setting up menu....");
    Event.observe(window,"load",menu_tabs_setup);
} else {
    attach_event(window,"load",menu_tabs_setup,true);
}
