/*
	Copyright (c) 2004-2006, The Dojo Foundation
	All Rights Reserved.

	Licensed under the Academic Free License version 2.1 or above OR the
	modified BSD license. For more information on Dojo licensing, see:

		http://dojotoolkit.org/community/licensing.shtml
*/


dojo.provide("dojo.widget.iManTreeDocIconExtension");

dojo.require("dojo.widget.TreeDocIconExtension");

// selector extension to emphasize node

dojo.widget.defineWidget(
	"dojo.widget.iManTreeDocIconExtension",
	[dojo.widget.TreeDocIconExtension],
{
	
//	getnodeDocType: function(node) {
//		var nodeDocType = node.getnodeDocType();
//		if (!nodeDocType) { // set default type
//			nodeDocType = node.isFolder ? "Folder" : "Document";
//		}
//		return nodeDocType;
//	},
	
//	setnodeDocTypeClass: function(node) {
		//dojo.widget.TreeDocIconExtension.setnodeDocTypeClass(node);
//		if(node.iconUrl)
//		{		
//			node.iconNode.style.backgroundImage = "url(/nps/portal/modules/dev/images/dir/"+node.iconUrl+")";
//		}
//	}
//	,		
// 	onAfterSetFolder: function(message) {
		//dojo.debug("FOLDER");
//		if (message.source.iconNode) {
			// on node-initialize time when folder is set there is no iconNode
			// this case will be processed in treeChange anyway
//			this.setnodeDocTypeClass(message.source);
//		}
//	},
	
//	onAfterUnsetFolder: function(message) {
//		this.setnodeDocTypeClass(message.source);
//	},
		
	
	listenNode: function(node) {
		/**
		 * add node with document type icon to node template and Tree.iconNodeTemplate
		 * it will be set to TreeNode.iconNode on node creation
		 * we do not assign document type yet, its node specific
		 */
		dojo.widget.iManTreeDocIconExtension.superclass.listenNode.apply(this,[node]);
			
//		node.contentIconNode = document.createElement("div");
//		var clazz = node.tree.classPrefix+"IconContent";
//		if (dojo.render.html.ie) {
//			clazz = clazz+' '+ node.tree.classPrefix+"IEIconContent";
//		}
//		dojo.html.setClass(node.contentIconNode, clazz);
//		
//		node.contentNode.parentNode.replaceChild(node.contentIconNode, node.expandNode);
//									  
//	  	node.iconNode = document.createElement("div");
//		dojo.html.setClass(node.iconNode, node.tree.classPrefix+"Icon"+' '+node.tree.classPrefix+'Icon'+this.getnodeDocType(node));
//		
//		node.contentIconNode.appendChild(node.expandNode);
//		node.contentIconNode.appendChild(node.iconNode);
//		
//		dojo.dom.removeNode(node.contentNode);
		if(node.iconUrl)
		{
			node.iconNode.style.backgroundImage = "url(/nps/portal/modules/dev/images/1px_spacer.gif)";
			node.iconNode.style.whiteSpace="nowrap";
			node.iconNode.style.width="28px";
			var specialImageUrl = "/nps/portal/modules/dev/images/1px_spacer.gif";
			if(node.dispAttrs){
				if(node.dispAttrs.charAt(2)=='P'){
					specialImageUrl = "/nps/portal/modules/dev/images/dir/Partition.gif";
				}else if(node.dispAttrs.charAt(3)=="A"){
					specialImageUrl = "/nps/portal/modules/fw/images/alias_container.gif";
				}
			}
			// @todo try to add the partition and alias icons to the iconNode.innerhtml here.
			node.iconNode.innerHTML="<img title='"+node.objectTypeDisplayName+"' src='/nps/portal/modules/dev/images/dir/"+node.iconUrl+"' onclick='nodeIconClicked(\""+node.widgetId+"\")'/><img width='10px' src='"+specialImageUrl+"' />"; 
			
		}
//		node.contentIconNode.appendChild(node.contentNode);
		
		
		//dojo.html.insertAfter(node.iconNode, node.expandNode);
		
		//dojo.debug("listenNode out "+node);
		
	}
//	,
			
	
//	onAfterChangeTree: function(message) {
//		var _this = this;
		
		//dojo.debug(message.node)
		
//		if (!message.oldTree || !this.listenedTrees[message.oldTree.widgetId]) {			
//			// moving from old tree to our tree
//			this.processDescendants(message.node,
//				this.listenNodeFilter,
//				this.listenNode
//			);
//		}
//		
//	}
	
});
