function TreeItem(el){
        this.frame = el;
}

TreeItem.prototype.toggle = function() {
        if ( this.frame.className == 'closed' )
                this.frame.className = 'opened';
        else
                this.frame.className = 'closed';
}

function processTree() {
        var tree = document.getElementById('product_tree');
        if (! tree)
                return;
        var treeItems = tree.childNodes;
        var j=0;
        for (var i=0,I=treeItems.length;i<I;i++) {
                if (treeItems[i].nodeType == 1 && treeItems[i].className.indexOf('empty') == -1) {
                        items[j] = new TreeItem(treeItems[i]);
                        items[j].frame.id = 'ti_'+j;
                        if(items[j].frame.getElementsByTagName('h3')[0]){
                                items[j].frame.getElementsByTagName('h3')[0].onclick = function() { items[this.parentNode.id.substr(3)].toggle(); }
                        }
                        j++;
                }
        }
}

function addOnloadEvent(func) {
        var current = window.onload;
        if (typeof current == "function") {
                window.onload = function() {
                        current();
                        func();
                }
        } else {
                window.onload = func;
        }
}

addOnloadEvent(function() { processTree(); });
var items = new Object();