(function () {
	
    var Y = YAHOO, Dom = Y.util.Dom, Widget = Y.widget;

	Widget.DialogTreeNode = function(id, oConfig) {
		Widget.DialogTreeNode.superclass.constructor.call(this, id, oConfig);
	};
	
	Y.lang.extend(Widget.DialogTreeNode, Widget.TextNode, {
		
		_type : "DialogNode",
		
		dialogURL : null,
		
		recordId : null,
		
		DIALOG_LABEL_CSS : 'dialog-node-label',
		
		init : function(oData, oParent, expanded) {
			Widget.DialogTreeNode.superclass.init.call(this, oData, oParent, expanded);
			this.dialogURL = oData.dialogURL || null;
			this.recordId = oData.recordId;
		},
		
		collapse : function(e) {
			Widget.DialogTreeNode.superclass.collapse.call(this, e);
			this.selected();
		},
	
		selected : function() {
			if(this.dialogURL !== null) {
				Y.util.Connect.asyncRequest('GET', this.dialogURL+'/item.id/'+this.recordId, {
					success: function(r) {
						this.tree.dialog.setBody(r.responseText);
						nmdgf.dom.evaluateScripts(r.responseText);
						this.tree.dialog.show();
						this.tree.dialog.focusFirst();
					}, scope: this
				});
				this.positionDialog();
				Dom.addClass(this.labelElId, this.DIALOG_LABEL_CSS);
			}else {
				this.tree.dialog.hide();
			}
		},
	
		deselected : function() {
			Dom.removeClass(this.labelElId, this.DIALOG_LABEL_CSS);
		},
		
		positionDialog : function() {
			var region = Dom.getRegion(this.labelElId);
			this.tree.dialog.moveTo(region.right-4, region.top);
		}
	
		
	});
	
})();
