/*
 * Used to display the a youtube video on the NCC homepage
 * 
 * Also uses the swfobject.js javascript file
 * 
 * Matt Peters, 30th March 2011
 */

var videoID = "savyhxPuI8k";
var videoTimeout;

nccJQuery(function(){

	nccJQuery(".vidLink").click(function(){
		var currentWidth = nccJQuery("#youtubePreview").width() - 20;
		nccJQuery("#description").fadeOut('fast');
		nccJQuery(".ytThumbImg").animate({
			width: currentWidth + "px",
			height: "273px"
		}, 700, function(){
			nccJQuery("#youtubeVid").fadeIn();
			nccJQuery("#extVideoLink").slideDown();
			var params = {
				allowScriptAccess: "always",
				allowFullScreen: "true"
			};
			var atts = {
				id: "myytplayer"
			};
			swfobject.embedSWF("http://www.youtube.com/e/savyhxPuI8k?enablejsapi=1&playerapiid=ytplayer&rel=0", "vidReplace", currentWidth, "273", "8", null, null, params, atts);
			videoTimeout = setTimeout(function(){
				nccJQuery('#youtubeVid').hide();
				nccJQuery('#youtubeError').slideDown()
			}, 10000);
		});
		return false;
	});
});

function onYouTubePlayerReady(playerId) {
	clearTimeout(videoTimeout);
	ytplayer = document.getElementById("myytplayer");
	ytplayer.playVideo();
}
