/* snabel.org JavaScript
   Copyright (C) 2009 Morten Brekkevold
   License: BSD
*/

function checkAll(id, name, flag)
{
  if (flag == 0) {
    $("form#" + id + " INPUT[@name=" + name + "][type='checkbox']").attr('checked', false);
  } else {
    $("form#" + id + " INPUT[@name=" + name + "][type='checkbox']").attr('checked', true);
  }
}

$(document).ready(function() {
  $(".commentadmin").hide();
  $(".commentadmintoggle").each(function(i) {
    $(this).click(function() {
      var data = $(this).attr("id").split("-");
      var target = "#commentadmin-" + data[1]
      $(target).toggle("slow");
      return false;
    });
  });

  $("ul.expandable").each(function(i) {
    // close all elemens
    $(this).find("> li ul").hide();
    $(this).find("> li").each(function(i) {
        $(this).prepend("<a href=\"#\" class=\"expander\">▼&nbsp;</a>");
    });

    // open the first element
    $(this).find("> li:first-child ul").show();
    $(this).find("> li:first-child .expander").each(function(i) {
       $(this).empty();
       $(this).append("►&nbsp;");
       $(this).addClass("opened");
    });

    $(this).find(".expander").each(function(i) {
      $(this).click(function() {
	$(this).parent().find("ul").toggle("slow");

        $(this).toggleClass("opened");
	if ($(this).hasClass("opened")) {
	    $(this).empty();
	    $(this).append("►&nbsp;");
	} else {
	    $(this).empty();
	    $(this).append("▼&nbsp;");
	}
        return false;
      });
    });

  });
});

