/**
 * Comments block
 * @author Rygor Kharytanovich
 * @extends jquery
 * Usage: $(<selector>).comments();
 */

jQuery.fn.extend({
	comments: function () {
		
		if (this) {
			
			$(this).find('.comment-cont').each(function () {
				
				var el = $(this);
				
				el
					.mouseover(function () {
						el.addClass('comment-cont-hover')
					})
					.mouseout(function () {
						if (!el.hasClass('comment-cont-opened')) {
							el.removeClass('comment-cont-hover')
						}
					})
					.find('.reply a').click(function () {
						el.find('form').slideDown();
						el.addClass('comment-cont-opened');
					}).end()
					.find('.close a').click(function () {
						el.find('form').slideUp();
						el.removeClass('comment-cont-opened');
					}).end();
				
			});
			
			$(this).find('.post').each(function () {
				var me = $(this),
					form = $(this).find('form');
				$(this).find('.makepost a').click(function () {
					if (!form.is(':visible')) {
						form.slideDown();
						me.addClass('post-opened');
					}
				})
				form.find('.close a').click(function () {
					if (form.is(':visible')) {
						form.slideUp();
						me.removeClass('post-opened');
					}
				})
			});
			
		}
		
		$('.ccomments-page form').show();
		
	}
});



