var catagories_list = new Array();
var catagories_hover_list = new Array();


function show_tip(data) {
document.getElementById("info").innerHTML=data;
}


function hide_tip() {
document.getElementById("info").innerHTML="";
}


function highlight_category(category){
	categories = document.getElementsByClassName("category");
	for (var i = 0; i < categories.length; i++){
		if (categories[i].title == category){
			categories[i].style.color = "#606060";
		}
		else{
			categories[i].style.color = "#b0b0b0";
		}
	}
}

function highlight_items(category){

//alert(catagories_list[2]+" "+catagories_hover_list[2]);

highlight_color = "#808080";
highlight_hover_color = "#404040";
fade_color = "#d0d0d0";
fade_hover_color = "#d0d0d0";

if (category == "all" || category == ""){
	for (i = 0; i < document.styleSheets.length; i++){
		for (j = 0; j < document.styleSheets[i].cssRules.length; j++){
			if (catagories_list.indexOf(document.styleSheets[i].cssRules[j].selectorText) >= 0){
				document.styleSheets[i].cssRules[j].style["color"] = highlight_color;
			}
			if (catagories_hover_list.indexOf(document.styleSheets[i].cssRules[j].selectorText) >= 0){
				document.styleSheets[i].cssRules[j].style["color"] = highlight_hover_color;
			}
		}
	}
}
else{
	for (i = 0; i < document.styleSheets.length; i++){
		for (j = 0; j < document.styleSheets[i].cssRules.length; j++){
			if (catagories_list.indexOf(document.styleSheets[i].cssRules[j].selectorText) >= 0){
				if (document.styleSheets[i].cssRules[j].selectorText == "."+category){
					document.styleSheets[i].cssRules[j].style["color"] = highlight_color;
				}
				else{
					document.styleSheets[i].cssRules[j].style["color"] = fade_color;
				}
			}
			if (catagories_hover_list.indexOf(document.styleSheets[i].cssRules[j].selectorText) >= 0){
				if (document.styleSheets[i].cssRules[j].selectorText == "."+category+":hover"){
					document.styleSheets[i].cssRules[j].style["color"] = highlight_hover_color;
				}
				else{
					document.styleSheets[i].cssRules[j].style["color"] = fade_hover_color;
				}
			}
		}
	}
}
}


//onload start-up
window.onload = function() {
	
	//initializes tooltip show/hide
	items = document.getElementsByClassName("item");
	for (var i = 0; i < items.length; i++){
		items[i].addEventListener("mouseover", function(){show_tip(this.title);}, false);
		items[i].addEventListener("mouseout", function(){hide_tip();}, false);
	}

	//initializes category higlighting
	categories = document.getElementsByClassName("category");
	for (var i = 0; i < categories.length; i++){
		categories[i].addEventListener("click", function(){highlight_category(this.title);highlight_items(this.title);return false;}, false);
	}
	
	categories = document.getElementsByClassName("category");
	for (i = 0; i < categories.length; i++){
		catagories_list.push("."+categories[i].title);
		catagories_hover_list.push("."+categories[i].title+":hover");
	}

	wlocation = window.location.toString();
	pos = wlocation.indexOf("#");
	if (pos >= 0){
		param = wlocation.substr(pos + 1, wlocation.length - pos - 1);
		if (catagories_list.indexOf("."+param) >= 0){
			highlight_category(param);
			highlight_items(param);
		}
	}
	else{
		highlight_category("all");
	}
	
	//sets timer to periodically check for location.hash change
	var hash = location.hash;
	setInterval(function() {
			if (hash != location.hash) {
				hash = location.hash;
				highlight_category(hash.substr(1));
				highlight_items(hash.substr(1));
			}
		}, 100);

}
