var currently_open = '';

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function myparam(name) {
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if (results == null) return "";
    else return results[1];
}

function doMenu() {
    var mstyle = myparam('m');
    switch (mstyle) {
        case '1': slideopen('submenu1', 430); break;
        case '2': slideopen('submenu2', 300); break;
        case '91': setOpen('submenu1', 430); break;
        case '92': setOpen('submenu2', 300); break;
        case '12':
            setOpen('submenu1', 430);
            slideopen('submenu2', 300);
            slideshut('submenu1');
            break;
        case '21':
            setOpen('submenu2', 300);
            slideopen('submenu1', 430);
            slideshut('submenu2');
            break;
    }
}

function setDisplay(what, value) {
    $(what).setStyle('display', value);
}

function slideshut(what) {
    currently_open = '';
    setDisplay(what,'block');
    var myfx = new Fx.Tween(what, {
        property: 'width',
        duration: 500,
        onComplete: setDisplay.pass(what,'none')
    });
    myfx.start(1);
}

function slideopen(what, width) {
    if (currently_open == what) {
        slideshut(what);
        return;
    }
    if (currently_open != '') { slideshut(currently_open); }
    
    currently_open = what;
    setDisplay(what, 'block');
    var myfx = new Fx.Tween(what, {
        duration: 500,
        property: 'width'
    });
    myfx.start(1, width);
}

function setOpen(what, width) {
    $(what).setStyle('width', width);
    $(what).setStyle('display', 'block');
    currently_open = what;
}