/**
 * @version $Id: catalogue-tree.js 196 2006-12-18 16:42:10Z developer $
 * Catalogue tree control object
 */
(CatalogueTree = {
    /**
     * Current node
     * @type object
     * @private
     */
    _Node : [],

    /**
     * Constructor of control
     * @constructor
     */
    init: function(){
        //void
    },

    /**
     * Node setter
     */
     setNode: function(mValue){
        try{
            this._Node = mValue;
        }catch(e){
            // TODO: handle exception
        }
     },

    /**
     * Node getter
     */
     getNode: function(){
        return CatalogueTree._Node;
     },

     /****************************************************************/

    /**
     * Node toggler
     */
    ToggleNode: function(oController, sMode){
        try{
            if(sMode == 'outline'){
                if(oController.nextSibling.nextSibling.nextSibling.nextSibling.tagName == 'UL'){
                    this.setNode(oController.nextSibling.nextSibling.nextSibling.nextSibling);
                }else{
                    this.setNode(oController.nextSibling.nextSibling.nextSibling);
                }
                if(this.getNode().offsetWidth == 0){
                    this.getNode().style.display = 'block';
                }else{
                    this.getNode().style.display = 'none';
                }
            }else{
                this.setNode(oController.nextSibling.nextSibling.nextSibling);
                CatalogueTree.setNodeStateIndicator(oController);
                if(this.getNode().offsetWidth == 0){
                    oController.className = 'node opened-node';
                    this.getNode().style.display = 'block';
                }else{
                    oController.className = 'node';
                    this.getNode().style.display = 'none';
                }
            }
        }catch(e){
            // TODO: handle exception
        }
    },

    /**
      * Control state indicator setter
      */
     setNodeStateIndicator: function(oNodeSet){
        try{
            oNodeStateIndicator = oNodeSet.previousSibling;
            if(oNodeStateIndicator.src.indexOf('closed.gif') != -1){
                oNodeStateIndicator.src = oNodeStateIndicator.src.replace("closed.gif", "opened.gif");
            }else{
               oNodeStateIndicator.src = oNodeStateIndicator.src.replace("opened.gif", "closed.gif");
            }
        }catch(e){
            // TODO: handle exception
        }
     },

     /**
      * Expand all nodes
      */
     ExpandAll: function(){
        try{
            oHTMLCollection = document.getElementById('catalogue-tree-container').getElementsByTagName('UL');
            for(i = 0; i < oHTMLCollection.length; i++){
                oHTMLCollection[i].style.display = 'block';
            }
            oHTMLCollection = document.getElementById('catalogue-tree-container').getElementsByTagName('IMG');
            for(i = 0; i < oHTMLCollection.length; i++){
                if(oHTMLCollection[i].src.indexOf('closed.gif') != -1){
                    oHTMLCollection[i].src = oHTMLCollection[i].src.replace("closed.gif", "opened.gif");
                }
            }
        }catch(e){
            // TODO: handle exception
        }
     },

     /**
      * Collapse all nodes
      */
     CollapseAll: function(){
        try{
            oHTMLCollection = document.getElementById('catalogue-tree-container').getElementsByTagName('UL');
            for(i = 0; i < oHTMLCollection.length; i++){
                oHTMLCollection[i].style.display = 'none';
            }
            oHTMLCollection = document.getElementById('catalogue-tree-container').getElementsByTagName('IMG');
            for(i = 0; i < oHTMLCollection.length; i++){
                if(oHTMLCollection[i].src.indexOf('opened.gif') != -1){
                    oHTMLCollection[i].src = oHTMLCollection[i].src.replace("opened.gif", "closed.gif");
                }
            }
        }catch(e){
            // TODO: handle exception
        }
     }

}).init();