function collapse(dom)
{
    if( !dom || typeof(dom) == "undefined" ) return false;
    if( dom.tagName.toUpperCase() != "A" && dom.tagName.toUpperCase() != "UL" ) return false;
    var h4 = dom.parentNode;
    if( !h4 ) return false;
    var found = null;
    for( var next = h4.nextSibling; next; next = next.nextSibling )
    {
        if( next.nodeType == 1 && next.tagName.toUpperCase() == "UL" )
        {
            found = next;
            break;
        }
    }
    if( !found ) return false;
    h4.className = "collapsed";
    dom.className = h4.className;
    dom.onclick = function(){ expand(dom); return false; };
    found.className = dom.className;
    return false;
}
function expand(dom)
{
    if( !dom || typeof(dom) == "undefined" ) return false;
    if( dom.tagName.toUpperCase() != "A" && dom.tagName.toUpperCase() != "UL" ) return false;
    var h4 = dom.parentNode;
    if( !h4 ) return false;
    var found = null;
    for( var next = h4.nextSibling; next; next = next.nextSibling )
    {
        if( next.nodeType == 1 && next.tagName.toUpperCase() == "UL" )
        {
            found = next;
            break;
        }
    }
    if( !found ) return false;
    h4.className = "expanded";
    dom.className = h4.className;
    dom.onclick = function(){ collapse(dom); return false; };
    found.className = dom.className;
    renderUl( found );
    return false;
}
function renderUl(dom)
{
    if( !dom || typeof(dom) == "undefined" ) return false;
    if( dom.tagName.toUpperCase() != "UL" ) return false;
    var li = dom.getElementsByTagName( "LI" );
    var ul = dom.getElementsByTagName( "UL" );
    var real = li.length - ul.length - 1; // one less for more
    var pos = 0;
    var max = 3;
    if( real < max ) max = real;
    for( var i = 0, imax = li.length; i < imax; i++ )
    {
        var child = getFirstChild( li[i] );
        if( child && child.tagName == "UL" )
        {
            continue;
        }
        if( pos < max )
        {
            li[i].style.display = "";
        }
        else
        {
            li[i].style.display = "none";
            if( real > max )
            {
                var a = getFirstChild( li[i] );
                if( a )
                {
                    if( a.className.toUpperCase() == "MORE" )
                    {
                        li[i].style.display = "";
                    }
                }
            }
        }
        pos++;
    }
    return false;
}
function showMore(dom)
{
    if( !dom || typeof(dom) == "undefined" ) return false;
    var li = dom.parentNode;
    if( li.tagName.toUpperCase() != "LI" ) return false;
    var ul = li.parentNode;
    if( ul.tagName.toUpperCase() != "UL" ) return false;
    li = ul.getElementsByTagName( "LI" );
    for( var i = 0, imax = li.length; i < imax; i++ )
    {
        li[i].style.display = "";
        var a = li[i].getElementsByTagName( "A" );
        if( a && a.length > 0 )
        {
            if( a[0].className.toUpperCase() == "MORE" )
            {
                li[i].style.display = "none";
            }
        }
    }
    return false;
}
function getFirstChild(dom)
{
    if( !dom || typeof(dom) == "undefined" ) return null;
    for( var i = 0, imax = dom.childNodes.length; i < imax; i++ )
    {
        if( dom.childNodes[i].nodeType == 1 )
        {
            return dom.childNodes[i];
        }
    }
    return null;
}
function getChildren(dom)
{
    var ret = [];
    if( !dom || typeof(dom) == "undefined" ) return ret;
    for( var i = 0, imax = dom.childNodes.length; i < imax; i++ )
    {
        if( dom.childNodes[i].nodeType == 1 )
        {
            ret.push( dom.childNodes[i] );
        }
    }
    return ret;
}
function loadPage(dom)
{
    if( typeof(dom) == "string" ) dom = document.getElementById( dom );
    if( !dom || typeof(dom) == "undefined" ) return false;
    var elements = getChildren(dom);
    if( elements.length > 0 )
    {
        for( var i = 0, imax = elements.length - 1; i < imax; i++ )
        {
            var h4 = null;
            var ul = null;
            if( elements[i].tagName.toLowerCase() == "h4" ) h4 = elements[i];
            if( elements[i+1].tagName.toLowerCase() == "ul" ) ul = elements[i+1];
            if( !h4 || !ul ) continue;
            var li = getChildren(ul);
            if( li.length > 1 )
            {
                h4.style.display = "block";
                var alink = h4.getElementsByTagName( "A" );
                if( alink )
                {
                    expand(alink[0]);
                }
            }
            i++;
        }
    }
    return true;
}
 
$(document).ready(function(){
  loadPage('techresources');
});

