/* treeMenu class */
function treeMenu()
{
    this.childNode = new Object();
}

/* */
treeMenu.prototype.turnNode = function(nodeId) {
    for(node in this.childNode) {
        this.childNode[node].style.display = (node == nodeId)? 'block': 'none';
    }	
}

/* append node to treeMenu */
treeMenu.prototype.appendNode = function(parentId, childId)
{
    objParent = document.getElementById(parentId);
    objChild = document.getElementById(childId);

    if (objChild != null) {
        objChild.style.display = 'none';
        this.childNode[childId] = objChild;
    }
    if (objParent != null) {
        objParent.onmouseover = function() { rootNode.turnNode(childId) }
        objParent.onfocus = function() { rootNode.turnNode(childId) }
    }
}

function initTreeMenu()
{	
    rootNode = new treeMenu();
    for(i = 1; i <= 8; i++) {
        rootNode.appendNode('parent'+i,'child'+i);
    }

    coreHref = location.href.replace(/\/P\d+$/,'');
    coreHref = coreHref.replace(/\/entry\/[0-9]+/,'');
    coreHref = coreHref.replace(/#.*$/,'');
console.log(coreHref);
    //if (coreHref.indexOf("/members_blog/category/", 0) == -1) {
        baseHref = coreHref.replace(/category\/.*/,'');
        baseHref = baseHref.replace(/archive\/.*/,'');
    //}
    rootHref = '';//coreHref.replace(/\/[a-z0-9_-]+\/?$/, '/');

    for(i = 0; i < document.links.length; i++) {
        link = document.links[i];

        if (link.id != 'siteName' &&
            (link.href == baseHref || link.href == coreHref
                || link.href == rootHref)) {
            if (link.id.substr(0,6) == 'parent') {
                childId = 'child' + link.id.substr(6);
                if (document.getElementById(childId) != null) {
                    document.getElementById(childId).style.display = 'block';
                }
            } else if (link.parentNode.className == 'treeNode') {
                link.parentNode.style.display = 'block';
            }
            if (link.parentNode.tagName.toLowerCase() != 'h2'
                && link.parentNode.tagName.toLowerCase() != 'h3') {
                link.style.color = '#f90';
            }
        }
    }

    if (document.getElementsByTagName) {
        input = document.getElementsByTagName('INPUT');
        for(i = 0; i < input.length; i++) {
            if (input[i].className == 'button'
                || input[i].className == 'formbutton') {
                input[i].onfocus = function() { this.style.background = '#f90' };
                input[i].onmouseover = function() { this.style.background = '#f90' };
                input[i].onblur = function() { this.style.background = '#999' };
                input[i].onmouseout = function() { this.style.background = '#999' };

            }
        }
    }

    if (k = document.getElementById('search_keywords')) {
        k.onfocus = function () {
            if (k.value == 'サイト内検索') {
                k.value = '';
            }
        };
        k.onblur = function () {
            if (k.value == '') {
                k.value = 'サイト内検索';
            }
        };
    }
}
window.onload = function() {initTreeMenu()};


