﻿var ytPlayer = null;
var nextVideo = null;
var jqmHide = function(hash) {
	if (!ytPlayer) ytPlayer = document.getElementById("myytplayer");
	if (ytPlayer) {
	    ytPlayer.stopVideo();
	    ytPlayer.clearVideo();
	}
	nextVideo = null;
	hash.w.fadeOut(100,function(){ hash.o.remove(); });
};
jQuery(document).ready(function() {
    swfobject.embedSWF("http://gdata.youtube.com/apiplayer?key=AI39si69yCOZkQSOpnQvlKjPnY7a1olUzGXQjC2UPnbclxlrQqXeNPxhPzTUg-lj8QhzGVf6juYoTEdYm0enFAbqnVLFAHXswQ&enablejsapi=1&playerapiid=ytplayer", 
                             "viewer", "425", "349", "8", null, null, { allowScriptAccess: "always", bgcolor: "#cccccc" }, {id:"myytplayer"});
	jQuery('#right a.thumbnail').click(function(evt) {
        // queue and play movie
        //alert(jQuery(this).data("uid"));
        nextVideo = jQuery(this).data("uid");
		jQuery('.jqmWindow').jqm({onHide: jqmHide}).jqmShow();
		if (ytPlayer) ytPlayer.loadVideoById(nextVideo); // IE doesn't reload the player
//	    if (!ytPlayer) ytPlayer = document.getElementById("myytplayer");
//		if (ytPlayer) ytPlayer.loadVideoById(jQuery(this).data("uid"), 0);
        evt.preventDefault();
		return false;
	});
	jQuery('#right a.thumbnail').each(function() {
		jQuery(this).removeClass("thumbnail");
		jQuery(this).data('uid', this.className);
		this.href = "#";
	});
	// scrolling
	 jQuery('#scroll1 div.ytEntries').serialScroll({
        items:'.ytEntry',
        prev:'#scroll1 a.prev',
        next:'#scroll1 a.next',
        axis:'y',
        lock:false,
        cycle:false
    });
	 jQuery('#scroll2 div.ytEntries').serialScroll({
        items:'.ytEntry',
        prev:'#scroll2 a.prev',
        next:'#scroll2 a.next',
        axis:'y',
        lock:false,
        cycle:false
    });
	jQuery.noConflict();
	$ = function(id){return document.getElementById(id);};
});
function onYouTubePlayerReady(playerId) {
  ytPlayer = document.getElementById("myytplayer");
  if (ytPlayer && nextVideo) {
    ytPlayer.loadVideoById(nextVideo);
  }
}
