﻿function menuSwitch(menuId, itemId) {

    var children = document.getElementById(menuId).childNodes;
    var oCurrentMenu = null;
    
    for ( i = 0; i < children.length; ++i ) {
        if ( children[i].id == itemId ) {
            oCurrentMenu = children[i];
        }
        else {
            if ( children[i].style != null )
                setOpacity(children[i], 0);
            children[i].className = 'hidden';
        }
    }
    
    if ( oCurrentMenu != null ) {
        appear(oCurrentMenu);
    }
}

function setOpacity(obj, val) {
    obj.style.MozOpacity = val;
    obj.style.opacity = val / 10;
    obj.style.filter = 'alpha(opacity = ' + (val * 10) + ')';
}

function fade(obj){

    if(obj.style.display == "none") 
        return false;
        
    var alpha = 10;
    function f() {
        --alpha;
        setOpacity(obj, alpha);
        
        if ( alpha > -1 ) {
            setTimeout(f, 100);
        } else {
            obj.style.display = 'none';
        }
    }
    setTimeout(f, 100);
}

function appear(obj) {

    if ( obj.className == 'display' )
        return;
    
    setOpacity(obj, 0);
    obj.className = 'display';
    obj.style.width = '100%';
    
    var alpha = 0;
    function a() {
        alpha += 3;
        setOpacity(obj, alpha);
        
        if ( alpha < 11 )
            setTimeout(a, 100);
    }
    
    setTimeout(a, 100);
};