var C4=C4||{};
C4.Controller=(function seriesDetailControllerInit(H){var D="videoFinderResults";
var L={Categories:{getClipMerchandiseLinks:function B(S){var Q=[];
var P=H(S);
P.find("ul li a").each(function R(){var T=H(this);
Q.push({href:T.attr("href"),title:H.trim(T.text())})
});
return Q
},getCategoryClips:function N(){var Q=[];
H("#Clips ul li:not(.clipMerchandise)").each(function P(){var R=H(this);
Q.push({title:H.trim(R.find("h3").text()),img:{src:R.find("h3 img").attr("src"),alt:R.find("h3 img").attr("alt")},img_lrg:{src:R.find("h3 a").metadata().img_lrgSrc,alt:R.find("h3 a").metadata().img_lrgAlt},guidance:H.trim(R.find("p.guidance").text()),brandTitle:H.trim(R.find("p.brand").text()),synopsis:H.trim(R.find("p.synopsis").text()),type:R.find("p.type").text(),duration:H.trim(R.find("p.duration").text()),episode:H.trim(R.find("p.episode").text()),merchadiseLinks:L.Categories.getClipMerchandiseLinks(R),referenceId:R.find("h3 a").metadata().referenceId,rating:R.metadata().rating})
});
return Q
},initialiseTagsFlash:function C(P){var T={salign:"top",allowFullScreen:"true",bgcolor:"#FFFFFF",allowScriptAccess:"always",wmode:"opaque"},R={id:"clipsPlayer"},Q={clips:encodeURIComponent(H.toJSON(P)),primaryColor:H.getCssFromClass("flashPrimaryColor","color",true),secondaryColor:H.getCssFromClass("flashSecondaryColor","color",true),categoryName:H.trim(H("#PrimaryContent").find("h1 span").text().replace("Programmes: ","")).toLowerCase(),invertSkin:H("body").hasClass("invert-skin")},S=110;
Q.pinRequestCallback="C4.PinController.doPinChecks";
swfobject.embedSWF(swfRoot+"asset/flash/swf/categoryclips.swf","flashContainer","625",S,"9.0.115",swfRoot+"asset/flash/swf/expressInstall.swf",Q,T,R);
C4.PinController.setFlashPlayer("clipsPlayer")
},moveTagsPOSH:function A(){if(swfobject.hasFlashPlayerVersion("9.0.115")){H("#Clips").addClass("accessibility");
H("#flashWrapper").addClass("flashEnabled");
H("#flashWrapper").before('<p class="accessibility">Flash content: <a href="#Programmes">skip to accessible alternative</a>')
}}},enhanceCategoryInfo:function G(){H("#flashContainer").prepend('<div>For more content and an enhanced view of this page <a href="http://get.adobe.com/flashplayer/">click here to install or upgrade Flash</a>. </div>');
L.Categories.moveTagsPOSH();
L.Categories.initialiseTagsFlash(L.Categories.getCategoryClips());
if(H.browser.msie&&H.browser.version>6&&H.browser.version<8){H("#categoryPage .categories").addClass("fullWidth")
}},enhanceCatJumpPoints:function K(){H(".jumpPoints").each(function(){if(H(this).find("li").length===1&&H(this).find("li.catchUp").length===0){H(this).find("li").css("margin-top","10px")
}})
},setSortList:function J(){H("#sortByLink").hide();
var P=window.location.href;
if(P.indexOf("/title")!=-1){H("select#sortTypes").val("Title")
}else{H("select#sortTypes").val("Broadcast")
}if(H.browser.msie&&H.browser.version>7){H("#sortByContainer").css("padding-bottom","12px").css("margin-bottom","12px")
}H("#sortByContainer form").show()
},getVideoFinderOptions:function E(){var P={resultsId:D,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(e,T,V,Q){var W=e.value.toLowerCase();
var Z=W.indexOf(Q,0);
var a=W.charAt(Z+Q.length+1);
var U=[Q,"-"+Q," "+Q,Q+" "],Y=e.value.toLowerCase(),X=-1,S=[],T;
for(T=0;
T<U.length;
T++){var b=U[T];
X=Y.indexOf(U[T]);
if(T==0){if(X==0){break
}}else{if(X>-1){X++;
break
}}}var R=e.value.substr(0,X);
var c=e.value.substr(X,Q.length);
var d=e.value.substr(X+Q.length);
if(c.indexOf(" ")!=-1){if(c.charAt(0)===" "){R+=" "
}if(c.charAt(c.length-1)===" "){d=" "+d
}c=H.trim(c)
}S.push("<p>");
if(X>-1){S.push(R,"<em>",c,"</em>",d)
}else{S.push(e.value)
}S.push("</p>");
return S.join("")
}};
return P
}};
var O={sortByListSelect:function I(P){H("#sortByContainer form").attr("action",H(P.target).val()).submit()
}};
return{init:function F(){C4.OO.insistRequired({object:H,names:["metadata","poshTabsLite","setadata","toJSON","getCssFromClass","outerHtml"]},{object:swfobject,names:["embedSWF"]},{object:C4.Brand.Views,names:["buildPocketsAndTabs","enhanceSponsorship"]});
L.enhanceCategoryInfo();
L.setSortList();
L.enhanceCatJumpPoints();
C4.Brand.Views.addAutocompleteForm();
var P=false;
C4searchAutocomplete("#videoFinderText",D,P,L.getVideoFinderOptions(),"/programmes/long-form-search/");
C4.Brand.Views.buildPocketsAndTabs();
C4.Brand.Views.enhanceSponsorship();
C4.Brand.Views.enhanceJumpPointLinks();
H("#sortTypes").change(O.sortByListSelect)
},openOutFlash:function(){H("#clipsPlayer").height(484);
var Q=(H("#clipsPlayer").offset().top)-42;
var P=H("#clipsPlayer").offset().left;
window.scrollTo(P,Q);
return true
},closeInFlash:function(){H("#clipsPlayer").height(110);
return true
},_getOmnitureVars:function M(){return"s_prop22="+c4props("vertical")+"|s_account="+s_account+"|mypage="+document.location.href
},_set$:function(P){H=P
},_setViews:function(P){L=P
},_getViews:function(){return L
},_reset:(function(){var P=H,Q=L;
return function(){H=P;
L=Q
}
})()}
})(jQuery);