/**
 * JavaScript file which causes the three words in the Providge
 * slogan to slowly fade into view upon page load.
 *
 * Requires
 *  - prototype.js >= 1.6.0
 *  - effects.js >= 1.8.1 (from scriptaculous library)
 */
 
var fnAnimateLinks = function() {

	var fnHideLinks = function() {
		// First, hide all of the links
		$$('#slogan a').each(
			function(oAnchor, iIdx) {
				if (Prototype.Browser.WebKit) {
					// The following line works around a clipping bug in Safari
					oAnchor.style.paddingTop = 	oAnchor.getHeight() + 'px';
				}
				oAnchor.hide();
			}
		);
	}
	
	fnHideLinks();
	
	// Define a function that will slowly fade in a
	// given link and recursively call the animation
	// on the next link in the sequence, if any.
	var fnAnimateLink = function(oAnchor) {
		if (!oAnchor) {
			window.setTimeout(function() {
				var aEffects = [];
				var iIndex = 0;
				var oReverseAnchor;
				
				oReverseAnchor = $('slogan').down('a');
				while (oReverseAnchor)
				{
					aEffects[iIndex] = new Effect.Fade(
						oReverseAnchor, {
						sync: true
					});
					oReverseAnchor = oReverseAnchor.next('a');
					iIndex++;
				}
				
				new Effect.Parallel(
					aEffects, {
						duration: 1.5,
						afterFinish: function() {
							fnAnimateLink($('slogan').down('a'));
						}
					}
				);
				
			}, 10000);
			return;
		}
		oAnchor.appear({
			duration: 1.5,
			afterFinish: function() {
				fnAnimateLink(this.next('a'));
			}.bind(oAnchor)
		});
	};
	
	// Start the recursive descent
	fnAnimateLink($('slogan').down('a'));
};

// Run the link animator when the DOM is loaded
FastInit.addOnLoad(fnAnimateLinks);