// Jquery Script to load in default styles for blocked users and message for
// Lusssumo Vanilla Forum with the modified Comment-Protection add-on
// 
// This script removes ability to block one's own messages
//
// If working on a static page for testing the script generates the equivalent buttons
//
// This may not be distributed or modified without the express permission of stardotBMP
// email[at]stardotbmp[dot]com
//
// Prepared for fazyluckers.com by stardotBMP ©2008

var loggedUserID;

jQuery(document).ready( function($){
 $(document).ready(function() {

//	loggedUserID = $('.PreviewButton').attr('onclick').match(/[0-9]{1,}/);

	var loggedUser = $('.PreviewButton').attr('onclick');	
	loggedUserID = String(loggedUser).match(/[0-9]+/);

	Headers = $('.CommentHeader')
	
	
	/*/ Begin Remote Testing Function if a block user link s found
	$('.CommentHeader a').each(function() {
		if ($(this).html().match(/^block/)) { 	
				$(Headers).each(function(){
					var commentID = $(this).parents('li').attr('id').match(/Comment_([0-9]*)/)[1];
					var userID = $(this).children('ul').children('li').children('a').attr('href').match(/\/([0-9]*)\//)[1];
					if (userID != loggedUserID) $(this).children('span').prepend("<a href='./' id='BlockUser_"+userID+"_Comment_"+commentID+"' onclick=\"BlockUser('/extensions/CommentProtection/block.php', '"+userID+"', '0', 'unblock user', 'Allow HTML in all comments by this user on the forum', 'block user', 'Block HTML in all comments by this user on the forum', 'unblock comment', 'Allow HTML in this comment', 'block comment', 'Block HTML in this comment'); return false;\" title='Block HTML in all comments by this user on the forum'>unblock user</a><a href='./' id='BlockComment_"+commentID+"' onclick=\"BlockComment('/extensions/CommentProtection/block.php', '"+commentID+"', '1', 1, false, 'unblock comment', 'Allow HTML in this comment', 'block comment', 'Block HTML in this comment'); return false;\" title='Block HTML in this comment'>block comment</a>");
				});		
			}
	});
	// End Remote Testing Function */

	// Begin Remove Block Own Message Buttons
	$(Headers).each(function(){
		var userID = $(this).children('ul').children('li').children('a').attr('href').match(/\/([0-9]{1,})\//)[1];
		if (userID == loggedUserID) {
			$(this).children('span').children('a').each(function() {
				correctUser = $(this).html().match(/block/);
				if (correctUser) {
					$(this).remove();
				}
			});
		}
	});
	// End Remove own messages
 	
 	// Begin Style Switcher on block mode function
 	$('.CommentHeader span a').each(function(){
 	
		var bComment = ($(this).html().match(/^unblock comment/));
		var bUser = ($(this).html().match(/^unblock user/));
		
		if (bComment) $(this).parents('li').toggleClass(blockCommentClass)
		if (bUser) $(this).parents('li').toggleClass(blockUserClass)
	});
	// End Style Switcher
 });
});