	//DELETE WHITEBOARD THREAD MODAL
	function deletePost(d, thread_id, id, confirm_question, success_msg, fail_msg, cr_name) {
		$(d).html(confirm_question);
		
		$(d).dialog({			
			closeOnEscape: false,
			draggable: false,	
			bgiframe: true,
			modal: true,
			title: 'Delete Post',
			buttons: {
				Yes: function() {
					$.post('/'+cr_name+'/whiteboard/' + action, {thread_id: thread_id, id: id}, function(data){
						if (data.verify == 0) {
							showDialogConfirm(data.msg, success_msg, '/'+cr_name+'/whiteboard');				
						}
						else {
							showDialogError(data.msg, fail_msg);
							$(d).remove();
						}
					}, "json");
				},
				Cancel: function() {
					$(d).remove();
				}
			}
		});
	}
	
// CREATE NEW WHITEBOARD THREAD
$(function() {

	//gets classroom name from URL
	var cr_name = window.location.pathname.split('/',2)[1];
	var wb_message = $('#wb_message');

	//SETS VARIABLES FOR DELETE COMMENT REQUEST
	$('.deleteComment').click(function () {
		var d = $('body').append('<div></div>').find(':last');
		thread_id = $(this).attr('thread_id');
		id = $('#id').attr('name');
		action = 'delete_comment';		
		confirm_question = 'Are you sure you want to delete this comment?';
		success_msg = 'Comment successfully deleted.';
		fail_msg = 'Deletion Error.  Please contact Customer Support.';
		
		$(d).dialog({
			open:function() {
			},
				draggable: false,		
				bgiframe: true,
				autoOpen: false,
				height: 150,
				width: 300,
				modal: true
		});
								
		$(d).dialog('open');
		$(d).html('Loading...');
		
		deletePost(d, thread_id, id, confirm_question, success_msg, fail_msg, cr_name);	
		return false;
	});		

	//SETS VARIABLES FOR DELETE THREAD REQUEST
	$('.deleteThread').click(function () {
		var d = $('body').append('<div></div>').find(':last');
		thread_id = $(this).attr('thread_id');
		id = $('#id').attr('name');
		action = 'delete_thread';
		confirm_question = 'Are you sure you want to delete this thread?';
		success_msg = 'Thread successfully deleted.';
		fail_msg = 'Deletion Error.  Please contact Customer Support.';
		
		$(d).dialog({
			open:function() {
			},
				draggable: false,		
				bgiframe: true,
				autoOpen: false,
				height: 150,
				width: 300,
				modal: true
		});
								
		$(d).dialog('open');
		$(d).html('Loading...');
					
		deletePost(d, thread_id, id, confirm_question, success_msg, fail_msg, cr_name);	
		return false;
	});				

	//SETS VARIABLES FOR NEW WB THREAD
	$('.wb_thread').click(function () {
		var d = $('body').append('<div></div>').find(':last');

		$(d).dialog({
			open:function() {
			},
				draggable: false,		
				bgiframe: true,
				autoOpen: false,
				height: 400,
				width: 600,
				modal: true
		});
								
		$(d).dialog('open');
		$(d).html('Loading...');		
		
		$.get('/'+cr_name+'/whiteboard/load_thread_form', function(data) {				
			$(d).html(data);
			$(d).dialog({
				title: 'Create New Whiteboard Post',
				buttons: {
					'Save Whiteboard Post': function() {
							$.post('/'+cr_name+'/whiteboard/new_post', $('#submit_wall').serialize(), function(data){
								if (data.verify == 0) {
									$(d).remove();
									showDialogConfirm(data.msg, 'Post successfully created', '/'+cr_name+'/whiteboard');
								}
								else if (data.verify == 9) {
									showDialogError(data.msg, 'Decency Policy Violation');
									$(d).remove();
								}
								else {
									showDialogError(data.msg, 'Posting Error');
								}
							}, 'json');
						},
					Cancel: function() {
						$(d).remove();
					}
				}
			});
		});
		return false;			
	});

	//SETS VARIABLES FOR NEW WB COMMENT
	$('.wb_comment').click(function () {
		var d = $('body').append('<div></div>').find(':last');
		thread_id = $(this).attr('thread_id');
		cr_id = $(this).attr('value');	
		
		$(d).dialog({
			open:function() {
			},
				draggable: false,		
				bgiframe: true,
				autoOpen: false,
				height: 400,
				width: 600,
				modal: true
		});
								
		$(d).dialog('open');
		$(d).html('Loading...');
		
		$.get('/'+cr_name+'/whiteboard/load_comment_edit_form', function(data) {				
			$(d).html(data);
			$('#thread_id').val(thread_id);
			$('#cr_id').val(cr_id);
			$(d).dialog({
				title: 'Create New Whiteboard Comment',
				buttons: {
					'Save Whiteboard Comment': function() {
							$.post('/'+cr_name+'/whiteboard/new_comment', $('#submit_wall').serialize(), function(data){
								if (data.verify == 0) {
									$(d).remove();
									showDialogConfirm(data.msg, 'Comment successfully saved', '/'+cr_name+'/whiteboard');			
								}
								else if (data.verify == 9) {
									showDialogError(data.msg, 'Decency Policy Violation');
									$(d).remove();
								}
								else {
									showDialogError(data.msg, 'Posting Error');
								}
							}, 'json');
						},
					Cancel: function() {
						$(d).remove();
					}
				}
			});
		});
		return false;	
	});	
	
	//SETS VARIABLES TO EDIT WB POST (THREAD OR COMMENT)
	$('.wb_edit_thread').click(function () {
		var d = $('body').append('<div></div>').find(':last');
		thread_id = $(this).attr('thread_id');
		message_text = $('.message' + thread_id).html();
		cr_id = $(this).attr('value');
		action = 'edit_post';
		
		$(d).dialog({
			open:function() {
			},
				draggable: false,		
				bgiframe: true,
				autoOpen: false,
				height: 400,
				width: 600,
				modal: true
		});
								
		$(d).dialog('open');
		$(d).html('Loading...');
		
		$.get('/'+cr_name+'/whiteboard/load_comment_edit_form', function(data) {				
			$(d).html(data);
			$('#thread_id').val(thread_id);
			$('#cr_id').val(cr_id);
			$('#type').val('U');
			$('#thread_id').val(thread_id);
			$('#wb_message').val(message_text);
			$(d).dialog({
				title: 'Edit Whiteboard Post',
				buttons: {
					'Save Changes': function() {
							$.post('/'+cr_name+'/whiteboard/edit_post', $('#submit_wall').serialize(), function(data){
								if (data.verify == 0) {
									$(d).remove();
									showDialogConfirm(data.msg, 'Post successfully updated', '/'+cr_name+'/whiteboard');				
								}
								else if (data.verify == 9) {
									showDialogError(data.msg, 'Decency Policy Violation');
									$(d).remove();
								}
								else {
									showDialogError(data.msg, 'Posting Error');
								}
							}, 'json');
						},
					Cancel: function() {
						$(d).remove();
					}
				}
			});
		});
		return false;
	});
});

