areaHeight = 0;

function hideWho() {
	$('#g3-involved').css('display','none');
}
function stopVideo() {
	try {
		$('#player').get(0).sendEvent('STOP');
	} catch(err) { }
	$('#player-wrapper').hide();
	$('#g3-main-content-wrapper').animate({'height': areaHeight}, 500, function() {
		$('#g3-main-content-wrapper').css('height', null);
	});
}

// swfobject functions to hide video when stopped or finished
function stateTracker(obj) {
	if(obj.newstate == 'COMPLETED' || obj.newstate == 'PAUSED') {
		stopVideo();
	}
};

var player;

var flashvars = {
	config: '/webcast/includes/config.xml?v=3',
	file: 'http://progressive.harvest.org/crusades/2010/g3.flv',
	autostart: true
};
var params = {
	quality: 'high',
	wmode: 'opaque',
	allowscriptaccess: 'always',
	allowfullscreen: 'true'
};
var attributes = {};
swfobject.embedSWF('http://www.harvest.org/flash/jw_player-5.swf?v=500', 'player', '720', '419', '9.0.115', '/flash/expressInstall.swf', flashvars, params, attributes);

//Watch for state of video
function playerReady(obj) {
	var id = 'player';
	var version = obj['version'];
	var client = obj['client'];
	player = document.getElementById(id);
	player.addModelListener("STATE","stateTracker");
};

function playVideo() {
	areaHeight = $('#g3-main-content-wrapper').height() + 'px';
	$('#g3-main-content-wrapper').animate({'height': '419px'}, 300);
	$('#player-wrapper').fadeIn(500);
	try {
		$('#player').get(0).sendEvent('PLAY');
	} catch(err) { }
}

$(document).ready(function(){
	$('a#g3-video').bind('click', playVideo);
	$('a#video-close').bind('click', stopVideo);
	$('#g3-involved-button').bind('click', function() {
		$('#g3-involved-button').slideUp(100, function() {
			$('#g3-involved').slideDown(500);
		});
	});
	$('li#youth-leader-link a').bind('click', function() {
		$('#who li a').removeClass('active');
		$(this).addClass('active');
		$('.getting-involved:visible').slideUp(200, function() {
			$('#youth-leader-section').slideDown(500);
		});
	});
	$('li#student-link a').bind('click', function() {
		$('#who li a').removeClass('active');
		$(this).addClass('active');
		$('.getting-involved:visible').slideUp(200, function() {
			$('#student-section').slideDown(500);
		});
	});
	$('li#parent-link a').bind('click', function() {
		$('#who li a').removeClass('active');
		$(this).addClass('active');
		$('.getting-involved:visible').slideUp(200, function() {
			$('#parent-section').slideDown(500);
		});
	});
	setTimeout('hideWho()', 600);
});
