$(document).ready(function() {
	$("table.events tr").click(function(){
		window.location = $(this).children("td.details").children("a")[0].href;
	});
	var clips = new Array();
	$("div#body table.clips div.clip").each(function(){
	  clips.push($(this).attr('id'));
	})
	var current = Math.floor(Math.random()*clips.length);
	$("div#body table.clips span#clip_count").html((current+1));
	var params = { allowScriptAccess: "always", bgcolor: "#FFF", wmode: "opaque" };
	var atts = { id: "myytplayer" };
	swfobject.embedSWF("http://www.youtube.com/v/" + clips[current] + "&amp;enablejsapi=1&amp;playerapiid=ytplayer&amp;rel=0&amp;egm=1&amp;showinfo=0&amp;fs=1", "ytapiplayer", "325", "190", "8", null, null, params, atts);
	$("div#body table.clips div#" + clips[current]).css('display', 'block');
	$("div#body table.clips a.reverse").click(function(){
		$("div#body table.clips div#" + clips[current]).css('display', 'none');
		current--;
		if (current < 0) current = (clips.length - 1);
		$("div#body table.clips span#clip_count").html((current+1));
		ytplayer.cueVideoById(clips[current]);
		$("div#body table.clips div#" + clips[current]).css('display', 'block');
	});
	$("div#body table.clips a.forward").click(function(){
		$("div#body table.clips div#" + clips[current]).css('display', 'none');
		current++;
		if (current == clips.length) current = 0;
		$("div#body table.clips span#clip_count").html((current+1));
		ytplayer.cueVideoById(clips[current]);
		$("div#body table.clips div#" + clips[current]).css('display', 'block');
	});
});
function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("myytplayer");
	setInterval(updateytplayerInfo, 250);
	updateytplayerInfo();
	ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
	ytplayer.addEventListener("onError", "onPlayerError");
}


