
// Node object

function Node1(id, pid, name, url, title, target) {

        this.id = id;
        this.pid = pid;
        this.name = name;
        this.url = url;
        this.title = title;
        this.target = target;
        this._ai;
        this._p;
};



// Tree object

function goriztree(objName) {

        this.config = {
                target          : '_blank',
                useSelection    : false,
                useStatusText   : false

        }
        this.obj = objName;
        this.aNodes = [];
        this.root = new Node(-1);
        this.selectedNode = null;
        this.selectedFound = false;
        this.completed = false;
};



// Adds a new node to the node array

goriztree.prototype.add = function(id, pid, name, url, title, target) {
        this.aNodes[this.aNodes.length] = new Node1(id, pid, name, url, title, target);
};



// Outputs the tree to the page

goriztree.prototype.toString = function() {
        var str = '<div class="menu">';
        str +='<div id="block_menu">';
        if (document.getElementById)
        {
                        str += this.addNode(0);
        }
        else
                        str += 'Browser not supported.';
        str +='</div>';
        str +='<div class="footer_menu"></div>';
        str +='</div>';
        this.completed = true;
        return str;
};



// Creates the tree structure

goriztree.prototype.overPunkt = function (obj_listPunkt)
{
  obj_listPunkt.childNodes[1].style.display="block";
  obj_listPunkt.childNodes[1].style.top=obj_listPunkt.offsetHeight;
  obj_listPunkt.style.background="#d1d3d4";
  obj_listPunkt.style.padding=0;
//  obj_listPunkt.style.margin=3;
  obj_listPunkt.childNodes[0].style.border="solid 1px #000";
  obj_listPunkt.childNodes[0].style.borderBottom="none";
  color_text=obj_listPunkt.style.color;
  obj_listPunkt.style.color="#000000";
}

goriztree.prototype.outPunkt = function(obj_listPunkt)
{
  obj_listPunkt.childNodes[1].style.display="none";
  obj_listPunkt.style.background="transparent";
  obj_listPunkt.style.padding=0;
  obj_listPunkt.style.paddingBottom=0;
  obj_listPunkt.childNodes[0].style.border="none";
  obj_listPunkt.style.color=color_text;
}

goriztree.prototype.addNode = function(apid) {
        var str = '';
        var n=0;
        for (n; n<this.aNodes.length; n++) {
                if (this.aNodes[n].pid == apid)
                {
                                                if (apid==0)
                                                {
                                                    if (this.aNodes[n].url=='')
                                                             str +='<div class="punkt" onMouseOver="'+this.obj+'.overPunkt(this);" onMouseOut="'+this.obj+'.outPunkt(this);"><div class="a_head">'+this.aNodes[n].name+'</div>';
                                                    else
                                                             str +='<div class="punkt" onMouseOver="'+this.obj+'.overPunkt(this);" onMouseOut="'+this.obj+'.outPunkt(this);"><div class="a_head"><a class="a_head" href="' + this.aNodes[n].url + '" title="' + this.aNodes[n].title + '" target="' + this.aNodes[n].target + '">'+this.aNodes[n].name+'</a></div>';
                                                    str +='<div class="list_punkts"><div class="kont">';
                                                    str +=this.addNode(this.aNodes[n].id);
                                                }
                                                else
                                                {
                                str += this.node(this.aNodes[n], n);
                                                }
                                                if (apid==0)
                                                {
                                                str +='</div></div></div>';
                                                }
                }
        }
        return str;
};



// Creates the node icon, url and text

goriztree.prototype.node = function(node, nodeId) {
        var str = '';
//        alert(node.title+' '+node.url)
        if (node.url) {
                str += '<a id="' + this.obj + nodeId + '" href="' + node.url + '"';
                if (node.title) str += ' title="' + node.title + '"';
                if (node.target) str += ' target="' + node.target + '"';
                str += '><div class="podpunkt"><div>';
        }
        else
        {
                str += '<a id="' + this.obj + nodeId + '" href="#"';
                if (node.title) str += ' title="' + node.title + '"';
                if (node.target) str += ' target="' + node.target + '"';
                str += '><div class="podpunkt"><div>';
        }
        if (node.name) str += node.name+'</div></div></a>';
        if (node.pid!=0) this.addNode(node.id);
        return str;
};
