//if browser version supports the following elements, initialise the page
if (document.getElementById && document.getElementsByTagName && document.createElement) {
    window.onload = initPage;
}

//initialise all dynamic elements on the page
function initPage() {
    if (document.bgColor== "#000001") {
        //check if images and CSS are enabled	
		
        //find all headings in the navigation section
        var t_nav = document.getElementById('navigation').getElementsByTagName('h3')
        //find all headings in the news section
        var t_news = document.getElementById('body').getElementsByTagName('h2')
        //find all news articles
        var t_cap = document.getElementById('body').getElementsByTagName('p')
        //find menu items
        //var t_bonsai = document.getElementById('bonsai').getElementsByTagName('li');
        //find page caps
        var t_cap = document.getElementById('body').childNodes;
        
        var y = 0;
		
        //identify the first Paragraphs after the news titles - mark them for a first letter change
        for (var i = 0; i < t_cap.length; i++) {
            if (t_cap[i].nodeName == "H2") { 
                y = 1; 
            }
            if (t_cap[i].nodeName == "P" && y == 1 ) {
                t_cap[i].className="news";
                y = 0;
            }
        }
        
        //set background image with dynamic text heading
        /*
		 for (var i = 0; i < t_nav.length; i++) {
            // t_nav[i].style.backgroundImage = "url('http://www.dladventures.com/images/gui/u01/interface/t_navigation.php?text=" + t_nav[i].innerHTML + "')";
            t_nav[i].style.backgroundImage = "url('http://www.umbrae.org/gui/u01/images/interface/t_navigation.php?text=" + t_nav[i].innerHTML + "')";
        }
		 */
        
        //set background image with dynamic text heading
        /*
        for (var i = 0; i < t_news.length; i++) {
            t_news[i].style.backgroundImage = "url('http://www.dladventures.com/images/gui/u01/interface/t_body.php?text=" + t_news[i].innerHTML + "')";
        }
        */
        
        //set first letter to javascript letter
        /*
		 for (var i = 0; i < t_cap.length; i++) {
            if (t_cap[i].className == "news" ) {
                //get the paragraph text an trim any non alpha numeric characters leading
                var theStr = t_cap[i].innerHTML.replace( /^\s+/g, "" );
                //get the first Letter of the paragraph
                var theLet = theStr.substring(1,0).toUpperCase();
                //set the first Letter as an image
                t_cap[i].innerHTML = "<img class=\"capital\" src=\"/gui/u01/images/capitals/"+theLet+".gif\" alt=\"\" />" + theStr.substring(1,theStr.length);
            }
        }
		 */
        
        //set up menu
        /* disable if not present
        for (var i = 0; i < t_bonsai.length; i++) {
            listitem = t_bonsai[i].childNodes;
            for (var x=0;x<listitem.length;x++) {
                if(listitem[x].nodeName=="A"){
                    listitem[x].onclick = function () {browser_hideShowDir(this.parentNode);return false;}
                }
                if(listitem[x].nodeName=="UL") {
                    listitem[x].className = "hide";
                    listitem = t_bonsai[i].childNodes;
                }
            }
        }
        */
    }
}

//hides and shows submenus
function browser_hideShowDir(item) {
    listitem = item.childNodes;
    for (var i=0;i<listitem.length;i++){
        if(listitem[i].nodeName=="UL") {
            listitem=listitem[i];
            break;
        }
    }
    if (listitem.className == "hide") {
        listitem.className = "show";
    } else {
        listitem.className = "hide";
    }
}
