// JavaScript Document

$(function() {
	if( $("div.home").length > 0 ) {
		pageHeight = ($(window).height() - 389);
	} else {
		pageHeight = ($(window).height() - 295);
	}
	$("#main").css('min-height',pageHeight);
	$("#top-nav table a img").bind('mouseover',function(event) {
		ImgRollover(this);
	});
	$("#top-nav table a img").bind('mouseout',function(event) {
		ImgRestore(this);
	});
	$("table#dashboard-menu a img").not($("table#dashboard-menu a img.current")).bind('mouseover',function(event) {
		ImgRollover(this);
	});
	$("table#dashboard-menu a img").not($("table#dashboard-menu a img.current")).bind('mouseout',function(event) {
		ImgRestore(this);
	});
	$("#month-nav img").bind('mouseover',function(){
		ImgRollover(this);
	});
	$("#month-nav img").bind('mouseout',function(event){
		ImgRestore(this);
	});

	//search for any fields that should have "first" or "last"defaults
	CheckFirstLastEmail();
	//remove the defaults on focus
	$("input.fname").add($("input.lname")).add($("input.email")).focus( function() {
		ClearFirstLastEmail(this); 
	});
	//remove the defaults if submitting form
	$("input[type=submit]").click(function() {
		$("input.fname").add($("input.lname")).each(function() {
			ClearFirstLastEmail(this);
		});
	});
	$(".month-nav-container > div > div ").slice(0,6).hide();
	$("#month-nav img:first-child").click(function(){
		numHidden = $(".month-nav-container > div > div:hidden").size();
		$(".month-nav-container > div > div:hidden").eq(--numHidden).slideDown();
		$(".month-nav-container > div > div:visible").eq(2).css('margin-bottom','35px');
	});
	$(".month-nav-container > div > div:visible").eq(2).css('margin-bottom','35px');
	$("#month-nav img:last-child").click(function(){
		$(".month-nav-container > div > div:visible").eq(2).css('margin-bottom','5px');
		$(".month-nav-container > div > div:visible").eq(3).css('margin-bottom','35px');
		$(".month-nav-container > div > div:visible").eq(0).slideUp();
	});
});

function ImgRollover(img) {
	dotIndex = img.src.lastIndexOf(".");
	base = img.src.substring(0,dotIndex);
	ext = img.src.substring(dotIndex);
	img.src = base + "_over" + ext;
}

function ImgRestore(img) {
	over = img.src.indexOf("_");
	dotIndex = img.src.lastIndexOf(".");
	if( over > 1) {
		base = img.src.substring(0,over);
		ext = img.src.substring(dotIndex);
		img.src = base + ext;
	}
}

function CheckFirstLastEmail() {
	$("input.fname").each(function () {
		if( this.value == '' ) {
			this.value = 'First Name...';
			this.style.color = '#999999';
		}
	});
	$("input[name=last_name]").each(function () {
		if( this.value == '' ) {
			this.value = 'Last Name...';
			this.style.color = '#999999';
		}
	});
	$("input.email").each(function () {
		if( this.value == '' ) {
			this.value = 'Email Address...';
			this.style.color = '#999999';
		}
	});
}

function ClearFirstLastEmail(input) {
	input.style.color = 'black';
	if( ( input.value == 'First Name...' ) ||
		( input.value == 'Last Name...' ) ||
		( input.value == 'Email Address...' ) ){
		input.value = '';
	}
}
