xAddEventListener(window,'load',setBarImageHeight);
xAddEventListener(document,'mouseover',showSubMenu);

function setBarImageHeight() {
    var height = xHeight("contentMain");
    var clientHeight = xClientHeight();
    if(clientHeight>height) height = clientHeight;
    else height+=40;

    var leftImg = xGetElementById("contentLeftBar");
    xHeight(leftImg, height);
    xHeight(leftImg.parentNode, height);

    var rightImg = xGetElementById("contentRightBar");
    xHeight(rightImg, height);
    xHeight(rightImg.parentNode, height);
}

var prevSubObj = null;
function showSub(obj) {
    if(prevSubObj) prevSubObj.style.display = 'none';
    obj.style.display = "block";
    prevSubObj = obj;
}

function closeSub(obj) {
    if(prevSubObj) {
        prevSubObj.style.display = 'none';
        prevSubObj = null;
    }
}

function showSubMenu(evt){
    var e = new xEvent(evt);
    var obj = e.target;
    var parent = null;

    if(obj.nodeName == 'A' && obj.parentNode) {
        parent = obj.parentNode.parentNode;
    } else if(obj.nodeName == 'DIV') {
        parent = obj.parentNode;
    }

    if(!parent || !parent.id || !/^main_menu_[0-9]+/.test(parent.id)) {
        closeSub(obj);
        return;
    }

    var id = parent.id.replace(/^main_menu_/,'');

    var subObj = xGetElementById('sub_'+id);
    if(!subObj) {
        closeSub(obj);
        return;
    }

    if(subObj.style.display != 'block') {
        subObj.style.right = 0;
        subObj.style.top = 0;
        showSub(subObj);
    }
}
