// LWS Custom Scripts
$(function() {
	// Enable the media plugin
	$(".lwsMedia").media();
	
	// Hide comments from selected users
	$(".hideThisUser").click(function() {
		// Get the name of author to hide
		var whichUser = $(this).children().attr("class");
		
		// Check to see if there is already a cookie set
		var cookieValue = $.cookie("hideThisCommentor");
		var quote = "'";
		var comma = ",";
				
		if (cookieValue) {
			var addToCookie = cookieValue + comma + quote + whichUser + quote;
		}
		else {
			var addToCookie = quote + whichUser + quote;
		}
				
		
		$.cookie("hideThisCommentor",addToCookie);
		
		// Fade out the comments by this user
		$(".userComment").each(function() {
			if (whichUser == $(this).attr("title")) {
				$(this).css("backgroundColor","#ffffcc").fadeOut(2000);
			}
		});
	});
	
	// Require the user to login
	
	// Create a login form
	$(".pleaseLogin").click(function() {
		var sitePath = $(this).attr("title");
		var itemType = $(this).attr("rel");
		var itemId = $(this).attr("itemId");
		requireLiveLogin(sitePath,itemType,itemId);
	});
	
	function requireLiveLogin(sitePath,itemType,itemId) {
		var startForm = '<form action="' + sitePath + '/login/?itemType=' + itemType + '&amp;itemId=' + itemId + '" method="post">';
		var endForm = '</form>';
		var usernameLabel = '<label for="lwsUsername">Username</label>';
		var username = '<input type="text" name="username" class="text" id="lwsUsername" />';
		var passwordLabel = '<label for="lwsPassword">Password</label>';
		var password = '<input type="password" name="password" class="text" id="lwsPassword" />';
		var submitButton = '<input type="submit" value="submit" />';
		var cancelButton = '<input type="button" value="Cancel" onClick="window.location.href="' + window.location.href + ' />';
		
		// Div elements
		var blackBg = '<div id="blackBgLogin">&nbsp;</div>';
		var requireLoginStart = '<div id="lwsRequireLogin">';
		var startDiv = '<div class="lwsFormFields">';
		var endDiv = '</div>';
		
		
		// Explanation of must log in
		var loginText = '<h3>Please Login</h3>';
		
		// Put the whole thing together
		var completeLogin = blackBg + requireLoginStart + loginText + startForm + startDiv + usernameLabel + username + endDiv + startDiv + passwordLabel + password + endDiv + startDiv + submitButton + cancelButton + endDiv + endForm + endDiv;
		$(completeLogin).appendTo("body");

		// Now center the form horizontally
		$("#lwsRequireLogin").center({vertical:false});
		
		// Put a black box over everything else
		var pageWidth = $("body").width();
		var pageHeight = $("body").height();
		
		$("#blackBgLogin").css("width",pageWidth);
		$("#blackBgLogin").css("height",pageHeight);
		$("#blackBgLogin").fadeTo("normal",0.8);
	}
	
});




