// preload learnmore arrow images
var arrows = [];
arrows["reg"] = new Image();
arrows["reg"].src = "css/arrow_reg.gif";
arrows["hover"] = new Image();
arrows["hover"].src = "css/arrow_hover.gif";

$(document).ready(function() {
	if (typeof window.XMLHttpRequest == "undefined") {
		/* test for ie6, and add class to make up for lack of li:hover */
		$("#nav li").hover(
			function() {$(this).addClass("hover");},
			function() {$(this).removeClass("hover");}
		);
	}
	
	/* enhance drop-down menus - Removed behavior 18 April 2008
	$("#nav li ul").hide();
	
	$("#nav>li").hover(
		function() {$(this).children("ul").fadeIn("slow");},
		function() {$(this).children("ul").hide();}
	);
	*/
	
	/* login display */
	$("#login").css("top", "-65px");
	$("#logintab span").css({cursor: "pointer", textDecoration: "underline"}).click(function(){
		var $dad = $("#login");
		var n = $dad.css("top");
		if ( parseInt(n) < 0 ) {
			$dad.animate({top: 0}, "slow");
		} else {
			$dad.animate({top: "-65px"}, "slow");
		}
	});
	

	/* place labels inside input */
	$("#notmember, #member").css("marginTop", "8px");
	$("#signin li").each(function() {
		var $input = $(this).children("input"),
			$label = $(this).children("label");
		$label.css("display", "none");
		$input[0].value = $label.attr("for");
		$input.focus(function() {
			var $this = $(this),
				s = $this.parent().children("label").attr("for");
			if ($this.val() == s) {
				if (this.id == "password") {
					if (!document.all) {
						this.type = "password"
					} else { // stupid IE!
						$this.parent().html("<input name=\"password\" id=\"password\" type=\"password\" onblur=\"ie1()\" \/> <label for=\"password\" style=\"display:none;\"> Password: <\/label> <p id=\"forgotPassword\"> <a href=\"#\" title=\"Forgot your Password?\">Forgot your password?<\/a> <\/p>");
						$("input#password").focus().select();
					}
				}
				$this.val("");
			}
		});
		$input.blur(function() {
			var $this = $(this);
			if ($this.val() == "") {
				if (this.id == "password") {
					if (!document.all) {
						this.type = "text";
						$this.val($this.parent().children("label").attr("for"));
					} else {
						$this.parent().html("<input name=\"password\" id=\"password\" type=\"text\" \/> <label for=\"password\" style=\"display:none;\"> Password: <\/label> <p id=\"forgotPassword\"> <a href=\"#\" title=\"Forgot your Password?\">Forgot your password?<\/a> <\/p>");
					}
				} else {
					$this.val($this.parent().children("label").attr("for"));
				}

			}
		});
		
	});
	
	// swap arrows on roll-over for .learnmore links
	$(".learnmore a").each(function() {
		$(this).hover(
			function() {$(this).next("img").attr({src: arrows.hover.src});},
			function() {$(this).next("img").attr({src: arrows.reg.src});}
		)
	});
	
	$("#primary tbody tr:odd").addClass("odd");
});

// functions below are for the login inputs in IE, which won't let JS 
// change an input's type from text to password, and back again.
// Code could be cleaned up, there's a lot of repetition and unnecessary items.
function ie1() {
	if ($("input#password").val() == "") {
		$("input#password").parent().html("<input name=\"password\" id=\"password\" type=\"text\" value=\"password\" onfocus=\"ie2()\" \/> <label for=\"password\" style=\"display:none;\"> Password: <\/label> <p id=\"forgotPassword\"> <a href=\"#\" title=\"Forgot your Password?\">Forgot your password?<\/a> <\/p>");
	}
}
function ie2() {
	$("input#password").parent().html("<input name=\"password\" id=\"password\" type=\"password\" onblur=\"ie1()\" \/> <label for=\"password\" style=\"display:none;\"> Password: <\/label> <p id=\"forgotPassword\"> <a href=\"#\" title=\"Forgot your Password?\">Forgot your password?<\/a> <\/p>");
	$("input#password").focus().select();
}

