$(document).ready(function() {

  $(".menuItem").hover(function() {
    $(".menuItem").removeClass("hover");
    $(this).addClass("hover");
  }, function() {
  });
  
  $("#inventory td").click(function() {
    var id = $(this).attr("id");
    if($("#inventory td[id="+id+"] .itemInfo:visible").length > 0) {
      $("#inventory td[id="+id+"] .itemInfo").hide("slow");
    } else {
      $("#inventory td[id="+id+"] .itemInfo").load("mini/item.php?id="+id, function() {
        $("#inventory td[id="+id+"] .itemInfo").show("slow");
        $(".confirm").click(function() {
          return confirm("Are you sure you want to do this?");
        });
      });
    }
  });
  
  $(".toggleall").click(function() {
    var checked_status = this.checked;
    $("input.not").each(function() {
      $(this).attr("checked", checked_status);
    });
  });
  
  $(".tabs").tabs();

  $(".gryffTable").attr("cellpadding", "10").attr("cellspacing", "1");

  $(".confirm").click(function() {
    return confirm("Are you sure you want to do this?");
  });

  $("#fetchSimilarGryffs").click(function() {
    $("#similar").load("mini/suggestions_level.php?id="+$("#gryffID").val()+"&level="+$("#getLevel").val());
  });
  
  
  $('.colorpick').each(function() {
    var hexVal = $(this).val();
    while(hexVal.length < 6) hexVal = "0" + hexVal;
    $(this).parent("td").css("background-color", "#"+hexVal);
  });
  $('.colorpick').ColorPicker({
    onSubmit: function(hsb, hex, rgb, el) {
    	$(el).val(hex);
    	$(el).parent("td").css("background-color", "#"+hex);
    	$(el).ColorPickerHide();
  },
    onBeforeShow: function () {
    	$(this).ColorPickerSetColor(this.value);
    }
  })
  .bind('keyup', function(){
    $(this).ColorPickerSetColor(this.value);
  });

});
