// Initialise global Hc context
var Hc = Hc || {};

Hc.AjaxEdit = {
	disableRte : null,

	addLoginFields : function(elt) {
		var string="<br/>";		
		string+='<span class="showOnEdit">';
		string+='<span>Login below. Not a member yet? <a href="#">Register here</a></span><br/><br/>';
		string+='<span>email:</span><br/>';
//		string+='<span id="id_auth_email" editwith="input"></span><br/>';
		string+='<input id="id_auth_email" viewwith="span" prompt="jbloggs@yahoo.co.uk"></input><br/>';
		string+='<span>password:</span><br/>';
//		string+='<span id="id_auth_password" type="password" editwith="input"></span><br/>';
		string+='<input id="id_auth_password" type="password" viewwith="span"></span><br/>';
		string+='</span>';
		elt.html(string);
		elt.find('a').click(Hc.AjaxEdit.switchToRegister);
	},
	addRegisterFields : function(elt) {
		var string="<br/>";		
		string+='<span class="showOnEdit">';
		string+='<span>Register below. Already have an account? <a href="#">Login here</a></span><br/><br/>';
		string+='<span>Name:</span><br/>';
		string+='<input id="id_auth_name" viewwith="span"></input><br/>';
		string+='<span>email:</span><br/>';
		string+='<input id="id_auth_email" viewwith="span"></input><br/>';
		string+='<span>password:</span><br/>';
		string+='<input id="id_auth_password" type="password" viewwith="span"></input><br/>';
		string+='<span>password again:</span><br/>';
		string+='<input id="id_auth_password2" type="password" viewwith="span"></input><br/>';
		string+='</span>';
		elt.html(string);
		elt.find('a').click(Hc.AjaxEdit.switchToLogin);
	},
	clearLoginRegisterFields : function(elt) {
		elt.html('');
	},
	switchToLogin : function() {
		var authform = $(this).parents('#loginRegisterWrapper');
		Hc.AjaxEdit.addLoginFields(authform);
		return false;
	},
	switchToRegister : function() {
		var authform = $(this).parents('#loginRegisterWrapper');
		Hc.AjaxEdit.addRegisterFields(authform);
		return false;
	},
	
	// convert all INPUT elts to view-only non editable elts.
	viewInputs : function(elts) {
		var inputs = elts.filter("input");
		inputs.each( function(){
            var tagName = $(this).attr('viewwith');
			var elt = $('<'+ tagName + ' ' +
				'id="'		+ $(this).attr('id') 		+ '" ' + 
				'class="' 	+ $(this).attr('className') + '" ' +
				'prompt="' 	+ $(this).attr('prompt')	+ '" ' +
				'maxlength="' 	+ $(this).attr('maxlength')	+ '" ' +
				'type="'    + $(this).attr('type')      + '" ' + 				
				'editwith="input" ' +
				'>' +
				$(this).val() +
				'</' + tagName + '>');
            elt.removeClass(tagName);
			$(this).replaceWith(elt);
		});	
	},

	// convert all CHECKBOXES elts to spans that are visible or not 
	// depending on whether they are checked or not.
	viewCheckBoxes : function(elts) {
		var viewWithCheckbox = elts.filter("[viewwith=checkbox]");
		viewWithCheckbox.each( function(){
			var checked = "";
			if( $(this).find('input').attr('checked') ){
				checked="checked";
			}
			text = $(this).html().split('>')[1];
			var eltString = '<span '+
				'id="'		+ $(this).attr('id') 		+ '" ' + 
				'class="checkbox ' 	+ checked + '" ' +
				'editwith="checkbox" ' +
				'type="checkbox">'+text+'</span>';
			var elt = $(eltString);
			$(this).replaceWith(elt);
		});
	},

	// convert RADIOBUTTON elts to spans that are viewable or not 
	// depending on which one is selected or not.
	viewRadioBoxes : function(elts) {
		var viewWithRadio = elts.filter("[viewwith=radioButtons]");
		viewWithRadio.each( function(){
			$(this).removeAttr('viewwith');
			$(this).attr('editwith','radioButtons');
			var labels = $(this).find('label');

			labels.each( function(){
				var elt = $('<span ' +
					'dbvalue="' + $(this).children().attr('dbvalue') + '" ' +
					'>' +
					$(this).text() +
					'</span>');
				if($(this).children('input').attr('checked') == true) {
					elt.addClass('selected');
				}
				$(this).replaceWith(elt);
			});		
		});	
	},

	// convert all predictive text subject list elts to list of links to the subjects
	viewSubjectList : function(elts) { 
		// get all editable subjectLists elts.
		var viewWithSubjectList = elts.filter("[viewwith=subjectList]");
		viewWithSubjectList.each( function(){
			pInnerHtml = "";
			var subjectString = $(this).val();
			// replace any newlines, carriage returns, tabs etc with comma.
			subjectString = subjectString.replace(/[\n\f\r\t]+/g, ",");
			var subjects = subjectString.split(',');
			for(var i=0; i<subjects.length; i++ ) {
				subject = jQuery.trim(subjects[i]);
				if(subject != "") {
					pInnerHtml += '<a href="/subject/'+subject+'">' + subject + '</a>, ';
				}
			}
			var elt = $('<div ' +
				'id="' + $(this).attr('id') + '" ' +
				'class="' + $(this).attr('className') + '" ' +
				'editwith="subjectList" ' +
				'>' + 
				pInnerHtml + 
				'</div>');
			$(this).replaceWith(elt);			
		});
	},

	// convert 'rte' elements to a DIV element.
	viewText : function(elts, form) { 
		var viewWithText = elts.filter("[viewwith=rte]");
		var content = Hc.AjaxEdit.removeRte(form);

		viewWithText.each( function(){		
			$(this).val(content);
			$(this).show();
			//$.wymeditors(0).hide();
			var eltString = '<div ' +
				'id="'		+ $(this).attr('id') 		+ '" ' + 
				'class="' 	+ $(this).attr('className') + '" ' +
				'editwith="rte" ' +
				'>'+$(this).val()+'</div>';
			var elt = $(eltString);
			$(this).replaceWith(elt);
		});		
	},
	

	
	
	
	
	// convert a form element from being editable to non editable.
	disableEditing : function(form) {
		
		if( Hc.AjaxEdit.disableRte ) {
			Hc.AjaxEdit.disableRte();
		}
		Hc.AjaxEdit.disableRte = null;
		
		// change class on form
		form.removeClass('contentEdit');
		form.addClass('contentView');
		
		// get all editable elts.
		var viewWith = form.find("[viewwith]");

		// and convert them to view elts.
		Hc.AjaxEdit.viewInputs(viewWith);
		Hc.AjaxEdit.viewCheckBoxes(viewWith);
		Hc.AjaxEdit.viewRadioBoxes(viewWith);
		Hc.AjaxEdit.viewSubjectList(viewWith);
		Hc.AjaxEdit.viewText(viewWith, form);		
	},


	// save the content in this div.
	save: function(){

		var form = $(this).parents('.contentEdit');
		
		// disable editing, switch all inputs and textareas back to normal elements
		Hc.AjaxEdit.disableEditing(form);
		
		// now grab the data we want to post
		var postData = {};
		var formDataElts = form.find('[editwith]');
		for(var i=0; i<formDataElts.length; i++) {
			// list of subjects in 'a' tags...
			if($(formDataElts[i]).attr('editwith') == 'subjectList') {
				var as = $(formDataElts[i]).find('a');
				var textareaString = "";
				as.each( function() {
					textareaString += $(this).html() + ', ';
				});
				postData[formDataElts[i].id] = textareaString;
			}
			// a checkbox
			else if($(formDataElts[i]).attr('editwith') == 'checkbox') {
				var radioValue = "0";
				if($(formDataElts[i]).hasClass('checked')) {
					radioValue = "1";
				}
				postData[formDataElts[i].id] = radioValue;
			}
			// a radio group
			else if($(formDataElts[i]).attr('editwith') == 'radioButtons') {
				var radioInputs = $(formDataElts[i]).find('span');
				var radioValue = "";
				radioInputs.each( function() {
					if( $(this).hasClass('selected')==true ) {
						radioValue = $(this).attr('dbvalue');
					}
				});
				postData[formDataElts[i].id] = radioValue;
			}
			// get the value or innerHTML as appropriate
			else {
				if(formDataElts[i].value) {
					postData[formDataElts[i].id] = formDataElts[i].value;
				} else {
					// check if the innerHTML = the prompt, 
					// if so, just replace with empty string.
					var prompt  = $(formDataElts[i]).attr('prompt');
					if(prompt == "undefined"){
					}
					else {
						if(prompt == formDataElts[i].innerHTML) {
							formDataElts[i].innerHTML = "";
						}
					}
					// now add the innerHTML tp the post.
					postData[formDataElts[i].id] = formDataElts[i].innerHTML;
				}
			}
		}	

		var url = $(this).attr('href');
				
		// now do the post...
		$.ajax({
			type: "POST",
			url: url,
			data: postData,
			error:function(xhr, status, errorThrown) {
                alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
			},
			success: function(response){
				
				var container;
				var templateCopy = form.parent(".templateCopy");
				if(templateCopy.length > 0) {				
					container = templateCopy;
				} else {
					container = form;
				}
				// extract data from the response and place it
				// in the appropriate areas.
//				alert(response);
				eval("var responseObj = "+response+";");
				for( name in responseObj.data ){
					// grab any element with id matching the one in the returned data
					var elts = container.find('[id='+name+']');
					// if we can't find an element with the correct id, then we create one.
					if(elts.length == 0) {
						container.children('.contentView').each( function () {
							var spanHtml = '<span id="'+name+'" class="hidden" editwith="none"></span>';
							$(this).prepend(spanHtml);
						});
						elts = container.find('[id='+name+']');
					}
					// elts should have at least one item in it now.
					if(elts.length > 0) {
						// if we have an object then we got some attribute/value pairs that
						// need to be added to the element in question
						if(typeof(responseObj.data[name]) == "object") {
							for( attr in responseObj.data[name] ){								
								if(attr == 'html') {
									elts.html(responseObj.data[name][attr]);
								} else {
									elts.attr(attr,responseObj.data[name][attr]);
								}
							}
						}
					}
				}
				// if we have some returned lat/lngs, update the map.
				if(responseObj.location) {
					Hc.Map.zoomToLocation(responseObj.location.lat, responseObj.location.lng, responseObj.location.acc);
				}
				
				var editElts = container.find('a.ajaxEdit');
				
				// if we just created new content (not edited) then a template copy will be wrapping our form
				// if this is the case, we move all of the contents in the template copy to *before* the template copy.
				// then we delete the copy. The sum effect of this is to remove the wrapping template copy div,
				// whilst preserving its contents.
				if(templateCopy.length > 0) {
					templateCopy.each( function (){
						var templateCopyInstance = $(this);
						templateCopyInstance.children().each( function(){
							$(this).css("display","block");
							$(this).insertBefore(templateCopyInstance);
						});
					});
				}
				templateCopy.remove();
				
				if(responseObj.action) {
					responseObj.action.method(responseObj.action.url);
				} else {
					$('#pleaseWaitOverlay').jqmHide();
				}
				
				if(responseObj.success == false) {					
					editElts.click();
				}

			}
		});		
		

		// finally set up the click handler enable edit for next time.
		//$(this).html("Edit");
		//$(this).unbind("click").click( Hc.AjaxEdit.edit );				
		
		// Handle rich texts and their images/videos.
		var rteElts = form.find('[editwith=rte]');
		if(rteElts.length > 0) {
			// HANDLE THE IMAGES IN THE POST:
			// put back any images
			var rteHtml = rteElts.html();
			//alert(rteHtml);
			var images = form.find('div.imageHolder').children();
			images.each( function (){
				imageId = $(this).attr('rel');
				imageSrc = $(this).find('img').attr('src');
				var re = new RegExp("\\<[pP]\\>\\[Image\\:"+imageId+"\\|([^\\]]*)\\]\\<\/[pP]\\>","g");
				var match = re.exec(rteHtml);
				//alert(match[1]);
				rteHtml = rteHtml.replace(re,'<div class="postPhotoFrame" rel="'+imageId+'"><img src="'+imageSrc+'" /><br/><span>'+match[1]+'</span></div>');
			});
			form.find('div.imageHolder').remove();
			// END put back images


			
			// HANDLE THE VIDEOS IN THE POST:
			var re = new RegExp("\\<[pP]\\>\\[Video\\:([^\\]]*)\\]\\<\/[pP]\\>","g");		
			
			htmlToInsert  = '<object type="application/x-shockwave-flash" width="460" height="340" data="http://www.youtube.com/v/'+"$1"+'" rel="'+"$1"+'">'
			htmlToInsert +=	'<param name="movie" value="http://www.youtube.com/v/'+"$1"+'"></param>'
			htmlToInsert +=	'<param name="flashVars" value="playerMode=embedded"></param>'
			htmlToInsert +=	'<param name="allowFullScreen" value="true"></param>'
			htmlToInsert +=	'<param name="allowscriptaccess" value="always"></param>'
			htmlToInsert +=	'<param name="wmode" value="transparent">'	
			htmlToInsert +=	'</object>'		
			
			rteHtml = rteHtml.replace(re,htmlToInsert);
			// END put back videos

			// Finally put the html back into the div.
			rteElts.html(rteHtml);
		}


		// remove backup copy for cancel
		var copy = form.prev('.contentView').remove();

		
		//alert("end save");
		return false;
	},

	inputOnBlur : function() {
		if($(this).attr("prompt") != "undefined") {
			// if the input value is empty, set it to be the prompt string
			if($(this).val() == "") {
				$(this).val($(this).attr("prompt")).addClass("prompt");
			}
		}
		
	},
	inputOnFocus : function() {
		if($(this).attr("prompt") != "undefined") {
			// if the input value is the prompt, set it to be empty
			if($(this).val() == $(this).attr("prompt")) {
				$(this).val("").removeClass("prompt");
			}
		}
	},
	
	edit: function(){
	
		var form = $(this).parents('.contentView');
		
		// before anything else - copy the content and place immediately before, with display:none;
		// we use this in the case of the user doing a cancel,
		// we just replace the copied form
		var formCopy = form.clone(true);
		formCopy.css({display:"none"});
		form.before(formCopy);
		
		
		// HANDLE THE IMAGES IN THE POST:
		// first of all remove any images from the post and 
		// store in an image holder. We will put them back 
		// when we have finished editing and the post is saved.
		var rteElts = form.find('[editwith=rte]');
		var imageHolder = $('<div class="imageHolder" style="display:none"></div>');
		rteElts.before(imageHolder);
		var images = rteElts.find('div.postPhotoFrame');
		images.each( function (){
			var image = $(this).replaceWith('<p>[Image:'+$(this).attr('rel')+'|'+$(this).find('span').html()+']</p>');
			imageHolder.append(image);
		});
		// END remove images
		
		// HANDLE THE VIDEOS IN THE POST:
		// replace any objects with <p>[Video:id]</p>
		var videos = rteElts.find('object');
		videos.each( function (){
			var video = $(this).replaceWith('<p>[Video:'+$(this).attr('rel')+']</p>');
		});
		// END replace images		
		
		
		// change class on form from viewing to editing.
		form.removeClass('contentView');
		form.addClass('contentEdit');
		
		// remove click handler from the link that triggered it.
		//var editLinks = form.find('.ajaxEdit');				
		//editLinks.unbind("click");
		
		// get all editable elts.
		var editWith = form.find("[editwith]");
		
		// now transform them - starting with the inputs...
		var editWithInput = editWith.filter("[editwith=input]");
		editWithInput.each( function(){
			var eltString = '<input ' +
				'id="'		+ $(this).attr('id') 		+ '" ' + 
				'class="' 	+ $(this).attr('className') + " " +this.tagName.toLowerCase()+ '" ' +
				'prompt="' 	+ $(this).attr('prompt')	+ '" ' +
				'maxlength="' 	+ $(this).attr('maxlength')	+ '" ' +
				'value="'	+ $(this).html() 			+ '" ' +
				'viewwith="'+ this.tagName.toLowerCase()+ '" ' +
				'type="'    + $(this).attr('type')      + '" ' + 
				'/>';
			var elt = $(eltString);
			elt.blur( Hc.AjaxEdit.inputOnBlur );
			elt.blur();
			elt.focus( Hc.AjaxEdit.inputOnFocus );
			$(this).replaceWith(elt);
			
			// if this input has a datepicker class then attach the datepicker to it,
			// triggered by clicking on it.
			if(elt.hasClass("datepicker")){
				elt.datePicker({clickInput:true, createButton:false});
			}
		});
		
		var editWithCheckbox = editWith.filter("[editwith=checkbox]");
		editWithCheckbox.each( function(){
			var checked = "";
			if ($(this).hasClass("checked")) {
				checked='checked="checked" ';
			}
			var eltString = '<label '+
				'for="' + $(this).attr('id') + '" ' +
				'id="'		+ $(this).attr('id') 		+ '" ' + 
				'class="checkbox" ' +
				'viewwith="checkbox">' +
				'<input ' +
				checked +
				'type="checkbox" />'+$(this).html()+'</label>';
			var elt = $(eltString);
			$(this).replaceWith(elt);
		});
		
		var editWithRadio = editWith.filter("[editwith=radioButtons]");
		editWithRadio.each( function(){
			var groupName = "radioGroup"+Math.floor((Math.random()*100000));
			$(this).removeAttr('editwith');
			$(this).attr('viewwith','radioButtons');
			var spans = $(this).find('span');
			spans.each( function(i){
				var elt = $('<label for="radio'+groupName+'_'+i+'"><input id="radio'+groupName+'_'+i+'" type="radio" name="'+groupName+'" class="radio"' +
					'dbvalue="' + $(this).attr('dbvalue') + '" ' +
					'/>' +
					$(this).html() +
					'</label>');
				if($(this).hasClass('selected')) {
					elt.children('input').attr('checked','checked');
				}				
				$(this).replaceWith(elt);
			});
		});
		
		// get all editable subjectLists elts.
		var editWithSubjectList = editWith.filter("[editwith=subjectList]");
		editWithSubjectList.each( function(){
			as = $(this).find('a');
			textareaString = "";
			as.each( function(i) {
				textareaString += $(this).html() + ', ';
			});

			var elt = $('<textarea ' + 
				'id="' + $(this).attr('id') + '" ' +
				'class="' + $(this).attr('className') + '" ' +
				'viewwith="subjectList"' +
				'>' + 
				textareaString +
				'</textarea>');

/*
			var elt = $('<input ' + 
				'id="' + $(this).attr('id') + '" ' +
				'class="' + $(this).attr('className') + '" ' +
				'viewwith="subjectList"' +
				'value="' + textareaString +
				'"/>');
*/
			$(this).replaceWith(elt);
			
			var formatItem = function(row) {
				return row[0];
				//return row[0] + " (<strong>id: " + row[1] + "</strong>)";
			}
			var formatResult = function(row) {
				return row[0].replace(/(<.+?>)/gi, '');
			}		
			// autocomplete stuff
			// elt.autocomplete('/subject/ajaxSearch/', {
			elt.autocomplete(fullSubjectList, {
				width: 300,
				multiple: !(elt.hasClass("singleSubject")),
				matchContains: true,
				formatItem: formatItem,
				formatResult: formatResult
			});			
		});

		var editWithText = editWith.filter("[editwith=rte]");
		editWithText.each( function(){
			var eltString = '<textarea ' +
				'id="'		+ $(this).attr('id') 		+ '" ' + 
				'class="' 	+ $(this).attr('className') + '" ' +
				'viewwith="rte" ' +
				'>'+$(this).html()+'</textarea>';
			var elt = $(eltString);
			$(this).replaceWith(elt);
			elt.wymeditor({
		        toolsItems: [
					{'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
					{'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
					{'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
					{'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
					{'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'}
				],
                containersItems: [
                    {'name': 'P', 'title': 'Paragraph', 'css': 'wym_containers_p'},
                    {'name': 'H4', 'title': 'Heading_4', 'css': 'wym_containers_h4'}
                ],
                skin: 'hc'
			});
		});

		// enable rte on any divs with class .rteContent
		var rtes = editWith.filter("[editwith=jrte]");
		var disableFunction = rtes.rte('/css/Hc.ajaxEdit.css'); 
		if(disableFunction) {
			Hc.AjaxEdit.disableRte = disableFunction;
			//$(editLinks).click( disableFunction );
		}
		
		// set up this link to perform save.
		//$(editLinks).html("Save");
		//$(editLinks).click( Hc.AjaxEdit.save );		

		$('a.jqModal').click(function(){
			$('#dialog').jqmShow(this);
		});
		
		
		/*
		var elts = form.find('.showOnEdit');
		elts.each( function(){
			$(this).css({'display':'block'});
		});
		
		var elts = form.find('.hideOnEdit');
		elts.each( function(){
			$(this).css({'display':'none'});
		});
		*/
		//("end edit");
		
		$('#pleaseWaitOverlay').jqm({
			trigger: 'a.pleaseWait',
			onShow: function(hash) {
				hash.w.fadeIn('500',function(){});
			},
			onHide: function(hash) {
				hash.w.fadeOut('500',function(){ 
					hash.o.remove(); 
				});
			},
			toTop:true
		});
		
		
		return false;
	},

	removeRte: function(form) {
	
		// disable an rte on form
		var textareas = form.find('[viewwith=rte]');
		var content = "";
        for(var i=0; i<WYMeditor.INSTANCES.length; i++) {
            if(WYMeditor.INSTANCES[i] && WYMeditor.INSTANCES[i]._element[0] == textareas[0]) {
                // grab content
                content = WYMeditor.INSTANCES[i].xhtml();
                WYMeditor.INSTANCES[i] = null;
                break;
            }
        }
		form.find('.wym_box').remove();		
		return content;
	},

	cancel: function() {
	
		var form = $(this).parents('.contentEdit');
		
		///////////////////////////////////////////////////////////////
		// show the copy and kill the form ( disable all rtes aswell )
		
		// show the form
		var copy = form.prev('.contentView').css({display:"block"});
		
		// However, if the content was going to be new, and therefore when cancelled
		// did not have an id, we should remove it too. Otherwise end up with empty
		// piece of content.
		var idSpans = copy.find('span[id="id_id"]');
		if(idSpans.length == 0) {
			copy.remove();
		}
		
		
		// disable RTE
		Hc.AjaxEdit.removeRte(form);
		
		// kill the form
		form.remove();
		
		
		$('a.jqModal').click(function(){
			$('#dialog').jqmShow(this);
		});

		
		return false;
	},

	newContent: function() {
		// copy the reply template and remove the "template_reply" id.
		var newPostContent = $($(this).attr('template')).clone(true);
		newPostContent.removeAttr("id");
		newPostContent.addClass("templateCopy");
		// get the contentView element inside the template.
		var newPostForm = newPostContent.children('.contentView');
		if( newPostForm.length > 0) {
			// grab any extra post data that needs to be added to the template copy,
			// that is specific to this particular link.
			var extraPostData = $(this).find('[editwith=none]');
			extraPostData.each( function() {
				modifiableElts = newPostForm.find('[id='+this.id+']');
				if(modifiableElts.length > 0) {
					modifiableElts.html($(this).html());
				} else {
					newPostForm.prepend($(this).clone());
				}
			});
		}

		// now add the copy after the block containing the link that activated this template
		// and show it
		var contentView = $(this).parents('.contentView');
		if(contentView.length > 0) {
			if($(this).attr("placement") == "before") {
				newPostContent.insertBefore($(this).parents('.contentView'));
			} else {
				newPostContent.insertAfter($(this).parents('.contentView'));
			}
		}
		else {
			if($(this).attr("placement") == "before") {
				newPostContent.insertBefore($(this).parent());
			} else {
				newPostContent.insertAfter($(this).parent());
			}
		}
		
		
		newPostContent.css({
			"display": "block"
		});
		// finally activate the the form.
		newPostContent.find("a.ajaxEdit").click();
		
		// add login/register fields if necessary.
		var loginRegisterWrapper = newPostContent.find("#loginRegisterWrapper");
		Hc.AjaxEdit.addRegisterFields( loginRegisterWrapper );		
		
		return false;
	},
	
	redirect: function(url) {
		window.location = url;
	},
	
	init: function() {
		// set up onclick for post edits
		$("a.ajaxEdit").click( Hc.AjaxEdit.edit );
		$("a.ajaxSave").click( Hc.AjaxEdit.save );
		$("a.ajaxEditNewContent").click( Hc.AjaxEdit.newContent );
		$("a.ajaxEditCancel").click( Hc.AjaxEdit.cancel );
	}
	
};
