(function () {
    var Dom = YAHOO.util.Dom,
        Lang = YAHOO.lang,
        Event = YAHOO.util.Event;


YAHOO.widget.DirSubNode = function(oData, oParent, expanded) {
    YAHOO.widget.DirSubNode.superclass.constructor.call(this,oData,oParent,expanded);
};

YAHOO.extend(YAHOO.widget.DirSubNode, YAHOO.widget.TextNode, {

    multiExpand: false,

    /**
     * The node type
     * @property _type
     * @private
     * @type string
     * @default "TextNode"
     */
   	_type: "DirSubNode",
   	
   	
   	
   	iconStyle: "ygtvSubCatIcon",

   	guid: 'guid',
	dirCat: 'dirCat',
	
    getNodeHtml: function() { 
        var sb = [];

       sb[sb.length] = '<table id="ygtvtableel' + this.index + '"border="0" cellpadding="0" cellspacing="0" class="ygtvtable ygtvdepth'+this.depth;
       if (this.enableHighlight) {
            sb[sb.length] = ' ygtv-highlight' + this.highlightState;
        }
        
        if (this.className) {
            sb[sb.length] = ' ' + this.className;
        }           
        
        sb[sb.length] = '"><tr class="ygtvrow" style=" padding-left: 0px">';

        sb[sb.length] = '<td id="' + this.contentElId; 
        sb[sb.length] = '" class="ygtvcell ';
        sb[sb.length] = this.contentStyle  + ' ygtvcontent " ';
        sb[sb.length] = (this.nowrap) ? ' nowrap="nowrap" ' : '';
        sb[sb.length] = ' >';
        sb[sb.length] = this.getContentHtml();
        sb[sb.length] = '</td></tr></table>';

        return sb.join("");

    },
    
    
    
    // overrides YAHOO.widget.Node
    getContentHtml: function() { 
        var sb = [];
        sb[sb.length] = this.href?'<a':'<span';
        sb[sb.length] = ' id="' + this.labelElId + '"';
        sb[sb.length] = ' class="'+this.labelStyle+' ' + this.getLabelStyle()  + '"';
        if (this.href) {
            sb[sb.length] = ' href="' + this.href + '"';
            sb[sb.length] = ' target="' + this.target + '"';
        } 
        if (this.title) {
            sb[sb.length] = ' title="' + this.title + '"';
        }
        sb[sb.length] = ' >';
        sb[sb.length] = this.label;
        sb[sb.length] = this.href?'</a>':'</span>';
        return sb.join("");
    },


     updateIcon: function() {

        if (this.hasIcon) {
        	
            var el = this.getToggleEl();
            if (el) {
                var pattern =  new RegExp('\\b'+this.iconStyle+'_(([ecn]h?)|(loading))\\b', 'gi');
            	el.className = el.className.replace(pattern,this.getLabelStyle());
            	//el.className = el.className.replace(/\bygtvSubCatIcon_(([ecn]h?)|(loading))\b/gi,this.getLabelStyle());
            }
        }
    },
    
    getToggleEl: function(){
    	return this.getLabelEl();
    },


    /**
     * Returns the css style name for the toggle
     * @method getStyle
     * @return {string} the css class for this node's toggle
     */
    getLabelStyle: function() {
        if (this.isLoading) {
            return this.iconStyle+"_loading";
        } else {

            // type p=plus(expand), m=minus(collapase), n=none(no children)
            
            //if (this.hasChildren(true) || (this.isDynamic() && !this.getIconMode())) {
             
             var   type =  "n";
            
             if(this.hasChildren(true) )
             {
             	type = this.expanded?"e":"c";
             }

            return this.iconStyle+'_'+ type;
        }
    }

});
})();


YAHOO.widget.DirCategoryNode = function(oData, oParent, expanded) {
	YAHOO.widget.DirCategoryNode.superclass.constructor.call(this,oData,oParent,expanded);
};

YAHOO.extend(YAHOO.widget.DirCategoryNode, YAHOO.widget.DirSubNode, {
    
	/**
     * The node type
     * @property _type
     * @private
     * @type string
     * @default "TextNode"
     */
	_type: "DirCategoryNode",
    /**
     * The CSS class for the label href.  Defaults to ygtvlabel, but can be
     * overridden to provide a custom presentation for a specific node.
     * @property labelStyle
     * @type string
     */
    labelStyle: "ygtvDirCatlabel",
    
    iconStyle: "ygtvDirCatIcon",

	/**
     * Called when first rendering the tree.  We always build the div that will
     * contain this nodes children, but we don't render the children themselves
     * unless this node is expanded.
     * @method getChildrenHtml
     * @return {string} the children container div html and any expanded children
     * @private
     */
    getChildrenHtml: function() {


        var sb = [];
        sb[sb.length] = '<div class="ygtvchildren ygtvDirCatChildren" id="' + this.getChildrenElId() + '"';

        // This is a workaround for an IE rendering issue, the child div has layout
        // in IE, creating extra space if a leaf node is created with the expanded
        // property set to true.
        if (!this.expanded || !this.hasChildren()) {
            sb[sb.length] = ' style="display:none;"';
        }
        sb[sb.length] = '>';


        // Don't render the actual child node HTML unless this node is expanded.
        if ( (this.hasChildren(true) && this.expanded) ||
                (this.renderHidden && !this.isDynamic()) ) {
            sb[sb.length] = this.renderChildren();
        }

        sb[sb.length] = '</div>';

        return sb.join("");
    }
    
});
