// JavaScript Document
$(document).ready(function() {
						
	editheading();
	
    function theFilename() {
        var file_name = document.location.href;
        var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
        return file_name.substring(file_name.lastIndexOf("/")+1, end);
    }
	
	var thePage = theFilename();

	function editheading () {
	
		// This is what to do when the newly created form has been submitted
		$(".edit-heading").bind("click", function() {
		
			$clicked = $(this);
			
			$($clicked).animate({opacity: 0.01}, 300, function () {
				$.post("http://www.rawfirepits.co.uk/admin/edit-headings.php", { theOldHeading: $clicked.html() },
					function(returned_data){
						$($clicked).html(returned_data);
						$($clicked).animate({opacity: 1}, 300);
						$($clicked).unbind("click");
						
						$('#updatebutton').bind("click", function() {
								
								var theHeading = $("#theHeading").val();
								
								$($clicked).animate({opacity: 0.01}, 300, function () {
									$.post("http://www.rawfirepits.co.uk/admin/edit-headings.php", { theHeading: theHeading, thePage: thePage  }, function(returned_data) {
										$($clicked).html(returned_data);
										$($clicked).animate({opacity: 1}, 1000, function () {
											$(".saved").fadeOut(3000, function() {
												$(".saved").remove();
												editheading();
											});
										});
									});
								});


						});
		
					}
					, "html");
				});
		});
		
	};

});
