
var myT;

function cleanColumns(rightcolId)
{
    nodes = $('contentleft').childNodes;
    var i = nodes.length; while(i-->0)
    {
        if(nodes[i].nodeType == 3 || nodes[i].tagName != 'DIV')
        {
            if (nodes[i].nodeType == 1)
            {
                console.log(nodes[i].tagName)
                //console.log('Type: ' + nodes[i].nodeType + ' / ' + nodes[i].nodeValue)
            }
            nodes[i].parentNode.removeChild(nodes[i]);
        }
    }
    if (rightcolId == undefined) rightcolId = 'contentright'

    nodes = $(rightcolId).childNodes;
    var i = nodes.length; while(i-->0)
    {
        if(nodes[i].nodeType == 3 || nodes[i].tagName != 'DIV')
        {
            nodes[i].parentNode.removeChild(nodes[i]);
        }
    }
}

function initMenu()
{
    $('search_button_id').addEvent('click', openAdvanced);
    $('searchcontext_id').addEvent('click', function(){if (this.value == 'Search') this.value='';});
    $('advsearch_close_id').addEvent('click', function(){$('advsrch').setStyle('visibility', 'hidden')});


    $$('#menucontainer td.menucell').each(function(el)
    {
        el.addEvent('mouseover', cleartimeout)
        el.addEvent('mouseover', showmenu)
        el.addEvent('mouseout', settimeout)
    })

    $$('#submenucontainer div.sub').each(function(el)
    {
        el.addEvent('mouseover', cleartimeout)
        el.addEvent('mouseout', settimeout)
    })

    $$('#menuitemscontainer tr.mrow').each(function(el)
    {
        el.addEvent('mouseover', cleartimeout)
        el.addEvent('mouseover', function(el){this.setStyle('background-color', '#dbeece')})
        el.addEvent('mouseover', submenu)
        el.addEvent('mouseout', settimeout)
        el.addEvent('mouseout', function(el){this.setStyle('background-color', 'transparent')})
    })
}

function showmenu()
{

    /* hideall()
    mx = this.getPosition().x + 20    
    if (this.id=='m1') mx = mx - 4;
    my = this.getPosition().y + 30;
    if( $(this.id+'i') )
    	$(this.id+'i').setStyles({display: 'block', top: my+'px', left: mx+'px'}) */
    
    /* Mootools 1.1 version */
    hideall()
    mx = this.getPosition().left + 20    
    if (this.id=='m1') mx = mx - 4;
    my = this.getPosition().bottom + 3    
    if( $(this.id+'i') )
    $(this.id+'i').setStyles({display: 'block', top: my+'px', left: mx+'px'})
    
}

function hideall()
{
    $('advsrch').setStyle('visibility', 'hidden');
    hidesub();
    var c = 1;
    while(c<7)
    {
        tmp = 'm' + c + 'i'
        c++
        if( document.getElementById(tmp) )
        	document.getElementById(tmp).style.display = 'none';
    }
}

function hidesub(big)
{
    if (!big)
    {
        $$('#submenucontainer div.sub').each(function(el){el.setStyle('display', 'none');})
    } else {
        big.setStyle('display', 'none')
    }
}

function settimeout()
{
    myT = hideall.delay(1000)
}

function cleartimeout()
{
    myT = $clear(myT)
}

function submenu()
{    
    /* 1.2
    hidesub();
    triangle = 't' + this.id
    if($(triangle))
    {
        var offset = (this.id.test('_0')) ? 20 : 19
        subname = 's' + this.id
        x = $(triangle).getCoordinates().right + 6
        y = $(triangle).getCoordinates().bottom - offset
        $(subname).setStyles({left: x+'px', top: y+'px', display: 'block'});
    } */
    hidesub();
    triangle = 't' + this.id
    if($(triangle))
    {
        var offset = (this.id.test('_0')) ? 20 : 19
        subname = 's' + this.id
        x = $(triangle).getPosition().right + 6
        y = $(triangle).getPosition().bottom - offset
        $(subname).setStyles({left: x+'px', top: y+'px', display: 'block'});
    }
}

function openAdvanced()
{
    var advPanel = $('advsrch');
    var x = $('frame').getPosition().right - advPanel.getPosition().width;
    var y = this.getPosition().bottom + 3;
    advPanel.setStyles({top: y + 'px', left: x+'px', visibility: 'visible'})
}


sfHover = function() {
    var sfEls = document.getElementById("share");
    if (sfEls) {
        sfEls.onmouseover=function() {
            this.className+=" sfhover";
        }
        sfEls.onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
