



/********************************************************

				  Search box functions

 ********************************************************/

	function focused(object) {
		if(object.value == "Search  ") {
			object.value = "";
			object.style.color = "#000";
		}
		
		return true;
	}
	
	function blurred(object) {
		if(object.value == "") {
			object.value = "Search  ";
			object.style.color = "#777";
		}
		
		return true;
	}
	


/********************************************************

					Front Page Timers

 ********************************************************/
	
	var promise        = 1;		// Current line of the IS Promise
	var photo          = 1;		// Current photo being viewed
	var numphotos      = 0;		// Number of photos
	var photoTimeout   = null;	// Photo timer
	var sponsor        = 1;		// Current sponsor
	var numsponsors    = 0;		// Number of sponsors
	var sponsorTimeout = null;	// Sponsor timer
	var moving         = false;	// Is the sponsor currently switching? If so, prevent moving around
	var loaded         = false;	// Prevent a weird bug from the Twitter thing that will
								// trigger the window load twice in Webkit
	
	
	// Load everything up
	function loadHome() {
		if(loaded) return;
		loaded = true;
		
		// Get the list of photos
		$("#photosList").children().each(function(){
			// ID and number them
			numphotos++;
			
			// Add the ID
			$(this).attr("id", "p"+numphotos);
			
			// Create the new selector
			var selected = "";
			if(numphotos == 1) selected = " class='selected'";
			$("#photoNav").append("<li id='pn"+numphotos+"' "+selected+"><a href='#' onclick='return setPhoto("+numphotos+");'>&bull;</a></li>");
		});
		
		
		// Get the list of sponsors
		$("#donorImages").children().each(function(){
			// ID and number them
			numsponsors++;
			
			// Add the ID
			$(this).attr("id", "s"+numsponsors);
		});
		
		// Do the same thing with the sponsor labels
		numsponsors = 0;
		$("#donorLabels ul").children().each(function(){
			numsponsors++;
			$(this).attr("id", "sn"+numsponsors);
		});
		
		// Start the timers
		setTimeout("promiseTimer()", 6000);
		if(numphotos   > 1) photoTimeout   = setTimeout("photoTimer()", 6000);
		if(numsponsors > 1) sponsorTimeout = setTimeout("sponsorTimer()", 4000);
	}
	
	// Promise line timer
	function promiseTimer() {
		$("#h"+promise).fadeOut();
		promise++;
		
		if(promise > 6) { promise = 1; }
		$("#h"+promise).fadeIn();
		setTimeout("promiseTimer()", 4000);
	}
	
	// Photos timer
	function photoTimer() {
		$("#p"+photo).fadeOut('slow');
		$("#pn"+photo).removeClass('selected');
		
		photo++;
		if(photo > numphotos) { photo = 1; }
		
		$("#pn"+photo).addClass('selected');
		$("#p"+photo).fadeIn('slow');
		
		photoTimeout = setTimeout("photoTimer()", 8000);
	}
	
	// Bypass the photo timer to skip to a photo
	function setPhoto(photoID) {
		if(photo == photoID) return false;
		
		window.clearTimeout(photoTimeout);
		
		$("#p"+photo).fadeOut('slow');
		$("#pn"+photo).removeClass('selected');
		
		photo = photoID;
		
		$("#pn"+photo).addClass('selected');
		$("#p"+photo).fadeIn('slow');
		
		photoTimeout = setTimeout("photoTimer()", 8000);
		
		return false;
	}
	
	
	
	
	// Sponsors Timer
	function sponsorTimer() {
		var originalSponsor = sponsor;	// Prevent overlap
		moving = true;
		$("#s"+originalSponsor).animate({"left": -259}, 1000, function(){ $("#s"+originalSponsor).hide(); });
		
		$("#sn"+originalSponsor).hide();
		
		sponsor++;
		if(sponsor > numsponsors) { sponsor = 1; }
		
		$("#s"+sponsor).css("left", 259);
		$("#sn"+sponsor).show();
		$("#s"+sponsor).show();
		$("#s"+sponsor).animate({"left": 0}, 1000, function(){ /*$("#s"+sponsor).animate({"left": 0}, 300); /* Extra bit of easing. */ moving = false; });
		
		sponsorTimeout = setTimeout("sponsorTimer()", 4000);
	}
	
	function sponsorGoLeft() {
		if(moving == true) return false;
		window.clearTimeout(sponsorTimeout);
		
		var originalSponsor = sponsor;	// Prevent overlap
		$("#s"+originalSponsor).animate({"left": 259}, 200, function(){ $("#s"+originalSponsor).hide(); });
		
		$("#sn"+originalSponsor).hide();
		
		sponsor--;
		if(sponsor < 1) { sponsor = numsponsors; }
		
		$("#s"+sponsor).css("left", -259);
		$("#sn"+sponsor).show();
		$("#s"+sponsor).show();
		$("#s"+sponsor).animate({"left": 0}, 200);
		
		sponsorTimeout = setTimeout("sponsorTimer()", 4000);
		
		return false;
	}
	
	function sponsorGoRight() {
		if(moving == true) return false;
		window.clearTimeout(sponsorTimeout);
		
		var originalSponsor = sponsor;	// Prevent overlap
		$("#s"+originalSponsor).animate({"left": -259}, 200, function(){ $("#s"+originalSponsor).hide(); });
		
		$("#sn"+originalSponsor).hide();
		
		sponsor--;
		if(sponsor < 1) { sponsor = numsponsors; }
		
		$("#s"+sponsor).css("left", 259);
		$("#sn"+sponsor).show();
		$("#s"+sponsor).show();
		$("#s"+sponsor).animate({"left": 0}, 200);
		
		sponsorTimeout = setTimeout("sponsorTimer()", 4000);
		
		return false;
	}
	
	
		
