$(document).ready(function(){
	
	// Home Feature Box (Sorry, this is totally experimental)
	$("#features li").each(function(i) {
		i = (i+1);
		$(".f" + i).click(function() {
			window.location.href = 	($(".f" + i + " a").attr("href"));			
		}).hover(
			function() {
				$(this).css("cursor", "pointer");
			},
			function() {
				$(this).css("cursor", "default");
			}
		);
	});
	
	
	// What News
	var limited_text1 = $(".article1").text().substring(0, 250);
	var limited_text2 = $(".article2").text().substring(0, 250);
		
	$(".article1").replaceWith("<p>" + limited_text1 + "...</p>");
	$(".article2").replaceWith("<p>" + limited_text2 + "...</p>");
	
	
	// Top login form
	var text_username = "Username";
	var text_password = "Password";
	var text_account = "AccountID";
	
	$("#loginform input[name='username']").val(text_username);
	$("#loginform input[name='account']").val(text_account);
	
	$("#loginform input[name='password']").css("display", "none").after('<input type="text" name="passtext" value="Password" size="25" />');
	$("#loginform input[type='text']").css("color", "#999");
	
	$("#loginform input[name='username']").focus(function() {
		$(this).css("color", "#171717");
		if( $(this).val() == text_username ) {
			$(this).val("");
		}
	});
	
	$("#loginform input[name='account']").focus(function() {
		$(this).css("color", "#171717");
		if( $(this).val() == text_account ) {
			$(this).val("");
		}
	});
	
	swap_password_field ();
	
	$("#loginform input[name='username']").blur(function() {
		if ($(this).val() == "") {
			$(this).val(text_username).css("color", "#999");	
		}
	});
	
	$("#loginform input[name='account']").blur(function() {
		if ($(this).val() == "") {
			$(this).val(text_account).css("color", "#999");	
		}
	});
	
	$("#loginform input[name='password']").blur(function() {
		if ($(this).val() == "") {
			$(this).css("display", "none").after('<input type="text" name="passtext" value="Password" />');
			$("#loginform input[name='passtext']").css("color", "#999");
			
			swap_password_field ();
			
		}	
	});
	
	
	
	$("#loginform").submit(function() {
		if ( $("#loginform input[name='username']").val() == text_username ) {
			$("#loginform input[name='username']").val("");	
		}
		if ( $("#loginform input[name='account']").val() == text_account ) {
			$("#loginform input[name='account']").val("");	
		}
	});
});

function swap_password_field () {
	$("#loginform input[name='passtext']").focus(function() {
		$(this).remove();												  
		$("#loginform input[name='password']").css("display", "inline").focus();
	});
}