/**
 * @author Nivaria Innova Team
 */
function CategoriesList() {
	this.id = null;
	this.simplefields = [];		//Simple fields
	this.eventsListeners = [];  //Events listeners
}

CategoriesList.prototype = {
	initialize: function(objectId,json,jsonData) {
		this.id = objectId;
		//Getting component simple fields values
		ncm.initSimpleFields(CategoriesList,this,json);
		//Init events listeners
		ncm.initEventsListeners(CategoriesList,this);
		//Init component
		this.initComponent(jsonData);
	},
	
	initComponent: function(jsonData) {
		var Me = this;
		var m_process = function(html){
			$jq(ncm.concat("div#categorieslist",Me.id)).html(html).find("ul.tv").treeview({
				animated: Me.simplefields["ANIMATED"]?Me.simplefields["ANIMATED"]:0,
				collapsed: Me.simplefields["COLLAPSED"],
				unique: Me.simplefields["UNIQUE"]
			}).end().find("a.category-selected").parents("li").each(function(){
					$jq(this).find(".hitarea").eq(0).click();	
			});
		};
		
		if(jsonData) {
			m_process(jsonData)
		} else {
			//New Ajax Request
			var jspfile = CategoriesList.getProperty("jsp_default");
			if(jspfile==null) jspfile="components/queries/categories/categorieslist.jsp";
			var data = ncm.getComponentConstructorParamsObject(this,CategoriesList,true);
			$jq.extend(data,ncm.getParametersFromUrlAsObject());
			$jq.get(jspfile,data,function(html){
				m_process(html);
			},"html");	
		}
	},
	
	filterCategory: function(categoryId,domElem) {
		ncm.triggerCustomEvent(ncm.customEvents["ncmValueChange"],this,categoryId);
		$jq(ncm.concat("div#categorieslist",this.id," a.category-selected")).removeClass("category-selected");
		if(domElem!=null) $jq(domElem).addClass("category-selected");
	}
};

CategoriesList.instances = new Array();
CategoriesList.properties = new Array();
CategoriesList.datatype = null;
CategoriesList.jsp_utils = null;
CategoriesList.language = null;
CategoriesList.pageUrl = null;
CategoriesList.channel = null;
CategoriesList.inPreview = false;
CategoriesList.issueId = null;
CategoriesList.skin = null;
CategoriesList.pageId = null;

CategoriesList.register = function(objectId,json,jsonData) {
	var aObject = new CategoriesList();
	aObject.initialize(objectId,json,jsonData);
	CategoriesList.instances[""+objectId] = aObject;
}

CategoriesList.getRegistered = function(objectId) {
	return CategoriesList.instances[""+objectId];
}

CategoriesList.get = function(objectId) {
	return CategoriesList.getRegistered(objectId);
}

CategoriesList.initProperties = function(options) {
	ncm.initProperties(CategoriesList,options);
}

CategoriesList.getProperty = function(propName) {
	var res = CategoriesList.properties[propName];
	if(res==null) res="";
	if(typeof(res)=="undefined") res="";
	return res;
}
