var C4=C4||{};
C4.Brand=(function(H){return{Views:{buildPocketsAndTabs:function B(){H(".pocket").each(function(){var N=H(this).attr("id")=="moreShowInfo"?false:true;
var O=H(this).hasClass("vertical")?true:false;
H(this).poshTabsLite(N,O)
})
},enhanceSponsorship:function(){H(function(){if(H("#c4ad-Top1 a").length>0){H("#c4ad-Top1 a").appendTo(H("#PrimaryContent")).wrapAll('<div id="sponsorship"></div>')
}})
},enhanceDropDownNavigation:function G(){C4.Brand.Views.enhanceDropDownNavigationInitial();
H("body").click(function(){H("ul.jumpLinks li.dropdown ul").removeClass("jumpLinksOpen")
});
H("ul.jumpLinks li.dropdown").each(function(){if(H(this).hasClass("episodes")){var P,O,N=20;
O=H(this).find("a:first");
P=jQuery.trim(O.text());
if(P.length>N){P=P.substring(0,N);
O.text(P+"\u2026")
}}H(this).find("a:first").click(function(Q){Q.stopPropagation();
H(this).parents("li:first").children("ul:first").toggleClass("jumpLinksOpen");
return false
}).keypress(function(Q){Q.stopPropagation();
H(this).parents("li:first").children("ul:first").toggleClass("jumpLinksOpen").find("li:first a").focus();
return false
});
H(this).find("ul a:last").blur(function(Q){Q.stopPropagation();
H(this).parents("ul:first").removeClass("jumpLinksOpen");
return false
})
})
},enhanceBrandPageAds:function(){H(function(){H("#SecondaryContent .promo-slot").each(function(){var N=H(this);
if(N.find("img[src*='empty.gif']").length===0){N.css("margin-bottom","10px")
}else{N.hide()
}});
if(H("body#catchUp").length===0){H("#c4ad-BottomLeft").find("script").remove();
H("#c4ad-BottomRight").find("script").remove();
if(H("#c4ad-BottomLeft").find("script").length===0&&H("#c4ad-BottomRight").find("script").length===0){H("#c4ad-BottomRight").prependTo("#c4footer").addClass("promo-slot");
H("#c4ad-BottomLeft").prependTo("#c4footer").addClass("promo-slot").css("margin-right","26px")
}H("img[width=1]").hide()
}})
},enhanceDropDownNavigationInitial:function D(){H(".jumpLinks li.dropdown ul").each(function(){H(this).addClass("jumpLinksClosed");
if(H(this).height()>300){H(this).height(300)
}});
if(H.browser.msie&&jQuery.browser.version<7){C4.Brand.Views.fixDropDownPositionIE6()
}},fixDropDownPositionIE6:function K(){H(".jumpLinks li.dropdown").each(function(){var O=H(this);
var N=O.find("ul");
N.css({top:O.height()});
if(H.browser.msie&&H.browser.version==6){N.css("left","5px");
if(H("body").attr("id")=="catchUp"){N.css("width",parseInt(O.width()-7))
}else{N.css("width",O.width()-2)
}O.css("padding-left","5px")
}})
},enhanceLongFormLinkIE:function C(){if(H.browser.msie&&H.browser.version==6){var N=H("a.episodeImageLongFormLink").attr("href");
if(N){H("#episodeImage").css("cursor","pointer");
H("#episodeImage").click(function(){window.location=N
})
}}},enhanceQuickLinks:function M(){H("#QuickLinks li").each(function(){var P=H(this),N=P.text().toLowerCase(),O=(/series/.test(N))?"107px":(/articles/.test(N))?"104px":"102px";
P.css("width",O);
if(P.is(":last-child")){P.css("width","104px")
}})
},enhanceJumpPointLinks:function I(){H("ul.jumpPoints").each(function(){var N=H(this).find("li.catchUp").length>0;
var O=H(this).find("li").length>1;
if(O){if(N){H(this).find("li.catchUp").prev().find("a").css("margin-right","0")
}else{H(this).find("li:last-child a").css("margin-right","0");
H(this).css("padding-top","0")
}}else{H(this).find("li a").css("margin-right","0").css("margin-left","0");
if(!N){H(this).css("padding-top","0")
}}})
},enhanceEpisodeLinks:function L(N){H("li.noImage").each(function(){var P=H(this);
var O=P.find("a.arrowLink span.title").text();
var Q=C4.Util.getTextWidth(O);
if(Q<160){Q=parseInt(Q+parseInt(160-Q))
}if(Q>N){Q=300
}P.find("h3").width(Q);
P.find("a.arrowLink").each(function(){if(!(H(this).hasClass("more"))&&!(H(this).hasClass("longFormLink"))){H(this).width(Q)
}});
if(P.find(".last-shown").length>0){P.css("padding-top","20px");
P.find(".last-shown").css("top","-4px")
}else{if(P.find(".next-time").length>0){P.css("padding-top","20px");
P.find(".next-time").css("top","-4px")
}}if(P.find(".longFormLink").length===0){P.find("ul.jumpPoints").css("padding-top","0")
}})
},addAutocompleteForm:function A(){H("#videoFinderResultsContainer").before('<input type="text" value="Enter a programme name" id="videoFinderText" />');
H("#videoFinderResults").html("<p class='message'>TYPE IN THE SPACE ABOVE<br />TO FIND ALL PROGRAMMES AVAILABLE ON 4oD</p>").find(".message").click(function(){H("#videoFinderText").focus()
})
},enhanceRelatedLinksList:function E(){},enhanceComments:function F(){H("#comments #listComments ol li").css("padding","11px 0 0 0").css("margin-top","0");
H("#postCommentForm form#commentForm h4").css("display","none");
H("div.commentsClosedBody").css("display","none");
if(H("div#postCommentThanks").is(":visible")){H("div#postCommentThanks").css("margin-top","0").css("padding-bottom","10px").css("margin","10px 0")
}if(H("#listComments ol li").length==0){H("#listComments").remove()
}if(H("div#commentsClosed").not(":hidden")){H("div#commentsClosed").css("margin-bottom","0")
}H("#comments div.formrow").each(function(){$this=H(this);
if(H.trim(H(":first-child",$this).text())=="Post your comment"){H(":first-child",this).text("Post Your Comment")
}if(H.trim($this.text()).substring(0,10)=="By posting"){$this.find("br").remove()
}if($this.find("label[for=email]").length>0){$this.css("margin-top","0")
}if($this.find("label[for=userid]").length>0){$this.find("label[for=userid]").text("Display Name:*")
}if($this.find("label[for=email]").length>0){$this.find("label[for=email]").text("Email Address:*")
}if($this.find("strong").length>0&&$this.find("strong").text()=="Your Comment"){$this.html("<strong>Your Comment:*</strong><span>(max characters 4000)</span>");
$this.find("span").css("font-size","0.85em").css("margin-left","13px")
}if($this.find("label#trackbackLabel").length>0){$this.find("label#trackbackLabel").html("<strong>Your website address:</strong><br/><span>(optional)</span>");
$this.find("span").css("font-size","0.85em")
}});
H("label#anonymousLabel").remove();
H("input#anonymous").remove();
H("div#anonymousError").remove();
H("<input type='hidden' name='anonymous' value='n'/>").appendTo(H("div#commentError").parent());
H("#comments div.postCommentButtons input#postCommentSubmit").attr("value","Post Your Comment");
H("#postCommentThanks div.postCommentBody").find("div.clear").remove();
H("#postCommentThanks div.postCommentBody p:first-child").css("font-weight","bold");
H("#listComments h4").remove();
H("#listComments ol li").each(function(){$this=H(this);
$this.addClass("polka");
var R="",O="",Q="",P="";
$this.find("div.line").each(function(){$line=H(this);
var V=$line.text().replace(/Posted by/,"");
if($line.html().substring(0,9)=="Posted by"){var U=(V.substring(0,V.length-23)).toUpperCase();
U=(H.trim(U).length==0)?"ANONYMOUS":U;
if($line.find("a[target=_blank]").length>0){var S=$line.find("a[target=_blank]").attr("href");
R="<span class='username'><a href='"+S+"' target='_blank'>"+U+"</a> on&nbsp;</span>"
}else{R="<span class='username'>"+U+" on&nbsp;</span>"
}Q=V.substring(V.length-19,V.length-8);
var W=Q.split("/");
var T=W[0];
W[0]=W[1];
W[1]=T;
Q=W.join("/");
Q=(new Date(Q)).toLocaleDateString();
P=V.substring(V.length-8,V.length-3);
$line.remove()
}else{if($line.html().substring(0,10)=="Offensive?"){$line.html($line.html().substring(22))
}else{$line.html("<span id='openQuote'>&nbsp;&nbsp;&nbsp;</span>"+$line.html()+"<span id='closeQuote'>&nbsp;&nbsp;&nbsp;</span>")
}}$line.find("a").each(function(){if(H(this).text()=="Report this comment"){H(this).text("").append("<span>REPORT</span>").addClass("arrowLink")
}H(this).parent().html("<div class='linkContainer'>"+H(this).parent().html()+"</div")
});
$line.addClass("cf")
});
$this.find("div.odd, div.even").prepend("<div class='line'>"+R+"<span class='commentDate'>"+Q+" at&nbsp;</span><span class='commentTime'>"+P+"</span></div>")
});
H("#CommentsContainer h2.subHeader").text("COMMENTS ("+parseInt(H("#comments div.even").length+H("#comments div.odd").length)+")");
function N(){H("div.errorMessage").each(function(){$this=H(this);
if(H.trim($this.text())!=""){if($this.attr("id")=="usernameError"){H("input#userid").css("border-color","#CC0000")
}else{if($this.attr("id")=="emailError"){H("input#email").css("border-color","#CC0000")
}else{if($this.attr("id")=="commentError"){H("textarea#comment").css("border-color","#CC0000")
}}}}else{if($this.attr("id")=="usernameError"){H("input#userid").css("border-color","black")
}else{if($this.attr("id")=="emailError"){H("input#email").css("border-color","black")
}else{if($this.attr("id")=="commentError"){H("textarea#comment").css("border-color","black")
}}}}})
}H("input#postCommentSubmit").bind("click",function(){setTimeout(N,1000)
})
},enhanceCommentsIE:function J(){if(H.browser.msie){H("#comments div.clear").remove();
H("#comments div#listComments a[name=commentList]").css("display","none");
H("#comments div#listComments").css("margin-top","0");
H("#comments div#listComments ol li").css("margin-bottom","0").css("padding-top","0");
if(parseInt(H("#comments div.even").length+H("#comments div.odd").length)==0){H("#comments #listComments").css("margin-bottom","-17px")
}if((parseInt(H("#comments div.even").length+H("#comments div.odd").length)>0)&&(H("#comments #postCommentForm").is(":visible"))){H("#comments #listComments").css("margin-top","-5px")
}H("#comments #listComments ol li").css("padding-bottom","7px");
H("#comments #listComments ol li:last-child").css("padding-bottom","0");
H("#postCommentThanks").css("margin-top","0").css("margin-bottom","0");
if(H("div#postCommentThanks").not(":visible")){H("a[name=thanks]").remove()
}if(H("#listComments ol li").length>0){H("div#postCommentForm").css("margin-bottom","16px");
H("div#postCommentThanks").css("margin-bottom","16px");
H("#listComments ol li:last-child").css("margin-bottom","-4px")
}H("#comments div.formrow").each(function(){$this=H(this);
if(H.trim($this.text()).substring(0,10)=="By posting"){$this.contents().not("[nodeType=1]").wrap("<span/>");
var N=$this.find("span:last-child").text();
$this.find("span:last-child").html("<span>&nbsp;"+N+"</span>");
$this.find("br").replaceWith("<span>&nbsp; </span>")
}})
}}}}
})(jQuery);