/*
** Watch The Shows
*/

if (typeof ourworld == "undefined") var ourworld = new Object();
if (typeof ourworld.shows == "undefined") ourworld.shows = new Object();

// _global.set_flv = function (file : String) { }
// _global.play_flv = function () { }
// _global.pause_flv = function () { }
// _global.stop_flv = function () { }
// _global.restart_flv = function () { }
// _global.rewind_flv = function () { }

ourworld.shows.set_small_flv = function (i) {
	console.log("ourworld.shows.set_small_flv()", i)
	
	ourworld.shows.id = i;

	$("#about-ep p").html(ourworld.shows.about[i]);
	document.getElementById("flash").set_flv(ourworld.shows.small_flvfile[i]);
}

ourworld.shows.show_large_flv = function () {
	var i = ourworld.shows.id;
	
	console.log("ourworld.shows.show_large_flv()", i)

	var $flash2_popup = $("body").createAppend("div", { "id": "flash2_popup" });
	var $flash2_close = $flash2_popup.createAppend("p", { "id": "flash2_close" });
	var $flash2 = $flash2_popup.createAppend("div", { "id": "flash2" });

	$flash2_close.createAppend("a", { "href": "#" }).html("[X]").bind("click", ourworld.shows.hide_large_flv);

	$flash2_popup.css("height", $(document).height());

	if (swfobject.hasFlashPlayerVersion("6.0.65")) {
		document.getElementById("flash").pause_flv();

		var expressInstall = "_swf/expressInstall.swf";
		var flashvars = { flvfile: ourworld.shows.large_flvfile[i], skinfile: "swf/watch/ClearOverAll.swf" };
		var params = { menu: "false", scale: "noscale", allowScriptAccess: "always" };
		var attributes =  { };
		
		swfobject.embedSWF("swf/watch/player-960.swf", "flash2", "980", "540", "9", expressInstall, flashvars, params, attributes);
	}
	
	$.scrollTo("#header", { duration: 250 });
}

ourworld.shows.hide_large_flv = function ()
{
	console.log("ourworld.shows.hide_large_flv()");
	
	$("#flash2_popup").remove();
	
	return false;
}

ourworld.shows.update_watch_links = function ()
{
	console.log("ourworld.shows.update_watch_links()", ourworld.shows.id);
	
	$("#episodes li").each(function (i) {
		var $a = $(this).children("a");
		var id = parseInt($(this).attr("id").slice(8), 10);
		var txt;

		if (id == ourworld.shows.id) {
			txt = "Now Playing"
		} else {
			txt = "Watch"
		}
		
		$a.attr("title", txt);
		$a.html(txt + "  &gt;");
	});
}

ourworld.init_watch = function () {
	console.log("ourworld.init_watch()");

	$("#episodes").jScrollPane({});

	$("#episodes li").each(function (i) {
		var $a = $(this).children("a");
		var id = parseInt($(this).attr("id").slice(8), 10);
		
		$a.bind("click", function () {
			if (id != ourworld.shows.id) {
				ourworld.shows.set_small_flv(id);
				ourworld.shows.update_watch_links();
			}
			return false;
		});
	});

	$("a#double").bind("click", function () {
		ourworld.shows.show_large_flv();
		return false;
	});

	if (swfobject.hasFlashPlayerVersion("6.0.65")) {
		var expressInstall = "_swf/expressInstall.swf";
		var flashvars = { flvfile: ourworld.shows.small_flvfile[ourworld.shows.id], skinfile: "swf/watch/ClearOverAll.swf" };
		var params = { menu: "false", wmode: "transparent", scale: "noscale", allowScriptAccess: "always" };
		var attributes =  { };
		
		swfobject.embedSWF("swf/watch/player-480.swf", "flash", "480", "270", "9", expressInstall, flashvars, params, attributes);
	}
}
