$(document).ready(function(){
   
  $("#toggleCategoryTree").click(function(){
    $("#categoryTree").slideToggle();
  });
  
  $("#closeCategoryTree").click(function(){
    $("#categoryTree").slideUp();
  });
  
  
  $("#categoryTree li").mouseover(function(event){
    showSubTree($(this));
  });
  
  $("#categoryTree li").mouseout(function(event) {
    hideSubTree($(this));
  });


});

function getCategoryId(string) {
  var category = string.match(/category\/\d+/g);
  return category[0].match(/\d+/g);
}


function showSubTree(obj) {
  var a = obj.children("a");
  var catId = getCategoryId(a.attr("href"));
  var color = categoryColor[catId];
  if (color != "") a.css({backgroundColor: "#" + color});
  else a.css({backgroundColor: "#EF3824"});
  //a.css({color: "white"});
  obj.children("ul:first").show();
}

function hideSubTree(obj) {
  var a = obj.children("a");
  a.css({backgroundColor: "transparent"});
  obj.children("ul:first").hide();
}
