//CKEDITOR STUFF
var richTextOptions = {
	toolbar: [	
		['Bold','Italic','Underline','Strike','-','NumberedList','BulletedList','-','Link','Unlink','-','Image','MediaEmbed', '-', 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','SpellCheck']
	],
	scayt_autoStartup: false,
	disableNativeSpellChecker: false,
	skin:'kama',
	removePlugins: 'scayt,menubutton,contextmenu',
	resize_maxWidth: 560,
	width:560
};

if (typeof(CKEDITOR) != 'undefined') {
	CKEDITOR.on( 'dialogDefinition', function( ev )
	{
		// Take the dialog name and its definition from the event data.
		var dialogName = ev.data.name;
		var dialogDefinition = ev.data.definition;
 
		// Check if the definition is from the dialog we're
		// interested on (the Link dialog).
		if ( dialogName == 'link' )
		{
			// FCKConfig.LinkDlgHideAdvanced = true
			dialogDefinition.removeContents( 'advanced' );
 
			// FCKConfig.LinkDlgHideTarget = true
			dialogDefinition.removeContents( 'target' );
/*
Enable this part only if you don't remove the 'target' tab in the previous block.
 
			// FCKConfig.DefaultLinkTarget = '_blank'
			// Get a reference to the "Target" tab.
			var targetTab = dialogDefinition.getContents( 'target' );
			// Set the default value for the URL field.
			var targetField = targetTab.get( 'linkTargetType' );
			targetField[ 'default' ] = '_blank';
*/
		}
 
		if ( dialogName == 'image' )
		{
			// FCKConfig.ImageDlgHideAdvanced = true	
			dialogDefinition.removeContents( 'advanced' );
			// FCKConfig.ImageDlgHideLink = true
			dialogDefinition.removeContents( 'Link' );
		}
 
		if ( dialogName == 'flash' )
		{
			// FCKConfig.FlashDlgHideAdvanced = true
			dialogDefinition.removeContents( 'advanced' );
		}
 
	});
}



$(window).load(function() {
		$('.media_embed').css('display','block');
});

$(function(){
	
	$('.replyButton').click(function() {
		var commentReplyContainer = $(this).siblings('.commentReplyContainer');
		commentReplyContainer.toggle();
		commentReplyContainer.find('.commentTextArea').focus();
		return false;
	});
	
	var commentToggle = function(elem) {
		var elemParent = $(elem).parents('.commentContainer');
		var commentEdit = elemParent.find('.commentEdit');
		elemParent.find('.commentContent').toggle();
		commentEdit.toggle();
		if (!commentEdit.hasClass('richtext')) {
			commentEdit.addClass('richtext');
			commentEdit.find('textarea').ckeditor(function(){}, richTextOptions);
		}
		return false;
	};
	$('.commentEditLink').click(function () {
			if ($(this).text() == 'edit') {
			$(this).text('cancel');
		} else {
			$(this).text('edit');
		}
	return commentToggle(this);
	});
	
	$('.commentDeleteLink').click(function () {
		var commentId = $(this).attr('mid');
		$("#diaglogConfirmCommentDelete").dialog({
			resizable: false,
			height: 140,
			modal: true,
			buttons: {
				"Confirm": function() {
							$.post('/Comment/Unpublish', {commentId: commentId}, function(data) {
							window.location.reload();
							}, 'json');
				},
				Cancel: function() {
					$(this).dialog( "close" );
				}
			}
		});

		

	});
	
	
	$('.commentReplyLink').click(function() {
		if ($(this).text() == 'Post A Reply') {
			$(this).text('Cancel');
		} else {
			$(this).text('Post A Reply');
		}
		return commentToggle(this);
	});
	
	$('.commentUpdateButton').click(function() {
		var formData = $(this).siblings('form').serializeArray();
		$.post('/Comment/Edit', formData, function(data) {
			var container = $('#' + data.data.id);
			container.find('.commentContent').html(data.data.content);
			container.find('.commentEdit').hide();
			container.find('.commentContent').show();
			container.find('.commentEditLink').text('edit');			
		},'json');
	});



});
setInterval(function() {
	$.ajax({
			url: '/Chat/ajaxUsersChatting/',
			cache: false,
			success: function(html) {
				$('#ajaxUsersChatting').html(html);
			}
	});
	},60 * 1000);

