
$(document).ready(function() {

  $("div#edit-label-dialog").html($("div#label-edit-loading").html());

  $("a.label-dialog-close").live('click', function() {
    $("div#edit-label-dialog").html($("div#label-edit-loading").html());
    $("div#edit-label-dialog").dialog("close");
    return false;
  });

  $("a#save-label").live('click', function() {
    $("img.spinner").show();
    var labelFormData = $("form#edit-label-form").serialize();
    $.ajax({
      type: 'PUT',
      url: $("form#edit-label-form").attr('action') + '.js',
      dataType: 'html',
      data: $("form#edit-label-form").serialize(),
      processData : false,
      success: function(data) { 
        if( data == "status-done" ) {
          if (window.location.pathname == "/labels/new") {
            window.location.reload();
          } else {
            window.location.pathname = "/labels/new";
          }
        } else {
        $("div#edit-label-dialog").html(data); }}
    });
    
    return false;
  });

  $("a#edit-dialog-label").click(function() { 
    $(".ui-dialog-titlebar").hide();
    $("div#edit-label-dialog").dialog('open');
    $.get("/labels/3/edit.js", function(data) { 
      $("div#edit-label-dialog").html(data); }, "html");
    return false;
  });
});
