function layerSelect(id) {
    var obj;
    for(var i = 1; ; i++) {
        obj = document.getElementById("nav" + i);

        if(obj == undefined)
            break;
        if(obj.id != id) {
            obj.style.display = 'none';
        }
    }

    var click = document.getElementById(id) ;
    if ( click.style.display == 'block' ) {
            click.style.display = 'none' ;
    } else {
            click.style.display = 'block' ;
    }

    listingCategory(id);
}

function listingCategory(id) {
    var currentH = parseInt(($(window).height() - 82) / 23);
    var selectedlayernumber = id.replace(/nav/,'');
    var prateObj = $('#' + id);
    prateObj.children().remove();
    var listcount = 0;
    topList = 0;
    bottomList = 0;
    
    for (var category in imginfo[selectedlayernumber])
    {
        var listlink;
        listcount++;

        if (listcount == 0 || currentH >= listcount) {
            listlink = $('<li id="list' + listcount + '"><a target="_self" href="/?category=' + selectedlayernumber + '-' + category + '-1"' +
                ' Onfocus="this.blur();" OnMouseOver="moveTo(\'' + id + '\', \'' + listcount + '\');" >' + imginfo[selectedlayernumber][category] + '</a></li>');
            bottomList++;
        }
        else {
            listlink = $('<li id="list' + listcount + '" style="display:none;"><a target="_self" href="/?category=' + selectedlayernumber + '-' + category + '-1"' +
                ' Onfocus="this.blur();" OnMouseOver="moveTo(\'' + id + '\', \'' + listcount + '\');" >' + imginfo[selectedlayernumber][category] + '</a></li>');
        }
        prateObj.prepend(listlink);
    }
    if (listcount >= currentH)
        prateObj.height(currentH * 23);
    else
        prateObj.height(listcount * 23);
}

function moveTo(parentId, targetId) {
    var prateObj = $('#' + parentId);
    var prateObjChildrenLength = prateObj.children().length;
    var visibleListObj;
    var disableListObj;

    if (targetId - 1 == topList && targetId != 1) {
        visibleListObj = $('#' + parentId + ' #list' + (topList));
        disableListObj = $('#' + parentId + ' #list' + (bottomList));
        topList--;
        bottomList--;
    }
    else if (targetId == bottomList && targetId != prateObjChildrenLength) {
        visibleListObj = $('#' + parentId + ' #list' + (bottomList + 1));
        disableListObj = $('#' + parentId + ' #list' + (topList + 1));
        topList++;
        bottomList++;
    }

    if (visibleListObj) {
        visibleListObj.show(150);
        disableListObj.hide(150);
    }
}

