if (THC == undefined) 
{
		var THC = {}; 
} 
THC.CategoryController = function (categoryTree) 
{ 	
	var categoryStore;
	var that = this;
	
	this.createCategoryTree= function(categoryDiv)
	{
	
	  that.categoryStore = new dojo.data.ItemFileReadStore({url:'getCategories.html'});
		
		var	categoryModel = new dijit.tree.ForestStoreModel({
				store: that.categoryStore,
				query: {type:'rootCategory'},
				rootId: "category",
				rootLabel: "Category",
				childrenAttrs: ["children"]
			});
		if(!categoryTree)
		{
			categoryTree = new dijit.Tree({
				id: "categoryTree",
				model: categoryModel,
				showRoot: false,
				openOnClick: true,
				persist : true,
				onClick : this.categoryClick
			});
		}
			var categoryDiv = document.getElementById("categoryDiv");
			categoryDiv.appendChild(categoryTree.domNode);
			categoryTree.startup();
	
	};
	this.categoryClick = function(item, node)
	{
		document.location.href="getProducts.html?catId="+item.id;
	};
	this.getIconClass = function(item, opened)
	{
		return (item == this.model.root || that.categoryStore.getValue(item, "type") == "rootCategory") ?
                   (opened ? "customFolderOpenedIcon" : "customFolderClosedIcon") :
                    "noteIcon";
	};
	this.expandCategory = function (cat1,cat2,cat3)
	{
		if(!cat1)
		{
			cat1 = cat2;
			cat2 = cat3;
			cat3 = "";
		}
		
		var cat1Found = false;
		for (c1 in self.categoryTree)
		{
			if(cat1 == self.categoryTree.children[c1].item)
			{
				cat1Found = true;
				break;
			}
		}
		if(cat1Found)
		{
			that.nodeClicked(cat1);
			if(cat2)
			{
				var cat2Found = false;
				for (c2 in cat1.children)
				{
					if(cat2 == cat1.children[c2].objectId)
					{
						cat2Found = true;
						break;
					}
				}
				if(cat2Found)
				{
					that.nodeClicked(cat2);
					if(cat3)
					var cat3Found = false;
					for (c3 in cat2.children)
					{
						if(cat3 == cat2.children[c3].objectId)
						{
							cat3Found = true;
							break;
						}
					}
					if(cat3Found)
					{
						that.nodeClicked(cat3);
					}
				}
			}
		}
	}
		
	this.breadCrumbClicked = function ( nodeId )
	{
		var node = dojo.widget.getWidgetById(nodeId);
		var controller = dojo.widget.getWidgetById("categoryTreeLoadingController");
		if(node)
		{
			controller.expand(node);		
			//dojo.html.scrollIntoView(node);
		}
	};	
	
};

