/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
YAHOO.widget.TreeView = function(id) {
    if (id) {
        this.init(id);
    }
};
YAHOO.widget.TreeView.nodeCount = 0;
YAHOO.widget.TreeView.prototype = {id:null,_nodes:null,locked:false,_expandAnim:null,_collapseAnim:null,_animCount:0,maxAnim:2,setExpandAnim:function(_2) {
    if (YAHOO.widget.TVAnim.isValid(_2)) {
        this._expandAnim = _2;
    }
},setCollapseAnim:function(_3) {
    if (YAHOO.widget.TVAnim.isValid(_3)) {
        this._collapseAnim = _3;
    }
},animateExpand:function(el) {
    if (this._expandAnim && this._animCount < this.maxAnim) {
        var _5 = this;
        var a = YAHOO.widget.TVAnim.getAnim(this._expandAnim, el, function() {
            _5.expandComplete();
        });
        if (a) {
            ++this._animCount;
            a.animate();
        }
        return true;
    }
    return false;
},animateCollapse:function(el) {
    if (this._collapseAnim && this._animCount < this.maxAnim) {
        var _7 = this;
        var a = YAHOO.widget.TVAnim.getAnim(this._collapseAnim, el, function() {
            _7.collapseComplete();
        });
        if (a) {
            ++this._animCount;
            a.animate();
        }
        return true;
    }
    return false;
},expandComplete:function() {
    --this._animCount;
},collapseComplete:function() {
    --this._animCount;
},init:function(id) {
    this.id = id;
    this._nodes = new Array();
    YAHOO.widget.TreeView.trees[id] = this;
    this.root = new YAHOO.widget.RootNode(this);
},draw:function() {
    var _8 = this.root.getHtml();
    document.getElementById(this.id).innerHTML = _8;
    this.firstDraw = false;
},regNode:function(_9) {
    this._nodes[_9.index] = _9;
},getRoot:function() {
    return this.root;
},setDynamicLoad:function(_10) {
    this.root.setDynamicLoad(_10);
},expandAll:function() {
    if (!this.locked) {
        this.root.expandAll();
    }
},collapseAll:function() {
    if (!this.locked) {
        this.root.collapseAll();
    }
},getNodeByIndex:function(_11) {
    var n = this._nodes[_11];
    return (n)?n:null;
},getNodeByProperty:function(_13, _14) {
    for (var i in this._nodes) {
        var n = this._nodes[i];
        if (n.data && _14 == n.data[_13]) {
            return n;
        }
    }
    return null;
},onExpand:function(_16) {
},onCollapse:function(_17) {
}};
YAHOO.widget.TreeView.trees = [];
YAHOO.widget.TreeView.getTree = function(_18) {
    var t = YAHOO.widget.TreeView.trees[_18];
    return (t)?t:null;
};
YAHOO.widget.TreeView.getNode = function(_20, _21) {
    var t = YAHOO.widget.TreeView.getTree(_20);
    return (t)?t.getNodeByIndex(_21):null;
};
YAHOO.widget.TreeView.addHandler = function(el, _22, fn, _24) {
    _24 = (_24)?true:false;
    if (el.addEventListener) {
        el.addEventListener(_22, fn, _24);
    } else {
        if (el.attachEvent) {
            el.attachEvent("on" + _22, fn);
        } else {
            el["on" + _22] = fn;
        }
    }
};
YAHOO.widget.TreeView.preload = function() {
    var _25 = ["ygtvtn","ygtvtm","ygtvtmh","ygtvtp","ygtvtph","ygtvln","ygtvlm","ygtvlmh","ygtvlp","ygtvlph","ygtvloading"];
    var sb = [];
    for (var i = 0; i < _25.length; ++i) {
        sb[sb.length] = "<span class=\"" + _25[i] + "\">&nbsp;</span>";
    }
    var f = document.createElement("div");
    var s = f.style;
    s.position = "absolute";
    s.top = "-1000px";
    s.left = "-1000px";
    f.innerHTML = sb.join("");
    document.body.appendChild(f);
};
YAHOO.widget.TreeView.addHandler(window, "load", YAHOO.widget.TreeView.preload);
YAHOO.widget.Node = function(_29, _30, _31) {
    if (_30) {
        this.init(_29, _30, _31);
    }
};
YAHOO.widget.Node.prototype = {index:0,children:null,tree:null,data:null,parent:null,depth:-1,href:null,target:"_self",expanded:false,multiExpand:true,renderHidden:false,childrenRendered:false,previousSibling:null,nextSibling:null,_dynLoad:false,dataLoader:null,isLoading:false,hasIcon:true,init:function(_32, _33, _34) {
    this.data = _32;
    this.children = [];
    this.index = YAHOO.widget.TreeView.nodeCount;
    ++YAHOO.widget.TreeView.nodeCount;
    this.expanded = _34;
    if (_33) {
        this.tree = _33.tree;
        this.parent = _33;
        this.href = "javascript:" + this.getToggleLink();
        this.depth = _33.depth + 1;
        this.multiExpand = _33.multiExpand;
        _33.appendChild(this);
    }
},appendChild:function(_35) {
    if (this.hasChildren()) {
        var sib = this.children[this.children.length - 1];
        sib.nextSibling = _35;
        _35.previousSibling = sib;
    }
    this.tree.regNode(_35);
    this.children[this.children.length] = _35;
    return _35;
},getSiblings:function() {
    return this.parent.children;
},showChildren:function() {
    if (!this.tree.animateExpand(this.getChildrenEl())) {
        if (this.hasChildren()) {
            this.getChildrenEl().style.display = "";
        }
    }
},hideChildren:function() {
    if (!this.tree.animateCollapse(this.getChildrenEl())) {
        this.getChildrenEl().style.display = "none";
    }
},getElId:function() {
    return "ygtv" + this.index;
},getChildrenElId:function() {
    return "ygtvc" + this.index;
},getToggleElId:function() {
    return "ygtvt" + this.index;
},getEl:function() {
    return document.getElementById(this.getElId());
},getChildrenEl:function() {
    return document.getElementById(this.getChildrenElId());
},getToggleEl:function() {
    return document.getElementById(this.getToggleElId());
},getToggleLink:function() {
    return "YAHOO.widget.TreeView.getNode('" + this.tree.id + "'," + this.index + ").toggle()";
},collapse:function() {
    if (!this.expanded) {
        return;
    }
    if (!this.getEl()) {
        this.expanded = false;
        return;
    }
    this.hideChildren();
    this.expanded = false;
    if (this.hasIcon) {
        this.getToggleEl().className = this.getStyle();
    }
    this.tree.onCollapse(this);
},expand:function() {
    if (this.expanded) {
        return;
    }
    if (!this.getEl()) {
        this.expanded = true;
        return;
    }
    if (!this.childrenRendered) {
        this.getChildrenEl().innerHTML = this.renderChildren();
    }
    this.expanded = true;
    if (this.hasIcon) {
        this.getToggleEl().className = this.getStyle();
    }
    if (this.isLoading) {
        this.expanded = false;
        return;
    }
    if (!this.multiExpand) {
        var _37 = this.getSiblings();
        for (var i = 0; i < _37.length; ++i) {
            if (_37[i] != this && _37[i].expanded) {
                _37[i].collapse();
            }
        }
    }
    this.showChildren();
    this.tree.onExpand(this);
},getStyle:function() {
    if (this.isLoading) {
        return "ygtvloading";
    } else {
        var loc = (this.nextSibling)?"t":"l";
        var _39 = "n";
        if (this.hasChildren(true) || this.isDynamic()) {
            _39 = (this.expanded)?"m":"p";
        }
        return "ygtv" + loc + _39;
    }
},getHoverStyle:function() {
    var s = this.getStyle();
    if (this.hasChildren(true) && !this.isLoading) {
        s += "h";
    }
    return s;
},expandAll:function() {
    for (var i = 0; i < this.children.length; ++i) {
        var c = this.children[i];
        if (c.isDynamic()) {
            alert("Not supported (lazy load + expand all)");
            break;
        } else {
            if (!c.multiExpand) {
                alert("Not supported (no multi-expand + expand all)");
                break;
            } else {
                c.expand();
                c.expandAll();
            }
        }
    }
},collapseAll:function() {
    for (var i = 0; i < this.children.length; ++i) {
        this.children[i].collapse();
        this.children[i].collapseAll();
    }
},setDynamicLoad:function(_41) {
    this.dataLoader = _41;
    this._dynLoad = true;
},isRoot:function() {
    return (this == this.tree.root);
},isDynamic:function() {
    var _42 = (!this.isRoot() && (this._dynLoad || this.tree.root._dynLoad));
    return _42;
},hasChildren:function(_43) {
    return (this.children.length > 0 || (_43 && this.isDynamic() && !this.childrenRendered));
},toggle:function() {
    if (!this.tree.locked && (this.hasChildren(true) || this.isDynamic())) {
        if (this.expanded) {
            this.collapse();
        } else {
            this.expand();
        }
    }
},getHtml:function() {
    var sb = [];
    sb[sb.length] = "<div class=\"ygtvitem\" id=\"" + this.getElId() + "\">";
    sb[sb.length] = this.getNodeHtml();
    sb[sb.length] = this.getChildrenHtml();
    sb[sb.length] = "</div>";
    return sb.join("");
},getChildrenHtml:function() {
    var sb = [];
    sb[sb.length] = "<div class=\"ygtvchildren\"";
    sb[sb.length] = " id=\"" + this.getChildrenElId() + "\"";
    if (!this.expanded) {
        sb[sb.length] = " style=\"display:none;\"";
    }
    sb[sb.length] = ">";
    if (this.hasChildren(true) && this.expanded) {
        sb[sb.length] = this.renderChildren();
    }
    sb[sb.length] = "</div>";
    return sb.join("");
},renderChildren:function() {
    var _44 = this;
    if (this.isDynamic() && !this.childrenRendered) {
        this.isLoading = true;
        this.tree.locked = true;
        if (this.dataLoader) {
            setTimeout(function() {
                _44.dataLoader(_44, function() {
                    _44.loadComplete();
                });
            }, 10);
        } else {
            if (this.tree.root.dataLoader) {
                setTimeout(function() {
                    _44.tree.root.dataLoader(_44, function() {
                        _44.loadComplete();
                    });
                }, 10);
            } else {
                return "Error: data loader not found or not specified.";
            }
        }
        return "";
    } else {
        return this.completeRender();
    }
},completeRender:function() {
    var sb = [];
    for (var i = 0; i < this.children.length; ++i) {
        sb[sb.length] = this.children[i].getHtml();
    }
    this.childrenRendered = true;
    return sb.join("");
},loadComplete:function() {
    this.getChildrenEl().innerHTML = this.completeRender();
    this.isLoading = false;
    this.expand();
    this.tree.locked = false;
},getAncestor:function(_45) {
    if (_45 >= this.depth || _45 < 0) {
        return null;
    }
    var p = this.parent;
    while (p.depth > _45) {
        p = p.parent;
    }
    return p;
},getDepthStyle:function(_47) {
    return (this.getAncestor(_47).nextSibling)?"ygtvdepthcell":"ygtvblankdepthcell";
},getNodeHtml:function() {
    return "";
}};
YAHOO.widget.RootNode = function(_48) {
    this.init(null, null, true);
    this.tree = _48;
};
YAHOO.widget.RootNode.prototype = new YAHOO.widget.Node();
YAHOO.widget.RootNode.prototype.getNodeHtml = function() {
    return "";
};
YAHOO.widget.TextNode = function(_49, _50, _51) {
    if (_50) {
        this.init(_49, _50, _51);
        this.setUpLabel(_49);
    }
};
YAHOO.widget.TextNode.prototype = new YAHOO.widget.Node();
YAHOO.widget.TextNode.prototype.labelStyle = "ygtvlabel";
YAHOO.widget.TextNode.prototype.labelElId = null;
YAHOO.widget.TextNode.prototype.label = null;
YAHOO.widget.TextNode.prototype.setUpLabel = function(_52) {
    if (typeof _52 == "string") {
        _52 = {label:_52};
    }
    this.label = _52.label;
    if (_52.href) {
        this.href = _52.href;
    }
    if (_52.target) {
        this.target = _52.target;
    }
    this.labelElId = "ygtvlabelel" + this.index;
};
YAHOO.widget.TextNode.prototype.getLabelEl = function() {
    return document.getElementById(this.labelElId);
};
YAHOO.widget.TextNode.prototype.getNodeHtml = function() {
    var sb = new Array();
    sb[sb.length] = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
    sb[sb.length] = "<tr>";
    for (i = 0; i < this.depth; ++i) {
        sb[sb.length] = "<td class=\"" + this.getDepthStyle(i) + "\">&nbsp;</td>";
    }
    var _53 = "YAHOO.widget.TreeView.getNode('" + this.tree.id + "'," + this.index + ")";
    sb[sb.length] = "<td";
    sb[sb.length] = " id=\"" + this.getToggleElId() + "\"";
    sb[sb.length] = " class=\"" + this.getStyle() + "\"";
    if (this.hasChildren(true)) {
        sb[sb.length] = " onmouseover=\"this.className=";
        sb[sb.length] = _53 + ".getHoverStyle()\"";
        sb[sb.length] = " onmouseout=\"this.className=";
        sb[sb.length] = _53 + ".getStyle()\"";
    }
    sb[sb.length] = " onclick=\"javascript:" + this.getToggleLink() + "\">&nbsp;";
    sb[sb.length] = "</td>";
    sb[sb.length] = "<td>";
    sb[sb.length] = "<a";
    sb[sb.length] = " id=\"" + this.labelElId + "\"";
    sb[sb.length] = " class=\"" + this.labelStyle + "\"";
    sb[sb.length] = " href=\"" + this.href + "\"";
    sb[sb.length] = " target=\"" + this.target + "\"";
    if (this.hasChildren(true)) {
        sb[sb.length] = " onmouseover=\"document.getElementById('";
        sb[sb.length] = this.getToggleElId() + "').className=";
        sb[sb.length] = _53 + ".getHoverStyle()\"";
        sb[sb.length] = " onmouseout=\"document.getElementById('";
        sb[sb.length] = this.getToggleElId() + "').className=";
        sb[sb.length] = _53 + ".getStyle()\"";
    }
    sb[sb.length] = " >";
    sb[sb.length] = this.label;
    sb[sb.length] = "</a>";
    sb[sb.length] = "</td>";
    sb[sb.length] = "</tr>";
    sb[sb.length] = "</table>";
    return sb.join("");
};
YAHOO.widget.MenuNode = function(_54, _55, _56) {
    if (_55) {
        this.init(_54, _55, _56);
        this.setUpLabel(_54);
    }
    this.multiExpand = false;
};
YAHOO.widget.MenuNode.prototype = new YAHOO.widget.TextNode();
YAHOO.widget.HTMLNode = function(_57, _58, _59, _60) {
    if (_58) {
        this.init(_57, _58, _59);
        this.initContent(_57, _60);
    }
};
YAHOO.widget.HTMLNode.prototype = new YAHOO.widget.Node();
YAHOO.widget.HTMLNode.prototype.contentStyle = "ygtvhtml";
YAHOO.widget.HTMLNode.prototype.contentElId = null;
YAHOO.widget.HTMLNode.prototype.content = null;
YAHOO.widget.HTMLNode.prototype.initContent = function(_61, _62) {
    if (typeof _61 == "string") {
        _61 = {html:_61};
    }
    this.html = _61.html;
    this.contentElId = "ygtvcontentel" + this.index;
    this.hasIcon = _62;
};
YAHOO.widget.HTMLNode.prototype.getContentEl = function() {
    return document.getElementById(this.contentElId);
};
YAHOO.widget.HTMLNode.prototype.getNodeHtml = function() {
    var sb = new Array();
    sb[sb.length] = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
    sb[sb.length] = "<tr>";
    for (i = 0; i < this.depth; ++i) {
        sb[sb.length] = "<td class=\"" + this.getDepthStyle(i) + "\">&nbsp;</td>";
    }
    if (this.hasIcon) {
        sb[sb.length] = "<td";
        sb[sb.length] = " id=\"" + this.getToggleElId() + "\"";
        sb[sb.length] = " class=\"" + this.getStyle() + "\"";
        sb[sb.length] = " onclick=\"javascript:" + this.getToggleLink() + "\">&nbsp;";
        if (this.hasChildren(true)) {
            sb[sb.length] = " onmouseover=\"this.className=";
            sb[sb.length] = "YAHOO.widget.TreeView.getNode('";
            sb[sb.length] = this.tree.id + "'," + this.index + ").getHoverStyle()\"";
            sb[sb.length] = " onmouseout=\"this.className=";
            sb[sb.length] = "YAHOO.widget.TreeView.getNode('";
            sb[sb.length] = this.tree.id + "'," + this.index + ").getStyle()\"";
        }
        sb[sb.length] = "</td>";
    }
    sb[sb.length] = "<td";
    sb[sb.length] = " id=\"" + this.contentElId + "\"";
    sb[sb.length] = " class=\"" + this.contentStyle + "\"";
    sb[sb.length] = " >";
    sb[sb.length] = this.html;
    sb[sb.length] = "</td>";
    sb[sb.length] = "</tr>";
    sb[sb.length] = "</table>";
    return sb.join("");
};
YAHOO.widget.TVAnim = new function() {
    this.FADE_IN = "YAHOO.widget.TVFadeIn";
    this.FADE_OUT = "YAHOO.widget.TVFadeOut";
    this.getAnim = function(_63, el, _64) {
        switch (_63) {case this.FADE_IN:return new YAHOO.widget.TVFadeIn(el, _64);case this.FADE_OUT:return new YAHOO.widget.TVFadeOut(el, _64);default:return null;}
    };
    this.isValid = function(_65) {
        return ("undefined" != eval("typeof " + _65));
    };
};
YAHOO.widget.TVFadeIn = function(el, _66) {
    this.el = el;
    this.callback = _66;
};
YAHOO.widget.TVFadeIn.prototype = {animate:function() {
    var _67 = this;
    var s = this.el.style;
    s.opacity = 0.1;
    s.filter = "alpha(opacity=10)";
    s.display = "";
    var dur = 0.4;
    var a = new YAHOO.util.Anim(this.el, {opacity:{from:0.1,to:1,unit:""}}, dur);
    a.onComplete.subscribe(function() {
        _67.onComplete();
    });
    a.animate();
},onComplete:function() {
    this.callback();
}};
YAHOO.widget.TVFadeOut = function(el, _69) {
    this.el = el;
    this.callback = _69;
};
YAHOO.widget.TVFadeOut.prototype = {animate:function() {
    var _70 = this;
    var dur = 0.4;
    var a = new YAHOO.util.Anim(this.el, {opacity:{from:1,to:0.1,unit:""}}, dur);
    a.onComplete.subscribe(function() {
        _70.onComplete();
    });
    a.animate();
},onComplete:function() {
    var s = this.el.style;
    s.display = "none";
    s.filter = "alpha(opacity=100)";
    this.callback();
}};