var image_directory = "/user_data/packages/default/img/";
var image_arrow = "arrow_square_gray_right.gif";
var image_plus = "bullet_square_red_plus.gif";
var image_minus = "bullet_square_red_minus.gif";

$(function(){
  $(".categoryTree li:has('ul') > img").attr('src', image_directory + image_plus).wrap('<a href="#" rel="switch"></a>');
  $(".categoryTree li ul").hide();
  $(".categoryTree li:has('ul li.init') > a[rel=switch] > img").attr('src', image_directory + image_minus);
  $(".categoryTree li:has('ul li.init') > ul").show();
  $(".categoryTree li.init:has('ul') > a[rel=switch] > img").attr('src', image_directory + image_minus);
  $(".categoryTree li.init > ul").show();

  $(".categoryTree li a[rel=switch]").click(function(){
    $parent = $(this).parent();
    if($parent.children("ul").css("display") == "none") {
      $parent.children("ul").show();
      $parent.children("a[rel=switch]").children("img").attr('src', image_directory + image_minus);
    } else {
      $parent.children("ul").hide();
      $parent.children("a[rel=switch]").children("img").attr('src', image_directory + image_plus);
    }
  });
});
