if (AJS.Labels) {
	AJS.toInit(function ($) {
		$(".show-labels-editor").unbind("click");
	    $(".show-labels-editor").click(function () {
	        SuggestedLabelsForEntity.viewLabels(AJS.params.pageId, AJS.Labels.suggestedLabelsCallback);
	        // reset the value of this field, just in case the browser wants to become helpful and insert the old value
	        $("#labelsString").val("");
	        $("#labels-section").addClass("open");
	
	        // update the links
	        AJS.setVisible(".show-labels-editor", false);
	        AJS.setVisible("a.hide-labels-editor", true);
	        AJS.setVisible("#labels-section-title", true);
	        $("#labels-section-title").show();
	        $("#labelsString").get(0).focus();
	        return false;
	    });
	    $(".hide-labels-editor").unbind("click");
	    $(".hide-labels-editor").click(function () {
	        // clear out any error messages
	        AJS.Labels.labelOperationError("");
	        $("#errorSpan").html("");
	
	        $("#labels-section").removeClass("open");
	
	        // update the links
	        AJS.setVisible("a.hide-labels-editor", false);
	        AJS.setVisible(".show-labels-editor", true);
	        if ($("#labelsList").children().length == 0 && $("#labelsString").val() == "") { // no labels
	            $(".show-labels-editor").addClass("add").text(AJS.params.addLabel);
	            AJS.setVisible("#labels-section-title", false);
	            $("#labels-section-title").css("display", "none");
	        }
	        else {
	            $(".show-labels-editor").removeClass("add").text(AJS.params.editLabel);
	            AJS.setVisible("#labels-section-title", true);
	            $("#labels-section-title").show();
	        }
	
	        // add label if any user input
	        if($("#labelsString").val() != "")
	            AJS.Labels.addLabel();
	        
	        return false;
	    });
	});
}

