﻿    function HelpTree(containerID,contentPanel,rootName)
    {
        //AddNode(toolName,html)
        this.nodes= new Array();
        this.sort = true;
        this.container = containerID;
        this.contentPanel = contentPanel;
        this.rootName = rootName;
        this.created = false;
        this.root;
    }
    
    HelpTree.prototype.AddNode = function(toolName,html,iconPath,nodeIconPath)
    {  
        this.nodes.push(new Array());
        this.nodes[this.nodes.length-1][0] = toolName;
        this.nodes[this.nodes.length-1][1] = html;
        this.nodes[this.nodes.length-1][2] = iconPath;
        this.nodes[this.nodes.length-1][3] = nodeIconPath;
    }
    
    HelpTree.prototype.Load = function(sort)
    {
        if (this.created == false)
        {
            this.created = true;
            this.LoadAGSHelpTree(sort)
        }
    }
    
    
    HelpTree.prototype.LoadAGSHelpTree = function(sort)
    {
    
        //create tree
        var Tree = Ext.tree;
        var tree = new Tree.TreePanel(this.container, {
            animate:true
            });
            
        //Add this.root node.    
         this.root = new Ext.tree.TreeNode({
           text: this.rootName,
           draggable:false
        });
        
    tree.setRootNode(this.root);
    if (sort)
    {
        this.nodes.sort();
    }
   
    for (var i=0; i<=this.nodes.length-1; i++)
    {
      var node = this.root.appendChild(new Ext.tree.TreeNode({
          text: this.nodes[i][0],
          icon: this.nodes[i][3],
          allowDrag: false
        }));
         this.SetUpNodeClicks(this,node,i)      
    }
    tree.render();
    tree.expandAll();
    }

    HelpTree.prototype.SetUpNodeClicks = function(copy,node,index)
    {
        node.on('click', function() { copy.ShowHelpContent(index) });
    }


    HelpTree.prototype.ShowHelpContent = function(i)
    {
        var cp = getEl(this.contentPanel);
        var html = '';
        var icon = this.nodes[i][2];
        if (icon != undefined)
        {
            icon = '<img src="'+icon+'">';
        }
        else
        {
            icon = '';
        }    
        //title and icon
        html += icon+'<span style="font-size:18px;"> '+this.nodes[i][0]+'</span>'
        html +='<hr size="1">';
        
        //body
        html += this.nodes[i][1];
        
        cp.innerHTML = html;
    }
    
    