var C4=C4||{};
C4.Catchup=C4.Catchup||{};
C4.Catchup.Model=(function(A){return{bgLink:null}
})(jQuery);
C4.Catchup.View=(function(F){var C=C4.Catchup.Model;
var A={generateMy4odButtons:function B(){C4.ButtonManager.Controller.addButtons(C4.My4oD.Model.PLAYLIST,C4.ButtonManager.Model.ADD_BTN,".highlights-module .promo");
C4.ButtonManager.Controller.addButtons(C4.My4oD.Model.PLAYLIST,C4.ButtonManager.Model.ADD_BTN,"#allCatchupDays .promo",true,"#allCatchupDays .promo-link")
},filterPrimeTime:function G(O){var P=F(".promo.allday");
Helper.eraseCookie("TIMERANGECOOKIE");
if(O==="primetime"){P.addClass("hidden");
Helper.createCookie("TIMERANGECOOKIE",O,7)
}else{P.removeClass("hidden")
}A.addUnavailableMessages()
},setMPUHeight:function D(){var O=F("#allCatchupDays > .module"),P=O.filter(":first").find(".promo").not(".hidden"),Q=P.filter(":eq(0)").outerHeight(true)+P.filter(":eq(4)").outerHeight(true);
F(".secondary-content").height(Q)
},removeUnavailableMessages:function I(){F("#allCatchupDays > .module .unavailable").remove()
},addUnavailableMessages:function M(){A.removeUnavailableMessages();
F("#allCatchupDays > .module").each(function(){if(F(this).find(".promo").not(".hidden").length===0){F(this).find(".promo-container").append("<li class='unavailable'>No items available</li>")
}})
},setUpAds:function E(){var O=[{advertSelector:"#c4ad-BottomLeft",targetSelector:".main-content"},{advertSelector:"#c4ad-BottomRight",targetSelector:".main-content"}];
C4.AdManager.insertAds(O);
C4.AdManager.clearEmptyAd("#c4ad-Middle1",C4.Util.removeClearing,"#allCatchupDays > .module:nth-child(3) .promo");
var P=[{advertSelector:"#c4ad-TopRight",targetSelector:".secondary-content .module",insertBefore:false,callbackFunc:A.styleMPUs}];
C4.AdManager.insertAds(P);
C4.AdManager.clearEmptyAd("#c4ad-TopRight",C4.Util.removeClearing,"#allCatchupDays > .module .promo")
},styleMPUs:function H(){if(C4.AdManager.advertExists("#c4ad-TopRight")){F("#c4ad-TopRight").prepend("<h2>Advertisement</h2>")
}},applyClearing:function N(O){if(!(F.browser.msie&&F.browser.version<8)){if(O){C4.Util.applyClearing("#allCatchupDays > .module",4,6,2);
C4.Util.applyClearing("#allCatchupDays > .module:nth-child(3)",4,6,2)
}else{if(C4.AdManager.advertExists("#c4ad-Middle1")){C4.Util.applyClearing("#allCatchupDays > .module:nth-child(3)",4,6,2)
}if(C4.AdManager.advertExists("#c4ad-TopRight")){C4.Util.applyClearing("#allCatchupDays > .module",4,6,2)
}}}},primeTimeSwitch:function K(O,P){C4.Util.removeClearing("#allCatchupDays > .module .promo");
A.filterPrimeTime(O);
A.applyClearing(P)
},moveFirstSixPromosIE7:function L(){F(function(){if(F.browser.msie&&F.browser.version<8){var P=null,Q;
F(".main-content .promo-container").each(function(S){if(S===0){P=F(this)
}if(S===1){Q=F(this)
}});
if(P!==null&&P.find(".promo").length>8&&C4.AdManager.advertExists("#c4ad-TopRight")){var O=F('<ul class="promo-container cf"></ul>');
O.insertBefore(P);
P.find(".promo").each(function(S){if(S<8){F(this).appendTo(O)
}});
F(".main-content .promo-container").each(function(S){if(S===1){F(this).width(960);
F(this).css("border-bottom","1px dotted #999");
F(this).parent().css("border-bottom","0 none")
}})
}if(Q!==null&&Q.find(".promo").length>8&&C4.AdManager.advertExists("#c4ad-Middle1")){var R=F('<ul class="promo-container cf"></ul>');
R.insertBefore(Q);
Q.find(".promo").each(function(S){if(S<8){F(this).appendTo(R)
}});
F(".main-content .promo-container").each(function(S){if(S===3){F(this).width(960);
F(this).css("border-bottom","1px dotted #999");
F(this).parent().css("border-bottom","0 none")
}})
}}})
}};
return{getView:function J(){return A
}}
})(jQuery);
C4.Catchup.Controller=(function(F){var A=C4.Catchup.View.getView(),C=C4.Catchup.Model;
Event={bind:function I(){F(".dropdown").dropdown({height:200,openerSelector:".title",dropdownSelector:"ul"});
F("#catchUpFilter input").click(function(N){var M=N.target.value;
A.primeTimeSwitch(M,false)
});
C4.Util.HashManager.addHandler("openPanel",C4.Util.openPanel);
C4.Util.HashManager.init();
if(C.bgLink){F(window).resize(C4.Brand.Views.resizeBgLink)
}},my4odCallback:function E(){A.generateMy4odButtons();
F(".highlights-module .promo-container").promoHover({showFullyOpened:false});
F("#allCatchupDays .promo-container").promoHover({showFullyOpened:true});
F(window).hashchange();
C4.Brand.Views.resizeInSkin();
if(C.bgLink){C4.Brand.Views.resizeBgLink()
}}};
Helper={initPrimetimeSwitch:function J(){var M=Helper.readCookie("TIMERANGECOOKIE");
if(M===null){M=F("#catchUpFilter input:checked").val()
}else{F("#radio-"+M).attr("checked","checked")
}A.primeTimeSwitch(M,true)
},createCookie:function G(O,P,Q){if(Q){var N=new Date();
N.setTime(N.getTime()+(Q*24*60*60*1000));
var M="; expires="+N.toGMTString()
}else{var M=""
}document.cookie=O+"="+P+M+"; path=/"
},readCookie:function H(N){var P=N+"=";
var M=document.cookie.split(";");
for(var O=0;
O<M.length;
O++){var Q=M[O];
while(Q.charAt(0)==" "){Q=Q.substring(1,Q.length)
}if(Q.indexOf(P)==0){return Q.substring(P.length,Q.length)
}}return null
},eraseCookie:function K(M){Helper.createCookie(M,"",-1)
},my4odInit:function D(){var M={logInStateChanged:true,callbackFunc:C4.Catchup.Controller.my4odCallback};
C4.My4oD.Controller.init(M)
},populateModel:function B(){if(F("body").attr("data-bgurl")){C.bgLink=F("body").attr("data-bgurl")
}}};
return{init:function L(){Helper.populateModel();
A.moveFirstSixPromosIE7();
Helper.initPrimetimeSwitch();
C4.Brand.Views.setBGLink(C.bgLink);
Event.bind();
C4.Brand.Views.createIntCmpLinks(".hero-frame .promo a","intcmp=catchupcarousel");
C4.PinController.View.updatePinStatus();
C4.Brand.Views.createSearchAutocomplete();
A.setUpAds()
},my4odCallback:Event.my4odCallback,my4odInit:Helper.my4odInit}
})(jQuery);
