	/* GLOBALS ========== */

// tweets
var tweet_advance_timeout = new Number(5000); // milliseconds before advancing to next tweet
var current_tweet_slide = new Number(-1); // starts at -1, goes to end of tweets, remembers last tweet
var next_tweet_slide = new Number(0); // starts at 0, goes to end of tweets, resets to zero
var tweet_slides = new Array(); // container for tweets
var t_tweets; // initialize timer for tweets

/* INITIALIZERS ========== */

$(document).ready(function() {
	// adds mouseover action to make YouTube UI visible
	if ( $('#media-player') && $('#media-player').hasClass('youtube') ) {
		$('#media-player').mouseenter(function(){
			$('#media-player').animate({height: 313}, 250);
		});
		$('#media-player').mouseleave(function(){
			$('#media-player').animate({height: 288}, 250);
		});
	}
	// adds animation to primary nav links
	$('a.primary-nav').each(function(){
		var my_parent = this.id.replace(/-link$/,'');
		if ( ! $('#' + my_parent).hasClass('current') ) {
			// "ON"
			$(this).mouseenter(function(){
				var my_id = this.id.replace(/-link$/,'-chrome');
				$('#' + my_id).stop();
				$('#' + my_id).animate({width: 52}, 100);
			});
			$(this).focus(function(){
				var my_id = this.id.replace(/-link$/,'-chrome');
				$('#' + my_id).stop();
				$('#' + my_id).animate({width: 52}, 100);
			});
			// OFF
			$(this).mouseleave(function(){
				var my_id = this.id.replace(/-link$/,'-chrome');
				$('#' + my_id).stop();
				$('#' + my_id).animate({width: 13}, 100);
			});
			$(this).blur(function(){
				var my_id = this.id.replace(/-link$/,'-chrome');
				$('#' + my_id).stop();
				$('#' + my_id).animate({width: 13}, 100);
			});
			// SELECT
			$(this).click(function(){
				var my_id = this.id.replace(/-link$/,'-chrome');
				$('#' + my_id).stop();
				$('#' + my_id).css({background: '#439539'});
				$('#' + my_id).animate({width: "100%"}, 100);
			});
		}
	});
	// adds mouseover and click behaviors to person photos
	$('a.person-portrait').each(function(){
		// "ON"
		$(this).mouseenter(function(){
			var my_id = this.id.replace(/-link$/,'-description');
			$('#' + my_id).show();
			// resets focus to prevent multiple items from showing
			//$('a.person-portrait').each(function(){this.blur();});
		});
		$(this).focus(function(){
			var my_id = this.id.replace(/-link$/,'-description');
			$('#' + my_id).show();
		});
		// "OFF"
		$(this).mouseleave(function(){
			var my_id = this.id.replace(/-link$/,'-description');
			$('#' + my_id).hide();
		});
		$(this).blur(function(){
			var my_id = this.id.replace(/-link$/,'-description');
			$('#' + my_id).hide();
		});
	});
	// tweets exist; start their presentation
	tweet_slides = $('li.tweet');
	if ( tweet_slides.length > 0 ) {
		// gather tweets
		tweet_slides.each(function(){
			$(this).fadeTo(0,0);
		});
		// start presentation
		advance_tweet_slide();
		// allows mouse to override tweet animations
		if ( $('#twitter-feed') ) {
			$('#twitter-feed').mouseenter(function(){
				clearTimeout(t_tweets);
			});
			$('#twitter-feed').mouseleave(function(){
				start_tweets_timer();
			});
		}
	}
	// add behaviors to presentations
	$('li.presentation').each(function(){
		var parent_id = this.id;
		// "ON"
		$(this).mouseenter(function(){
			$('li.presentation').each(function(){
				if ( this.id != parent_id ) {
					var my_id = this.id + '-chrome';
					$('#' + my_id).hide();
					var my_id = this.id + '-description';
					$('#' + my_id).hide();
				}
			});
			var my_id = this.id + '-chrome';
			$('#' + my_id).show();
			var my_id = this.id + '-description';
			$('#' + my_id).show();
		});
	});
});



/* FUNCTIONS ========== */

function advance_tweet_slide() {
	if ( current_tweet_slide >= 0 ) {
		// animate current slide out, ignore on first run
		$('#' + tweet_slides[current_tweet_slide].id).animate({top: "-100%", opacity: 0}, 300, function(){$('#' + this.id ).css({top: "100%"});});
	}
	$('#' + tweet_slides[next_tweet_slide].id).animate({top: 0, opacity: 1}, 300);
	current_tweet_slide = next_tweet_slide;
	next_tweet_slide++;
	if (next_tweet_slide >= tweet_slides.length) {
		next_tweet_slide = 0;
	}
	start_tweets_timer();
}
function start_tweets_timer() {
	t_tweets = setTimeout('advance_tweet_slide()', tweet_advance_timeout);
}
