function toggle_comment() {
var box = $('post_comment_box');

if (box.getStyle('height')==='0px') {
box.tween('height', '405px');
} else {
box.tween('height', '0px');
}

}

function comment_inject(img,name,comment_value) {
	toggle_comment();
	holder = new Element('article', {'id': 'comment_injected_div', 'class' : 'comment comment2 clearfix invisible' }),
	img = new Element('img', {'id': 'comment_injected_img', 'class' : 'avatar_left', 'src' : img }),
	comment = new Element('div', {'id': 'comment_injected'}),
	holder.inject(document.id('comment_box'), 'top');
	img.inject(holder, 'top');
	comment.inject(holder, 'bottom');
	comment.set('html', '<h3>'+name+'</h3>'+comment_value);
	holder.fade('in');
}



function comment_post(base, img) {

tinyMCE.triggerSave(true,true);

var btn = $('post_btn');

var req = new Request.JSON({
	method: 'post',
	url: base+'api/comment/post',
	data: {
	comment_name : $('comment_name').value,
	comment_email : $('comment_email').value,
	comment_website : $('comment_website').value,
	comment_text : $('comment_text').value,
	post_cat : $('cat').value,
	post_id : $('post_id').value,
	default_img : img
},
onRequest: function() {
btn.removeClass('btn_good');
btn.addClass('btn_deactive');
btn.set('html', 'Saving...');
},

onComplete: function(json) {
	
	if (json) {

		// if success message was received
		if (json.status==='success') {
			btn.removeClass('btn_deactive');
			btn.removeClass('btn_bad');
			btn.addClass('btn_info');
			btn.set('html', 'Comment Saved');
			comment_inject(json.img,json.name,json.comment);
		}
		
		// If error message was received
		else if (json.status==='error') {
			btn.removeClass('btn_deactive');
			btn.removeClass('btn_info');
			btn.addClass('btn_bad');
			btn.set('html', 'Error! Please try again.');
		}
	
		// if json.status was received
		else {
			btn.removeClass('btn_deactive');
			btn.removeClass('btn_info');
			btn.addClass('btn_bad');
			btn.set('html', 'Database Error!');
		}

	// If JSON response was not received (communication error)
	} else {

	}
	
}

}).send();

}



