var expandedImage='../img/exp.gif';
var contractedImage='../img/contr.gif';
var bulletImage='../img/item.gif';
var currentImage='../img/curr.gif';
var divImage = new Array();
divImage["none"] = contractedImage;
divImage["block"] = expandedImage;
divImage["item"] = bulletImage;
divImage["curr"] = currentImage;
var gid = 0;
var style = new Array();
var cur = new Array();
var curdepth = 0;
var expand = false;
var margin = 10;

var intro = ">>>>>";
var path = plink = "";
var tags = new Array();
var first = false;
var pathCount = 0;

function startMenu()
{
    depth = 0;
    style = arguments;
        document.writeln('<table width="100%" border="0" valign="top" cellspacing="0" cellpadding="10">\n');
        document.writeln('<tr><td valign="top"><div>\n');
    return;
}

function separator()
{
    document.writeln('</div></td></tr>\n');
    document.writeln('<tr><td valign="top" style="border-top: 1px solid #3081b9;"><div>\n');
    return;
}

function initPath( st1, st2 )
{
    tagl = 0;
    path = '<span class="' + st2 + '">'
    plink = st1;
    return;
}

function subMenu( tag, def, deftag )
{
    var str, spnid, divid, imgid;

    cur[++depth] = ++gid;
    divid = "div" + gid;
    spnid = "spn" + gid;
    imgid = "img" + gid;
    str = '<span id="' + spnid + '" ';
    str += 'onClick="flipState(' + "'" + divid + "', '" + imgid + "');" + '">';
    str += '<img style="margin-right: 8px;" src="' + contractedImage + '" id="' + imgid + '" name="' + tag + '" ' + ' border="0" />';

    str += '<span class="' + style[depth-1] + '" onMouseOver="this.className=' + "'" + style[depth-1] + "-hover'";
    str += '" onMouseOut="this.className=' + "'" + style[depth-1] + "'" + '">' + tag + "</span></span><br>";

    str += '<div id="' + divid + '" style="display:none; margin-left: ' + margin + 'px;">';
    document.writeln( str );

    first = true;
    if( def == null ) {
        tags[tagl++] = tag;
    }
    else
    {
        if( deftag == null )
            deftag = intro;
        tags[tagl++] = '<a class="' + plink + '" href="' + def + '">' + tag + '</a>';
    }
    return;
}

function endSub()
{
    var str;

    if( expand && curdepth == depth ) {
        flipState( "div" + cur[depth], "img" + cur[depth] );
        if( --curdepth == 0 ) {
            expand = false;
            tags = new Array();
            tagl = 1;
        }
    }
    if( depth > 0 )
    {
        depth--;
        str = '</div>\n';
        document.writeln( str );
    }
    if( ! expand )
        tagl--;
    return;
}

function item( tag, page, hint )
{
    var html, str;

    html = '<img style="margin-right: 8px;" src="';
    loc = document.location.pathname + document.location.search;
    if( loc.indexOf( page ) > 0 &&
      ( loc.length - loc.indexOf( page ) == page.length ) ) {
        expand = true;

        if( !first && pathCount == 0 )
            tags[tagl] = '<a class="' + plink + '" href="' + page + '" title="' + hint + '">' + tag + '</a>';
        else
            tags[tagl] = tag;
        
        if(pathCount > 0){
          path += '<br>';
        }

        for( i = 0; i < tagl; i++ )
            path += tags[i] + ' &gt ';
        path += tags[tagl];
        
        tags = new Array();
        tagl = 0;
        pathCount++;

        curdepth = depth;
        html += divImage["curr"];
        tag = "<b>" + tag + "</b>";
    }
    else
        html += divImage["item"];
    html += '"><a class="' + style[depth] + '" href="' + page + '" title="' + hint + '">' + tag + '</a><br \>\n';
    document.writeln( html );
    first = false;
    return;
}

function closeMenu()
{
    path += '</span>';
    document.writeln('</div></td></tr>\n</table>\n');
    return;
}

function flipState( menu, image ) {
    if( is.w3c ) {
        if( document.getElementById( menu ).style.display == "none" ) {
            document.getElementById( menu ).style.display = "block";
            document.getElementById( image ).src = divImage["block"];
        } else {
            document.getElementById( menu ).style.display = "none";
            document.getElementById( image ).src = divImage["none"];
        }
    } else if( is.ie4 ) {
        if( document.all[ menu ].style.display == "none") {
            document.all[ menu ].style.display = "block";
            document.all[ image ].src = divImage["block"];
        } else {
            document.all[ menu ].style.display = "none";
            document.all[ image ].src = divImage["none"];
        }
    } else {
        alert( "Can't operate with the " + navigator.appName + " browser." );
    }
    return;
}
