
function initComments() {
	// Make sure all comment are hidden when page is loaded
    $$('.xf_comments').each(function(el, idx) {
        el.slide('hide');
    });
    
	// Add FX.Slide to comment (slideIn, slideOut)
    $$('.xftogglecomment').addEvent('click', function(e) {
            var id = this.rel;
            e = new Event(e);
            var elName = "xfPost_" + id;
            $(elName).slide('toggle');
            e.stop();
    });
	
	// Add AJAX-save to comments
	$$('.xfcommentform').addEvent('submit', function(e) {
		e.stop();
		var postid = this.id.substring(12);
		var req = new Request.HTML({
			url: this.action,
			onRequest: function () {
				$('xfPost_' + postid).slide('toggle');
				$('xfPost_' + postid).set('text', 'Sparar...');
				$('xfPost_' + postid).slide('toggle');
			},
			onSuccess: function(html) {
				//Clear the text currently inside the results div.
				$('xfPost_' + postid).slide('toggle');
				$('xfPost_' + postid).set('text', '');
				//Inject the new DOM elements into the results div.
				$('xfPost_' + postid).adopt(html);
				$('xfPost_' + postid).slide('toggle');
			},
			//Our request will most likely succeed, but just in case, we'll add an
			//onFailure method which will let the user know what happened.
			onFailure: function() {
				alert('failure');
				$('xfPost_' + postid).set('text', 'The request failed.');
				$('xfPost_' + postid).slide('toggle');
				$('xfPost_' + postid).slide('toggle');
			}
		} ).post($(this));

	});
}

window.addEvent("domready", initComments);