
if (typeof _pcsg == 'undefined') {
	var _pcsg = {};
};

_pcsg.Blog =
{
	comments : function(elm, id)
	{
		if (!$('comments'+ id)) {
			return;
		};

		$('comments'+ id).innerHTML = '';
		$('comments'+ id).style.background = 'url("'+ PROJECT_BIN_URL +'images/loader.gif") no-repeat center center';

		new Fx.Morph($('comments'+ id), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function(Elm)
			{
				_Ajax.asyncPost('ajax_blog_get_comments', function(result, Ajax)
				{
					var Elm = Ajax.getAttribute('Elm');

					if (!Elm) {
						return;
					};

					Elm.style.background = '';
					Elm.innerHTML = result;

				}, {
					project : _Project.name,
					id      : id,
					Elm     : Elm
				});
			}
		}).start({
			height : 30
		});
	},

	answer : function(elm, id)
	{
		if (!$('answer'+ id)) {
			return;
		};

		new Fx.Morph($('answer'+ id), {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut,
			onComplete : function(Elm)
			{
				Elm.innerHTML = '' +
					'<textarea style="margin: 10px; width: 660px; height: 120px;" id="text_answer_'+ id +'"></textarea>' +
					'<div id="answer_btn_'+ id +'" style="width: 200px; margin: 0 auto; clear: both;"></div>';

				$('answer_btn_'+ id).appendChild(
					new _ptools.Button({
						name    : 'answer',
						text    : 'senden',
						width   : 100,
						onclick : function(Btn)
						{
							var id   = Btn.getAttribute('id');
							var text = $('text_answer_'+ id).value;

							_Ajax.asyncPost('ajax_blog_create_comment', function(params, Ajax)
							{
								_pcsg.Blog.closeAnswer( Ajax.getAttribute('Elm') );
							}, {
								Elm     : Btn.getAttribute('Elm'),
								project : _Project.name,
								id      : id,
								text    : text
							});

						},
						project : _Project.name,
						id      : id,
						Elm     : Elm
					}).create()
				);

				$('answer_btn_'+ id).appendChild(
					new _ptools.Button({
						name    : 'cancel',
						text    : 'abbrechen',
						width   : 100,
						onclick : function(Btn)
						{
							_pcsg.Blog.closeAnswer( Btn.getAttribute('Elm') );
						},
						project : _Project.name,
						id      : id,
						Elm     : Elm
					}).create()
				);

			}
		}).start({
			height : 200
		});
	},

	closeAnswer : function(Elm)
	{
		Elm.innerHTML = '';

		new Fx.Morph(Elm, {
			duration   : 500,
			transition : Fx.Transitions.Quad.easeOut
		}).start({
			height : 0
		});
	}
};