$(document).ready(function(){  

	$("p#assignments a").hover(function () {
		var highlight = $(this).attr("class");
		var windows= document.getElementById(highlight);
		$(windows).addClass("highlight");
	}, function () {
		$("#rendering span").removeClass("highlight");
	});

	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
	} else {

	// Give content page a min-height so the background fills all the way down the page
 	function setHeight(ele, h) {
		x = h;
		y = 319;
		z = x - y + "px";
		$("#pageContent").css({ 'min-height': z });
    } 
    
    setHeight("window", $(window).height()); 
    
    $(window).resize(function() {
		setHeight("window", $(window).height()); 
	});

	// Drop in the logo and animate footer down
	if(animateHeaderTitle){
		$('#headerTitle').animate({ top: '-25px' }, { duration: 3000, easing: 'easeOutElastic' });
		$("#footerContent").animate({ bottom: "-200px" }, 500 );
	} else {
		$('#headerTitle').css({ top: '-25px' });
    	$("#footerContent").css({ bottom: "-200px" }, 500 );
	}
    
    $('#backgroundTint').css({"display":"none"});
    
	// Slide in and out the donate panel
    $(".donate").click(
        function(){
        	$("div#moduleWrapper").find("div").each(function(i) {
			    if ($(this).css("height") === "300px") {
			    	$(this).animate({ "height": "0px" }, 500 );
			  	}
	 		});
	  		$('div#moduleWrapper h2 a').each(function(i) {
			    if ($(this).hasClass("active")) {
			    	$(this).removeClass('active');
			  	}
	 		});
	        if ($("#footerContent").css("bottom") == "0px") {
	                hideFooter();
	        } else {
		        $("#footerContent").animate({ bottom: "0px" }, 500 );
		        $('#backgroundTint').css({"display":"block"});
			    $('#backgroundTint').animate({"z-index":"450","opacity":".60"});
			    $('#close').css({"display":"block"});
	        }
        return false;
    });

    function hideFooter() {
        $("#footerContent").animate({ bottom: "-200px" }, 500 );
    	$('#backgroundTint').animate({"z-index":"0","opacity":"0"}, 500, function() {
	    		$('#backgroundTint').css({"display":"none"});
	    	});
    	$('#close').css({"display":"none"});
    	}
	}
	$("#close").click(hideFooter);

	// Suckerfish dropdown menu
    $("ul#headerNavigation").superfish({ 
        delay:       500, 
        animation:   {height:'show'},
        autoArrows:  false,
        dropShadows: false 
	}); 
	
	// Tool Tip - DONE
	if ($.browser.msie && $.browser.version.substr(0,1)<8) {
	} else {
		$(function(){
			$(".tip-b").tipTip({maxWidth: "auto", edgeOffset: -20});
			$(".tip-t").tipTip({maxWidth: "auto", defaultPosition: "top"});
		});

	// Homepage modules show/hide - DONE
    $('div#moduleWrapper h2 a').click(function() {
  		$("div#moduleWrapper").find("div").each(function(i) {
		    if ($(this).css("height") === "300px") {
		    	$(this).animate({ "height": "0px" }, 500 );
		  	}
 		});
  		$('div#moduleWrapper h2 a').each(function(i) {
		    if ($(this).hasClass("active")) {
		    	$(this).removeClass('active');
		  	}
 		});
		if ($(this).parent().next('div').css("height") == "0px") { //show
			$(this).addClass('active');
			$(this).parent().next('div').animate({ "height": "300px" }, 500 );
			$('#backgroundTint').css({"display":"block"});
			$('#backgroundTint').animate({"z-index":"450","opacity":".60"});
		} else { //hide
	        $(this).removeClass('active');
	        $(this).parent().next('div').animate({ "height": "0px" }, 500 );
	    	$('#backgroundTint').animate({"z-index":"0","opacity":"0"}, 500, function() {
	    		$('#backgroundTint').css({"display":"none"});
	    	});
		}
	});

	// Goal Chart Animation
	$('#goals a').click(function() {
		$('#moduleGoals ul').css({"height" : "0px"});
		$('#moduleGoals ul li').css({"height" : "0px"});
		$('#moduleGoals ul').animate({"height" : '125px'}, 100, function() {
			$('#p5').animate({ "height": "22px" }, 400 );
			$('#p10').animate({ "height": "22px" }, 400 );
			$('#p15').animate({ "height": "22px" }, 400 );
			$('#p20').animate({ "height": "22px" }, 400, function() {
				$('#p25').animate({ "height": "22px" }, 400 );
				$('#p30').animate({ "height": "22px" }, 400 );
				$('#p35').animate({ "height": "22px" }, 400 );
				$('#p40').animate({ "height": "22px" }, 400, function() {
					$('#p45').animate({ "height": "22px" }, 400 );
					$('#p50').animate({ "height": "22px" }, 400 );
					$('#p55').animate({ "height": "22px" }, 400 );
					$('#p60').animate({ "height": "22px" }, 400, function() {
						$('#p65').animate({ "height": "22px" }, 400 );
						$('#p70').animate({ "height": "22px" }, 400 );
						$('#p75').animate({ "height": "22px" }, 400 );
						$('#p80').animate({ "height": "22px" }, 400, function() {
							$('#p85').animate({ "height": "22px" }, 400 );
							$('#p90').animate({ "height": "22px" }, 400 );
							$('#p95').animate({ "height": "22px" }, 400 );
							$('#p100').animate({ "height": "22px" }, 400 );
						});
					});
				});
			});
		});
	});

/* PASTE THE 200 IN THIS LINE $('#p50')...

, function() {
	$('#p55').animate({ "height": "22px" }, 200, function() {
		$('#p60').animate({ "height": "22px" }, 200 );
	});
}

END PASTE */

} //end if statement

	//clear input field	
	(function($){
	$.fn.clearDefault = function(){
		return this.each(function(){
			var default_value = $(this).val();
			$(this).focus(function(){
				if ($(this).val() == default_value) $(this).val("");
			});
			$(this).blur(function(){
				if ($(this).val() == "") $(this).val(default_value);
			});
		});
	};
	})(jQuery);

	$('input#keywords').clearDefault();
	$('input#amt').clearDefault();
	
	randomtip();
	
	
}); //end doc ready
	
this.randomtip = function(){
	var length = $(".quickfact").length;
	var ran = Math.floor(Math.random()*length) + 1;
	$(".quickfact:nth-child(" + ran + ")").show();
};

function validate_form() {
	valid = true;
	if ( document.donateform.amt.value == "Enter an amount..." && document.donateform.windows.selectedIndex == 0 ) {
		alert ("Please select a window donation or enter an amount.");
		valid = false;
	} else if ( document.donateform.amt.value != "Enter an amount..." && document.donateform.windows.selectedIndex != 0 ) {
		alert ("Please only make a window donation" + '\n' + "selection OR enter an amount.");
		valid = false;
	}
	return valid;
	}
