//global variable to allow console inspection of tree:
var tree;
var js = YAHOO.util.Dom;

var totalItems;

//anonymous function wraps the remainder of the logic:
(function() {
	var treeInit = function() {

        var count = 0;

        var getTopElement = YAHOO.util.Dom.getElementsByClassName('addClick', 'span');

        for(var i=0;i < getTopElement.length; i++) {
            YAHOO.util.Event.addListener(
                getTopElement[i], "click", showItem,
                {
                    activeItem : (i+1)
                }
            );
            count++;

        }

        totalItems = count;

    };

	//Add an onDOMReady handler to build the tree when the document is ready
   YAHOO.util.Event.onDOMReady(treeInit);

})();

showItem = function(e, current){
    var d = document.getElementById("nav-"+current.activeItem);

    if(js.hasClass(d, "showItem")){
        js.removeClass(d, "showItem");
        js.addClass(d, "topLevel");
    }
    else{
        hideAllElement();
        js.removeClass(d, "topLevel");
        js.addClass(d, "showItem");
    }
}

hideAllElement = function(){

    var getTopElement = YAHOO.util.Dom.getElementsByClassName('showItem', 'li');
    for(var i=0;i < getTopElement.length; i++) {
        js.removeClass(getTopElement[i], "showItem");
        js.addClass(getTopElement[i], "topLevel");
    }
}


