var C4=C4||{};
C4.Controller=(function catchUpControllerInit(h){var q={PLAY:0,PAUSE:1,STOP:2,FULLSCREEN:3},J,A=false,g,o={assetId:null,guidanceText:"",episodeImageURL:""},l=C4.Util.hasAssetID(location.hash.substring(1)),y=(location.hash.substring(1,7)==="series"),T=false,D=false,P=false,R="catchUpPlayer",I="9.0.124",AD=null,AA=false,u="videoFinderResults",S=/chrome/.test(navigator.userAgent.toLowerCase()),m={mini:{width:256,height:144},normal:{width:512,height:288},large:{width:768,height:432},active:"normal"};
Events={playerLoadComplete:function(){A=true
},EpisodeTable:{onPlaybackStopped:function L(){if(!T){var AI=h("#catchUpEpisodes")[0];
if(AI.playingLabel!=null){AI.playingLabel.addClass("hide");
h(AI.playingLabel.playButton).removeClass("hide")
}AI.playingLabel=null
}},togglePlaying:function N(AJ){var AI=h("#catchUpEpisodes")[0];
Events.EpisodeTable.onPlaybackStopped();
AI.playingLabel=AJ.playingLabel;
AJ.playingLabel.removeClass("hide");
h(AJ).addClass("hide")
},loadEpisode:function(AJ){Views.setEpisodeHeaderInfo(this.catchUpData.assetId);
var AI=Events.EpisodeTable.doPinCheckForThisItem(h(this.parentRow),this.catchUpData);
if(AI){C4.Controller.externalPlayMovie(this)
}},doPinCheckForThisItem:function(AJ,AI,AL){var AK={};
AL=AL||false;
AK.rating=AJ.metadata().rating;
if(AK.rating){AK.assetId=AI.assetId;
AK.brandTitle=AI.brandTitle;
AK.episodeTxInfo=AI.episodeTxInfo;
AK.guidanceText=AI.guidanceText;
AK.popUpOptions=AL;
return C4.PinController.initialiseAccessControl(AK)
}else{return true
}},showPlayButtons:function r(){h(".playLink").removeClass("hide");
h(".episodeImageLongFormLink").removeClass("hide");
h(".popOut").removeClass("hide")
}},Player:{loaded:function d(){var AI=h("#catchUpPlayer")[0];
AI.setPlayerStateChangeCallback("C4.Controller.onPlayerStateChange");
Events.playerLoadComplete()
},stateChanged:function f(AI){AI=parseInt(AI);
switch(AI){case q.PLAY:Events.Player.onPlay();
break;
case q.PAUSE:Events.Player.onPause();
break;
case q.STOP:Events.Player.onStop();
break;
case q.FULLSCREEN:Events.Player.onFullScreen();
break
}},onPlay:function e(){var AI=h("#catchUpEpisodes")[0];
h(AI.playingLabel.playButton).addClass("hide");
AI.playingLabel.removeClass("hide");
Events.Player.scrollToPlayer()
},onPause:function z(){},onStop:function V(){var AI=h("#catchUpEpisodes")[0];
h(AI.playingLabel.playButton).removeClass("hide");
AI.playingLabel.addClass("hide")
},onFullScreen:function p(){},popOutPlayer:function b(AN){var AJ=h("#asset"+AN).find("a.popOut");
var AM=AJ.attr("href");
var AL,AK,AI;
var AO={url:AM,name:"window"+AN,height:350,width:((h.browser.msie&&h.browser.version<7)?508:512),resizable:0,scrollbars:"no"};
AL=AJ.parents(".episodeDetails").parent();
if(AL.metadata().rating){Events.EpisodeTable.doPinCheckForThisItem(AL,AL[0].playButton.catchUpData,AO)
}else{C4.Controller.externalSetPopup(AO)
}return false
},scrollToPlayer:function x(AI){if(!(h.browser.opera)){jQuery("html,body").animate({scrollTop:"245px"},1000,"linear",AI)
}else{window.scrollTo(0,245)
}}},PopoutWindow:{onWindowResize:function C(AI){AI.preventDefault();
if(AD){clearTimeout(AD)
}AD=setTimeout(Events.PopoutWindow.resizeFlashToWindow,100)
},resizeWindowToFixedRes:function AC(AI,AK,AJ){if(AI===m.mini.width&&AK===m.mini.height){m.active="mini"
}else{if(AI===m.normal.width&&AK===m.normal.height){m.active="normal"
}else{if(AI===m.large.width&&AK===m.large.height){m.active="large"
}}}h("#flashContainer").css("height","auto").css("width","auto");
var AL=AI;
if(h.browser.msie){if(h.browser.version<7){AL=AI+4
}else{AL=AI+10
}}else{if(h.browser.opera){AL=AI+9
}else{AL=AI+8
}}if(AJ){window.resizeTo(AL,AK)
}else{window.resizeTo(AL,(AK+Events.PopoutWindow.getOptimalWindowHeight(AK)))
}return false
},resizeFlashToWindow:function v(){var AI=Math.round(h(window).width());
var AJ=Math.round((AI/16)*9);
var AL=h("#catchUpPlayer")[0];
if(AL!=null&&AL.resizePlayer){AL.width=AI;
AL.height=AJ+22;
AL.resizePlayer(AI,AJ)
}h("#PrimaryContent").width(AI);
h("#flashContainer").width(AI);
h("#NCContentWrapper").width(AI);
h("#footerContainer").width(AI);
if(h.browser.msie&&h.browser.version<7){h("#linksContainer").css("left",AI-75)
}if(!(h.browser.msie)){try{window.innerHeight=parseInt(h("#PrimaryContent").height()+12)
}catch(AK){}}if(h(window).width()===screen.availWidth){window.moveTo(0,0);
Events.PopoutWindow.resizeWindowToFixedRes(screen.availWidth-100,screen.availHeight-500,true)
}},getOptimalWindowHeight:function E(AI){if(h.browser.msie){if(h.browser.msie&&h.browser.version>6){heightPadding=145
}else{heightPadding=115
}}else{if(S){heightPadding=127
}else{if(h.browser.safari){heightPadding=98
}else{if(h.browser.opera){heightPadding=112
}else{heightPadding=150
}}}}return heightPadding
}},SuggestiveSearch:{onResults:function G(AI){if(h.browser.msie&&!P&&AI.id=="c4navSearchTxt"&&h("#catchUpPlayer").css("height")!="1px"){h("#catchUpPlayer")[0].stallEpisode();
P=true;
Views.collapseFlash();
h("#catchUpPlayer").css("display","none");
h("#stallDisplay").css("display","block")
}},onFinishedSearching:function X(AI){if(h.browser.msie&&P&&AI.id=="c4navSearchTxt"){P=false;
Views.expandFlash();
h("#catchUpPlayer").css("display","block");
h("#catchUpPlayer")[0].unstallEpisode();
h("#stallDisplay").hide()
}}}},Views={fixEpisodeFormattedSynopsis:function O(){h(".episodesList li").each(function(){var AI=h(this).find("p.synopsis.formatted:last + a.episodeLink"),AJ=h(this).find("p.synopsis.formatted:last");
AI.appendTo(AJ)
})
},fixTitle:function a(){if(h.browser.msie){document.originalTitle=document.title;
function AI(){document.title=document.originalTitle
}window.attachEvent("onload",AI)
}},enhanceEpisodeTable:function B(){h("#catchUpEpisodes")[0].selectedRow=null;
h("#catchUpEpisodes .tabContent li").each(function(AM){var AN=h(".playLink",this)[0],AK=h(".guidance",this),AP=h(this),AL=AP.find(".broadcastDetails"),AQ=AL.find(".txDay").text()+" "+AL.find(".txDate").text()+" "+AL.find(".txTime").text().toLowerCase()+" "+AL.find(".channel").text(),AO=h("input[type=hidden]",this);
AN.catchUpData={assetId:AN.href.substr(AN.href.lastIndexOf("#")+1),guidanceText:AK.text(),episodeImageURL:h(AO).val(),brandTitle:h("h1").find("span").text(),episodeTxInfo:AQ};
h(AN).click(Events.EpisodeTable.loadEpisode);
AP.attr("id","asset"+AN.catchUpData.assetId);
this.playButton=AN;
AN.parentRow=this;
AN.playingLabel=h(".playingLabel",AN.parentNode);
AN.playingLabel.playButton=AN
});
Views.getSelectedAssetInfo();
var AJ=h("li.selected");
if(AJ.length>0){var AI=h("#catchUpEpisodes")[0];
AI.playingLabel=AJ[0].playButton.playingLabel
}},enhanceHighlightedEpisodeArea:function n(){h("#highlightedEpisodeInformation .episodeImageLongFormLink, #highlightedEpisodeInformation .playLink").click(function(){h("#asset"+h(this).attr("href").substring(1)).find("a.playLink").click()
});
h("#highlightedEpisodeInformation .popOut").click(function(AJ){var AI=h(this).attr("href");
assetId=AI.substring(AI.indexOf("player/")+7,AI.length);
h("#asset"+assetId).find("a.popOut").click();
return false
})
},getSelectedAssetInfo:function t(){var AJ,AN,AK,AI;
function AM(){AN=h("#catchUpEpisodes .tabContent:visible li:first-child");
AJ=parseInt(AN[0].id.replace("asset",""))
}if(T){var AL=h("#playerPlaceholder");
o={assetId:AL.metadata().preSelectAsset,guidanceText:AL.metadata().preSelectAssetGuidance,episodeImageURL:AL.metadata().preSelectAssetImageURL,isPopup:T,autorun:true}
}else{if(l){AJ=parseInt(location.hash.substring(1));
AN=h("#asset"+AJ);
if(AN.length){Views.setThisAssetsTabSelected(AN);
Views.setEpisodeHeaderInfo(AJ)
}else{AM()
}}else{AM()
}AK=h("input[type=hidden]",AN).val();
if(AN[0]){AN.addClass("selected");
o={assetId:AJ,guidanceText:AN[0].playButton.catchUpData.guidanceText,episodeImageURL:AN[0].playButton.catchUpData.episodeImageURL}
}}},setThisAssetsTabSelected:function M(AJ){var AI=AJ.parents(".tabContent").attr("id");
h("#catchUpEpisodes .tabNav a").each(function(){if(this.href.substring(this.href.indexOf("#")+1)==AI){h(this).click()
}})
},collapseFlash:function i(){h("#flashContainer").height(1);
h("#catchUpPlayer").height(1)
},expandFlash:function Z(){h("#flashContainer").height(374);
h("#catchUpPlayer").attr("height",374);
h("#catchUpPlayer").height(374)
},setEpisodeHeaderInfo:function s(AN){var AU=h("#asset"+AN).find(".broadcastDetails");
var AT=h("div#recentlyOn").find("li#asset"+AN).length>0;
var AI="";
if(AT){var AK=(h(AU).find("span.txTime").html()).toLowerCase();
var AQ=h(AU).find("span:nth-child(2)").html();
var AL=h(AU).find("span:nth-child(3)").html();
var AP=h(AU).find("span.channel").html();
AI="This episode: "+AQ+" "+AL+" "+AK+" on "+AP
}else{var AS=h.trim(h("li#asset"+AN).find("span.episodeNumber").html());
var AR=h.trim(h("li#asset"+AN).find("span.episodeTitle").html());
var AM=AS.substring(0,AS.indexOf("Episode"));
var AJ=AS.substring(AS.indexOf("Episode"));
if(AS.length===0){AI="This episode: "+AR
}else{AI=AM+" | "+AJ+" - "+AR
}}var AO=h("<h2 class='cb'>"+AI+"</h2>");
h("div#episodeHeader").find("h2").remove().end().append(AO)
},initialiseCatchUpPlayer:function AH(AM){var AN={align:"top",scale:"noscale",salign:"lt",allowFullScreen:"true",bgcolor:"#000000",allowScriptAccess:"always",wmode:(o.isPopup||AM.browser.msie)?"window":"opaque"},AJ={id:R},AI={brandTitle:encodeURIComponent(AM("#PrimaryContent").find("h1").text()),wsBrandTitle:AM("#PrimaryContent").find("h1").metadata().wsBrandTitle,primaryColor:AM.getCssFromClass("flashPrimaryColor","color",true),secondaryColor:AM.getCssFromClass("flashSecondaryColor","color",true),invertSkin:AM("body").hasClass("invert-skin"),preSelectAsset:o.assetId,preSelectAssetGuidance:encodeURIComponent(o.guidanceText),preSelectAssetImageURL:o.episodeImageURL,isPopup:o.isPopup,autorun:o.autorun,pinRequestCallback:"C4.PinController.doPinChecks"},AL=374,AK=625;
if(T){AK=512;
AL=310;
if(AM.browser.msie&&AM.browser.version<8){AM("#resizeButtons").css("margin-top","-26px")
}}if(!l&&!T){AL=1
}C4.PinController.setFlashPlayer(R);
swfobject.embedSWF(swfRoot+"asset/flash/swf/"+fourodPlayerFile,"playerPlaceholder",AK,AL,I,swfRoot+"asset/flash/swf/expressInstall.swf",AI,AN,AJ)
},setFlashEnabled:function c(){h("#playerPlaceholder").addClass("hidden").prepend('<div><p>For an enhanced view of this page <a href="http://get.adobe.com/flashplayer/">click here to install or upgrade Flash</a>.</p></div>');
if(swfobject.hasFlashPlayerVersion(I)){D=true;
h("#flashContainer").addClass("flashEnabled")
}else{h("#flashContainer").addClass("flashNotEnabled");
h("#playerPlaceholder").removeClass("hidden")
}},enhanceMainArea:function j(){if(D){if(l){h("#highlightedEpisodeInformation").hide();
Views.expandFlash()
}else{h("#flashContainer").addClass("hidden")
}}},isPopup:function AG(){return h("#playerPlaceholder").metadata().isPopup
},buildPopupLinks:function AF(AJ,AI,AK){h(AJ).click(function(AP){AP.preventDefault();
var AO,AN,AM,AL;
var AQ={url:this.href,name:"window"+this.href.substring(this.href.lastIndexOf("/")+1),height:AI,width:((h.browser.msie&&h.browser.version<7)?(AK-4):AK),resizable:0,scrollbars:"no"};
h("#catchUpPlayer")[0].pauseEpisode();
AO=h(this).parents(".episodeDetails").parent();
if(AO.metadata().rating){Events.EpisodeTable.doPinCheckForThisItem(AO,AO[0].playButton.catchUpData,AQ)
}else{C4.Controller.externalSetPopup(AQ)
}})
},setParentWindowLink:function Y(AI){h(AI).click(function(){var AJ="resizable=1,scrollbars=1,width="+(screen.width-30)+",height="+(screen.height-150)+",location=1,status=1,menubar=1,toolbar=1,left=0,top=0,screenX=0,screenY=0";
window.open(this.href,null,AJ);
return false
})
},selectSeriesTab:function Q(){var AI=location.hash.substring(1);
if(y){var AJ=parseInt(AI.substring(7));
h("a.tab").each(function(){var AK=h(this).attr("href");
var AL=C4.Util.getHashValue(AK);
if(AL.substring(0,6)==="series"&&AL.substring(6)==AJ){h(this).click()
}})
}},showPlayButtons:function r(){h(".playLink").removeClass("hide");
h(".episodeImageLongFormLink").removeClass("hide");
h(".standardLink.popOut").removeClass("hide")
},enhanceLongFormLinkIE:function k(){if(h.browser.msie&&h.browser.version==6){var AI=h("a.episodeImageLongFormLink").attr("href");
if(AI){h("#episodeImage").css("cursor","pointer");
h("#episodeImage").click(function(){h("a.episodeImageLongFormLink").click()
})
}}},enhancePlayButtonsIE:function K(){if(h.browser.msie&&h.browser.version<7){h(".playLink span.accessibility").removeClass("accessibility").addClass("positionFix")
}},getVideoFinderOptions:function W(){var AI={resultsId:u,overClass:"videoResultOver",loadingClass:"c4acLoading",cacheLength:50,mustMatch:false,formatMatch:null,matchContains:true,maxItemsToShow:"7",minChars:2,delay:0,width:280,inputWidth:264,showInPlace:true,omnitureCookie:"omn_intcmp=4oDpage_videofinder",omnitureProp8:"4oD",moreResultsMessage:'<p class="message-banner">THERE ARE MORE THAN 7 RESULTS - KEEP TYPING TO REFINE THE LIST</p>',noResultsMessage:'<p class="message no-results">NO VIDEO MATCHES </p>',formatItem:function(AX,AM,AO,AJ){var AP=AX.value.toLowerCase();
var AS=AP.indexOf(AJ,0);
var AT=AP.charAt(AS+AJ.length+1);
var AN=[AJ,"-"+AJ," "+AJ,AJ+" "],AR=AX.value.toLowerCase(),AQ=-1,AL=[],AM;
for(AM=0;
AM<AN.length;
AM++){var AU=AN[AM];
AQ=AR.indexOf(AN[AM]);
if(AM==0){if(AQ==0){break
}}else{if(AQ>-1){AQ++;
break
}}}var AK=AX.value.substr(0,AQ);
var AV=AX.value.substr(AQ,AJ.length);
var AW=AX.value.substr(AQ+AJ.length);
if(AV.indexOf(" ")!=-1){if(AV.charAt(0)===" "){AK+=" "
}if(AV.charAt(AV.length-1)===" "){AW=" "+AW
}AV=h.trim(AV)
}AL.push("<p>");
if(AQ>-1){AL.push(AK,"<em>",AV,"</em>",AW)
}else{AL.push(AX.value)
}AL.push("</p>");
return AL.join("")
}};
return AI
}};
return{init:function H(){C4.OO.insistRequired({object:h,names:["history","poshTabsLite","outerHtml","metadata","setadata","toJSON"]},{object:swfobject,names:["embedSWF"]},{object:C4.Brand.Views,names:["buildPocketsAndTabs","enhanceQuickLinks"]});
if(C4.Util.isMac()){I="10.0.0";
h("body").addClass("mac");
var AJ=window.devicePixelRatio;
if(AJ){h("body").addClass("saf")
}}Views.setFlashEnabled();
Views.enhanceMainArea();
T=Views.isPopup();
if(h("body#catchUp").length>0){C4.Brand.Views.addAutocompleteForm();
var AK=false;
C4searchAutocomplete("#videoFinderText",u,AK,Views.getVideoFinderOptions(),"/programmes/long-form-search/")
}C4.Brand.Views.buildPocketsAndTabs();
C4.Brand.Views.enhanceQuickLinks();
C4.Brand.Views.enhanceSponsorship();
C4.Brand.Views.enhanceBrandPageAds();
Views.buildPopupLinks("#catchUpEpisodes a.popOut",350,512);
if(T){Views.getSelectedAssetInfo();
Views.setParentWindowLink("#brandLink");
h(window).bind("resize",Events.PopoutWindow.onWindowResize);
h("#resizeMini").bind("click",function(){if(m.active!="mini"){Events.PopoutWindow.resizeWindowToFixedRes(256,144,false)
}});
h("#resizeNormal").bind("click",function(){if(m.active!="normal"){Events.PopoutWindow.resizeWindowToFixedRes(512,288,false)
}});
h("#resizeLarge").bind("click",function(){if(m.active!="large"){Events.PopoutWindow.resizeWindowToFixedRes(768,432,false)
}});
h("html").css("overflow-x","hidden");
h("html").css("overflow-y","hidden");
if(h.browser.opera){h("#linksContainer").css("top","0")
}h(function(){if(S||h.browser.mozilla||h.browser.opera||h.browser.safari){h("#flashContainer").css("height","auto").css("width","auto")
}})
}else{Views.enhanceEpisodeTable();
Views.fixEpisodeFormattedSynopsis();
Views.enhanceHighlightedEpisodeArea();
Views.enhancePlayButtonsIE()
}Views.fixTitle();
h(Views.initialiseCatchUpPlayer);
h("#footerContainer").show();
var AI=h('meta[name="brandTitle"]');
if(AI.length>0){J=AI.attr("content")
}Views.selectSeriesTab();
Views.enhanceLongFormLinkIE()
},onPlayerStateChange:function(AI){Events.Player.stateChanged(AI)
},openPopoutPlayer:function(AI){Events.Player.popOutPlayer(AI)
},setTitle:function(){document.originalTitle=document.title;
return document.originalTitle
},setFlashLoaded:function(){Events.Player.loaded();
Views.showPlayButtons()
},externalSetPopup:function U(AL){AL=AL||{};
var AJ="height="+AL.height+",width="+AL.width;
var AI=",resizable="+AL.resizable+",scrollbars="+AL.scrollbars;
var AK=window.open(AL.url,AL.name,AJ+AI);
if(AK&&window.focus){AK.focus();
return false
}else{if(typeof h("#catchUpPlayer")[0].handleBlockedPopUp==="function"){h("#catchUpPlayer")[0].handleBlockedPopUp(AL.url)
}}return false
},externalPlayMovie:function F(AI){if(h(AI).parents("#highlightedEpisodeInformation").length){AI=h("#asset"+h(AI).attr("href").substring(1)).find("a.playLink")[0]
}if(T){AI={};
AI.catchUpData=o
}h("#"+R)[0].loadEpisode(AI.catchUpData.assetId,AI.catchUpData.guidanceText);
if(!T){Views.expandFlash();
Events.EpisodeTable.togglePlaying(AI)
}if(!l){h("#highlightedEpisodeInformation").hide()
}},updatePositions:function AB(AO,AI){if(h("body#catchUp").length>0){var AN=AO.split(",");
AI=AI.replace("adstream_sx.ads","adstream_mjx.ads");
var AL="";
var AM="";
for(var AJ=0;
AJ<AN.length;
AJ++){AL=window.location.protocol+"//"+window.location.host+"/static/programmes/html/adverts/companionAdvert.htm?companionurl=";
AM=AI+"@"+AN[AJ];
AL+=AM;
var AK=document.getElementById("c4adFrame-"+AN[AJ]);
AK.src=AL
}return true
}},handleLoadedAd:function w(AI,AJ){h("#c4ad-"+AJ).show()
},_getOmnitureVars:function AE(){return"s_prop22="+c4props("vertical")+"|s_account="+s_account+"|mypage="+document.location.href
},_set$:function(AI){h=AI
},_setViews:function(AI){Views=AI
},_getViews:function(){return Views
},_setEvents:function(AI){Events=AI
},_getEvents:function(){return Events
},_fixTitle:function a(){if(h.browser.msie){document.title=document.originalTitle
}},_reset:(function(){var AI=h,AJ=Views,AK=Events;
return function(){h=AI;
Views=AJ;
Events=AK
}
})()}
})(jQuery);