var catList = [];

function Icon(icon){
		this.edge = 50
		this.id = icon.id;
		this.active = 0;
		this.show = function(){
			this.flashing();
			this.select();
		}
		this.create = function(){
//			this.ico = document.getElementById("ico").appendChild(document.createElement("img"));
			this.ico = document.createElement("img");
   			this.ico.src = icon.off;
			this.ico.id = icon.id;
			this.setParam("width", this.edge);
			this.setParam("height", this.edge);
			this.ico.title = icon.name;
            document.getElementById("ico").appendChild(this.ico)

			this.item = document.createElement("div")
			var b = document.createElement("p")
			this.item.id = "item"+icon.id;
			this.item.className = "cat";
			/*var img = document.createElement("img");
			img.src = "/images/catlistplus.gif";
			img.width = 7;
			img.height = 7;*/
			var img = document.createElement("p");
			img.className = "catPlus";
            b.appendChild(img)
			b.appendChild(document.createTextNode(icon.name));
			var strong = document.createElement("strong");
			if(icon.count!=0)
			strong.innerHTML = icon.count;
			b.appendChild(strong);
			this.item.appendChild(b);

			document.getElementById("catlist").appendChild(this.item);

   			b.onclick = cats[icon.id].click
			b.onmouseover = cats[icon.id].onmouseover
			b.onmouseout = cats[icon.id].onmouseout

	  		this.ico.onmouseover = cats[icon.id].onmouseover
  	  		this.ico.onmouseout = cats[icon.id].onmouseout
			this.ico.onclick = cats[icon.id].click

		}
		this.onmouseover = function(){
			document.getElementById(icon.id).src = icon.on;
			document.getElementById("item"+icon.id).style.color = "#ffa500";
			return icon.on;
		}
		this.onmouseout = function(){
			if(cats[icon.id].active!=1){
				document.getElementById(icon.id).src = icon.off;
				document.getElementById("item"+icon.id).style.color = "#C9C9C9";
				return icon.off;
			}
			return icon.on;
		}
		this.click = function(all){
			if (cats[icon.id].active == 1){
				cats[icon.id].turnOff();
			}else{
				cats[icon.id].turnOn();
			}
//			map.getObjects();
			if(!search_in)
				resetSeeker();
			else	
				map.getObjects();
		}
		this.turnOn = function(){
		  var item = document.getElementById("item"+icon.id)
			cats[icon.id].active = 1;
			document.getElementById(icon.id).src = icon.on;
			item.style.color = "#ffa500";
			catList.push(icon.id);
			if(item.getElementsByTagName("div").length>0)
				item.getElementsByTagName("div")[0].style.display="block";
			else{
				url = "/categories/id/" + icon.id;
				func = function(responseText, responseJS){
					var subd = document.createElement("div");
					subd.className = "sublist";
					subd.style.color = "#C9C9C9"
					subd.innerHTML = responseText;
					item.appendChild(subd)

					try{
						var su = subd.getElementsByTagName("div");
						for(var i=0; i<a.length; i++){
							su[i].onmouseover = function(){this.className = "item hov"}
							su[i].onmouseout = function(){this.className = "item"}
						}
					}
					catch(e){}

				}
				loadHTML(url, func);

			}
		}
		this.turnOff = function(){
		  	var item = document.getElementById("item"+icon.id)
			this.active = 0;
			document.getElementById(icon.id).src = icon.off;
			item.style.color = "#C9C9C9";
	 		//catList.splice(catList.indexOf(icon.id),1);
	 		for(var i=0; i<catList.length; i++){
	 			if(catList[i]==icon.id){	
					catList.splice(i,1);
				}
	 		}	
	 	
	 		if(item.getElementsByTagName("div").length>0)
					item.getElementsByTagName("div")[0].style.display="none";
		}
		
        
		this.setParam = function(attr, value){
			if (attr == "width") {
				this.width = value;
				this.ico.width = value;
			}
			if (attr == "height") {
				this.height = value;
				this.ico.height = value;
			}
		}
		
		this.getSrc = function(){
			return document.getElementById(icon.id).src;
		}
}

function showCatList(){
	catList=[];
	for (key in icons) {
		cats[key].turnOn();
	}
	//map.getObjects();
	resetSeeker();
}
function hideCatList(reset){
	for (key in icons) {
		cats[key].turnOff();
	}
	catList=[];
	if(reset==null)
		resetSeeker();
	else{
		map.getObjects();
	}
}