function btvIsFavorite(A){return $("#btv-sidebar .btv-favorites .btv-launchpad a[href$="+A+"]").size()}var btvRecipeWindow;var btvPageWindow;function btvRecipe(A){btvRecipeWindow=window.open("pages/shows/"+A+"/index.shtml","btvRecipe","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=825,height=500")}function btvPage(A){btvPageWindow=window.open("pages/other/"+A+"/index.shtml","btvPage","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=825,height=500")}function btvVisit(A){window.location=A}function btvTitle(A){$.getJSON("json/VideoDetails/byVideoId/"+A,function(B){$(".btv-header span.btv-category").html(B.result.show_name);$(".btv-header span.btv-title").html(B.result.name)})}function btvNowPlaying(A){if(A){$("div.btv-related").html("Now Playing")}else{$("div.btv-related").html("Related Content")}}var tooltipTimeout;function showToolTip(A){var B="";if($(A.target).is("a[href*=#play]")){B="watch"}else{if($(A.target).is("a[href*=#add]")){B="add"}else{if($(A.target).is("a[href*=#remove]")){B="remove"}}}if(B){var C='<img src="images/layout/tooltip-'+B+'.gif" />';clearTimeout(tooltipTimeout);var D=$(A.target).offset();D.top-=27;D.left-=5;D.opacity=1;switch(B){case"watch":D.left-=97;break;case"add":D.left-=143;break;case"remove":D.left-=189;break}$("div#btv-tooltip").hide().stop().css(D).find("div.ct").html(C).end().fadeIn(300);tooltipTimeout=setTimeout(function(){$("div#btv-tooltip").fadeOut(600)},2000)}}function getVideoLaunchpads(A){var B;if(A.is(".btv-launchpad")){B=A}else{if(A.is("a")){B=A.parent().parent().parent()}else{if(A.not("body").size()==1){B=getVideoLaunchpads(A.parent())}}}return B}function getVideoId(A){var C;if(A.is(".btv-launchpad")){C=getVideoId(A.find("a.btv-play"))}else{if(A.is("a")){var B=new RegExp("^.*play-([a-zA-Z0-9]+)$");C=A.attr("href").replace(B,"$1")}else{if(A.not("body").size()==1){C=getVideoId(A.parent())}}}return C}function applyVideoStatus(B,A){$(".btv-launchpad.watching").removeClass("watching");switch(A){case"unwatched":B.addClass("unwatched");B.removeClass("watched");B.removeClass("watching");break;case"watched":B.removeClass("unwatched");B.addClass("watched");break;case"watching":B.removeClass("unwatched");B.addClass("watched");B.addClass("watching");break}}function setVideoStatus(B,A){switch(A){case"unwatched":case"watched":case"watching":applyVideoStatus(getVideoLaunchpads($(".btv-launchpad a[href$="+B+"]")),A);break}}function activeQueue(){if($(".btv-tab-favorites").hasClass("active")){return"favorites"}else{if($(".btv-tab-history").hasClass("active")){return"history"}else{return"foobar"}}}function showClear(A){switch(A){case"favorites":$("#btv-sidebar a.btv-clear").addClass("btv-clear-favorites").removeClass("btv-clear-history").show();break;case"history":$("#btv-sidebar a.btv-clear").addClass("btv-clear-history").removeClass("btv-clear-favorites").show();break}}function hideClear(){$("#btv-sidebar a.btv-clear").hide()}function videoPlayListener(A){if(getVideoLaunchpads($(A.target)).not(".watching").size()==1){btvLoad(getVideoId($(A.target)))}return false}function videoAddListener(B){var A=new RegExp("^.*add-([a-zA-Z0-9]+)$");btvAddFavorite($(B.target).attr("href").replace(A,"$1"));return false}function videoRemoveListener(B){var A=getVideoLaunchpads($(B.target));A.slideUp(300,function(){$(this).remove();saveMyFavorites()});return false}function initLaunchpads(A){$(A+".btv-launchpad").each(function(B){if($(this).parent().is(".btv-favorites")||btvIsFavorite(getVideoId($(this)))){$(this).addClass("isFavorite")}else{$(this).removeClass("isFavorite")}});$(A+".btv-launchpad").click(videoPlayListener);$(A+"a.btv-play").click(videoPlayListener);$(A+"a.btv-play").mouseover(showToolTip);$(A+"a.btv-add").click(videoAddListener);$(A+"a.btv-add").mouseover(showToolTip);$(A+"a.btv-remove").click(videoRemoveListener);$(A+"a.btv-remove").mouseover(showToolTip)}function loadFavorites(A){$("#btv-sidebar .btv-favorites").load("ajax/queue/"+A,{},function(B){if($("#btv-sidebar .btv-favorites").children().size()>0){showClear("favorites");initLaunchpads("#btv-sidebar .btv-favorites ");$("#btv-sidebar .btv-favorites .btv-launchpad").show()}else{hideClear()}})}function loadHistory(){$("#btv-sidebar .btv-history").load("ajax/queue/history",{},function(A){initLaunchpads("#btv-sidebar .btv-history ");$("#btv-sidebar .btv-history .btv-launchpad").show()})}var cookname="BTVCOOKIE";function getMyFavorites(){var A=[];$("#btv-sidebar .btv-favorites .btv-launchpad a[href*=#play]").each(function(C){var D=getVideoId($(this));var B=getVideoLaunchpads($(this)).hasClass("watched")?1:0;A.push(D+":"+B)});return A.join(",")}function saveMyFavorites(){var A=getMyFavorites();if(A.length>0){$.cookie(cookname+"FAV",A)}else{$.cookie(cookname+"FAV",null)}initLaunchpads("")}function restoreMyFavorites(){loadFavorites("favorites")}function getMyHistory(){var A=[];$("#btv-sidebar .btv-history .btv-launchpad a[href*=#play]").each(function(B){var C=getVideoId($(this));A.push(C+":1")});return A.join(",")}function saveMyHistory(){var A=getMyHistory();if(A.length>0){$.cookie(cookname+"HIST",A)}else{$.cookie(cookname+"HIST",null)}}function restoreMyHistory(){var A=$.cookie(cookname+"HIST");if(A&&A.length>=4){loadHistory()}}function sidebarTabListener(C){var B=new RegExp("^.*sidebar-([a-zA-Z0-9]+)$");var D=$(C.target).attr("href").replace(B,"$1");if(D!=activeQueue()){var A=(D=="history"?"favorites":"history");initLaunchpads("#btv-sidebar .btv-"+D+" ");$("#btv-sidebar .btv-"+A).slideUp(300,function(){$("#btv-sidebar .btv-"+D).slideDown(300);$("#btv-sidebar .btv-tab-"+D).addClass("active");$("#btv-sidebar .btv-tab-"+A).removeClass("active");if($("#btv-sidebar .btv-"+D).children().size()>0){showClear(D)}else{hideClear()}})}return false}function clearListener(B){var A=activeQueue();hideClear();$("#btv-sidebar .btv-"+A).fadeOut(500,function(){$(this).empty().show();if(A=="history"){saveMyHistory()}else{if(A=="favorites"){saveMyFavorites()}}});return false}var navLoadedOnce=false;function navLoad(A){$("#btv-nav .btv-videos").load("ajax/queue/"+A,{},navInit)}function navLoadListener(B){var A=new RegExp("^.*nav-([a-zA-Z0-9]+)$");navLoad($(B.target).attr("href").replace(A,"$1"));$("a.category").removeClass("active");$(B.target).addClass("active");return false}function navPageListener(B){var A=new RegExp("^.*page-([a-zA-Z0-9]+)-([0-9]+)$");navLoad($(B.target).attr("href").replace(A,"$1,$2"));return false}function enableNavLinks(){$("a.category").click(navLoadListener)}function navReveal(){$(this).next().show(200,navReveal)}function navInit(A){initLaunchpads("#btv-nav ");if(navLoadedOnce){$("#btv-nav .btv-videos .btv-launchpad:first").show(200,navReveal)}else{if(window.defaultQueue===undefined){$("a.category[href=#nav-featured]").addClass("active")}else{$("a.category[href=#nav-"+defaultQueue+"]").addClass("active")}$("#btv-nav .btv-videos .btv-launchpad").show();navLoadedOnce=true}if($("#btv-nav .btv-pagination").size()){$("#btv-nav .btv-pagination a.btv-page").click(navPageListener)}}function btvAddFavorite(A){if(!btvIsFavorite(A)){$.get("ajax/queue/"+A,function(B){$(B).hide().addClass("isFavorite").appendTo($("#btv-sidebar .btv-favorites")[0]).fadeIn(200);saveMyFavorites();if(activeQueue()=="favorites"){showClear("favorites")}})}}function btvAddHistory(C){var A=$("#btv-sidebar .btv-history .btv-launchpad a[href$="+C+"]").size();if(!A){$.get("ajax/queue/"+C,function(D){$(D).hide().prependTo($("#btv-sidebar .btv-history")[0]).slideDown(300);initLaunchpads("#btv-sidebar .btv-history ");setVideoStatus(C,"watching");saveMyHistory();if(activeQueue()=="history"){showClear("history")}})}else{var B=getVideoLaunchpads($("#btv-sidebar .btv-history .btv-launchpad a[href$="+C+"]"));B.slideUp(300,function(){setVideoStatus(C,"watching");$(this).hide().prependTo($("#btv-sidebar .btv-history")[0]).slideDown(300);saveMyHistory()})}}function btvLoad(B){btvAddHistory(B);saveMyFavorites();btvTitle(B);var A=swfobject.getObjectById("btv-vav");if(A){A.loadVAV(B)}var C=swfobject.getObjectById("btv-video");if(C){C.loadVideo(B)}}function btvNext(){if($("#btv-sidebar .btv-favorites .btv-launchpad").size()>0){var B=$("#btv-sidebar .btv-favorites .btv-launchpad.watching");var A=false;if(B.length===0){A=$("#btv-sidebar .btv-favorites .btv-launchpad:first")}else{if($("#btv-sidebar .btv-favorites .btv-launchpad").size()>1){if(B.is(":last-child")){A=$("#btv-sidebar .btv-favorites .btv-launchpad:first")}else{A=B.next()}}}if(A){btvLoad(getVideoId(A))}}}$(function(){$("#btv-sidebar a.btv-tab").click(sidebarTabListener);$("#btv-sidebar a.btv-clear").click(clearListener);$("#btv-nav .btv-categories .list").load("ajax/shows",{},enableNavLinks);if(window.defaultQueue===undefined){navLoad("featured")}else{navLoad(defaultQueue)}restoreMyFavorites();restoreMyHistory()});var videoSwfLoaded=false;var vavSwfLoaded=false;function btvInit(A){if(A=="video"){videoSwfLoaded=true}if(A=="vav"){vavSwfLoaded=true}if(videoSwfLoaded&&vavSwfLoaded){if(window.defaultVideoId===undefined){btvLoad(getVideoId($("#btv-sidebar .btv-favorites .btv-launchpad:first")))}else{btvLoad(defaultVideoId)}}return true};