jQuery(document).ready(function(){
        jQuery("#schoolsmap .field input").attr("disabled", "disabled");
        jQuery("#schoolsmap .field input").addClass("no-edit");
});

(function() {
        jQuery.fn.schoolmap_modify = function () {
                var post_box = this.parents(".postbox");

                post_box.find(".field input").removeAttr("disabled");
                post_box.find(".field input").removeClass("no-edit");
                post_box.find(".field").each(function() {
                    var save = jQuery(this).find("input").val();
                    jQuery(this).find(".school-save").text(save);
                });

                post_box.find(".manage-button .delete-button").fadeOut(250);
                this.fadeOut(250, function() {
                    post_box.find(".manage-button .submit-button").fadeIn(250);
                    post_box.find(".manage-button .cancel-button").fadeIn(250);
                });
        }
})(jQuery);

(function() {
        jQuery.fn.schoolmap_cancelmodify = function () {
                var post_box = this.parents(".postbox");

                post_box.find(".field input").attr("disabled", "disabled");
                post_box.find(".field input").addClass("no-edit");
                post_box.find(".field").each(function() {
                        var save = jQuery(this).find(".school-save").text();
                        jQuery(this).find("input").val(save);
                });

                post_box.find(".manage-button .submit-button").fadeOut(250);
                this.fadeOut(250, function() {
                    post_box.find(".manage-button .delete-button").fadeIn(250);
                    post_box.find(".manage-button .modify-button").fadeIn(250);
                });
        }
})(jQuery);

(function() {
        jQuery.fn.schoolmap_delete = function () {
                var post_box = this.parents(".postbox");

                post_box.find(".manage-button .modify-button").fadeOut(250);
                this.fadeOut(250, function() {
                    post_box.find(".manage-button .confirmdelete-button").fadeIn(250);
                    post_box.find(".manage-button .canceldelete-button").fadeIn(250);
                });
        }
})(jQuery);

(function() {
        jQuery.fn.schoolmap_canceldelete = function () {
                var post_box = this.parents(".postbox");

                this.parents(".manage-button").find(".school-delete").val(0);

                post_box.find(".manage-button .confirmdelete-button").fadeOut(250);
                this.fadeOut(250, function() {
                    post_box.find(".manage-button .modify-button").fadeIn(250);
                    post_box.find(".manage-button .delete-button").fadeIn(250);
                });
        }
})(jQuery);

(function() {
        jQuery.fn.schoolmap_confirmdelete = function () {
                var post_box = this.parents(".postbox");

                this.parents(".manage-button").find(".school-delete").val(1);
                
                post_box.slideUp(500, function() {
                        jQuery(this).find(".school-form").submit();
                });
        }
})(jQuery);

(function() {
        jQuery.fn.schoolmap_newschool = function () {
                var new_school = jQuery("#schoolsmap #new-school").clone();

                new_school.hide();
                new_school.attr("id", "");
                new_school.insertBefore("#schoolsmap .postbox:first");
                new_school.fadeIn(250, function() {
                    jQuery(this).find(".inside").slideDown(250);
                    jQuery(this).find(".modify-button").trigger("click");
                });
            }
})(jQuery);
