var hideMenu = 0;
function domenu () {
    var menu = getCookie("menuState").split(',');
    var mset = new Object;
    for( var i=0;i < menu.length; i++) {
      var nv = menu[i].split(':');
      if (nv[0] == -1) {
        if (nv[1] == 1) {
            hideMenu = 1;
	    mtog('hide');
        }
      } else {
          mset[nv[0]] = nv[1];
      }
    } 
    var inArray = document.getElementsByTagName('img');
    for(var i=0; i < inArray.length; i++){
	if (inArray[i].className.match(/menutoggle/)) {
            var id = inArray[i].id.replace(/(mct)/,"");
            if (mset[id] == 1) {
		hideMenuBlk(id);
            }
            inArray[i].onclick = mcol;
	}
    }
}

function mcol () {
    var instate = this.src.match(/ha2.png/) ? 1 : 0;
    var id = this.id.replace(/(mct)/,"");		     
    if (instate) { 
	hideMenuBlk(id);
    } else {
	showMenuBlk(id);
    }
    saveMenu(id,instate);
    return false;
}
function fadeIn (id) {
    var o = document.getElementById(id);
    if (o.fadeIn) window.clearInterval(o.fadeIn);
    var step = 0;
    o.fadeIn = window.setInterval(
        function() {
            o.style.opacity = step * .05;
            step++;
            if (step >= 100) window.clearInterval(o.fadeIn);
        }, 3);
}
function hideMenuBlk (id) {
    document.getElementById("mct" + id).src = "/shared/sa2.png";
    document.getElementById("mcd" + id).style.display = "none";
} 
function showMenuBlk (id) {
    document.getElementById("mct" + id).src = "/shared/ha2.png";
    document.getElementById("mcd" + id).style.opacity = 0;
    document.getElementById("mcd" + id).style.display = "block";
    fadeIn("mcd" + id);
}
function saveMenu (index,value) {
    var menu = getCookie("menuState");
    var opts = menu.split(',');
    var kp = new Array;
    kp[0] = index +":" + value;
    for (var i=0;i < opts.length; i ++) {
	var nv = opts[i].split(':');
	if (nv[0] && nv[0] != index) {
            kp.push(opts[i]);
	}
    }
    setCookie("menuState",kp.join(','),300);
}
// cookie functions are from quirksmode
function setCookie(name,value,days) {
    if (days) {
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie (name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
	if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return "";
}

addEvent(window,'load',domenu);
//var _menu_init = document.addEventListener ? document.addEventListener("DOMContentLoaded", function(){domenu();}, false): setInterval( function(){if (/loaded|complete/.test( document.readyState )){ clearInterval(_menu_init);domenu(); } }, 10);