var C4=C4||{};
C4.Controller=(function hubControllerInit(F){var A="@%_#",E,L={Announcements:{clickLink:function Y(){location.href=F(this).find("a:first").attr("href")
},toggleCue:function P(){F(this)[(F(this).hasClass("hover-el"))?"removeClass":"addClass"]("hover-el")
}}},R={BrandHub:{getBrandAwards:function Q(){return""
},getBrandCategories:function W(){var d=[];
F("#Category").find("li").each(function c(){var e=F(this);
d.push({title:F.trim(e.text()),url:e.find("a").attr("href")})
});
return d
},getBrandCast:function M(){var d=[];
F("#Cast").find("dt").each(function c(){var e=F(this);
d.push({role:e.text(),name:e.next().text()})
});
return d
},getBrandCrew:function D(){var d=[];
F("#Crew").find("dt").each(function c(){var e=F(this);
d.push({role:e.text(),name:e.next().text()})
});
return d
},getBrandTags:function B(){var d=[];
F("#Tags").find("ul li").each(function c(){d.push(F(this).text())
});
return d
},getBrandClips:function X(){var d=[];
F("#Clips").find("ul li:not(.clipMerchandise)").each(function c(){var e=F(this);
d.push({title:F.trim(e.find("h3").text()),img:{src:e.find("h3 img").attr("src"),alt:e.find("h3 img").attr("alt")},img_lrg:{src:e.find("h3 a").metadata().img_lrgSrc,alt:e.find("h3 a").metadata().img_lrgAlt},guidance:F.trim(e.find("p.guidance").text()),synopsis:F.trim(e.find("p.synopsis").text()),type:e.find("p.type").text(),duration:F.trim(e.find("p.duration").text()),episode:F.trim(e.find("p.episode").text()),merchadiseLinks:R.BrandHub.getClipMerchandiseLinks(e),referenceId:e.find("h3 a").metadata().referenceId,rating:e.metadata().rating})
});
return d
},getBrandPictures:function Z(){var d=[];
F("#Pictures").find("ul li").each(function c(){var e=F(this);
d.push({title:F.trim(e.find("h3").text()),caption:F.trim(e.find("h3 a").metadata().caption),img:{src:e.find("h3 a").metadata().imgSrc,alt:e.find("h3 img").attr("alt")},thumb:{src:e.find("h3 img").attr("src"),alt:e.find("h3 img").attr("alt")}})
});
return d
},getMerchandiseLinks:function C(){var d=[];
F("#MerchandiseLinks ul li a").each(function c(){var e=F(this);
d.push({href:e.attr("href"),title:F.trim(e.text())})
});
return d
},getClipMerchandiseLinks:function b(f){var d=[];
var c=F(f);
c.find("ul li a").each(function e(){var g=F(this);
d.push({href:g.attr("href"),title:F.trim(g.text())})
});
return d
},getSynopsisParagraphs:function U(){var c="";
F("#synopsis p").each(function(){c+=F(this).text()+"\r\r"
});
c=c.replace(/\r\r$/,"");
return c
},buildBrandData:function J(){return{title:F("h1.imgRep span").text(),heroImage:{alt:F("#heroImage").attr("alt"),src:F("#heroImage").attr("src")},synopsis:R.BrandHub.getSynopsisParagraphs(),productionCompany:F(".productionCompany").next().text(),officialURL:F(".officialSite").next().find("a").attr("href"),officialURL_lbl:F(".officialSite").next().text(),awards:R.BrandHub.getBrandAwards(),categories:R.BrandHub.getBrandCategories(),castAndCrew:{cast:R.BrandHub.getBrandCast(),crew:R.BrandHub.getBrandCrew()},tags:R.BrandHub.getBrandTags(),clips:R.BrandHub.getBrandClips(),pictures:R.BrandHub.getBrandPictures(),announcement:F.trim(F("#announcement").text())}
},initialiseHubFlash:function K(c){var f={salign:"top",allowFullScreen:"true",bgcolor:"#FFFFFF",allowScriptAccess:"always",wmode:"opaque"},e={id:"clipsPlayer"},d={strQuotesEscapeChar:A,brand:encodeURIComponent(F.toJSON(c)),strSeeAllClipsUrl:encodeURIComponent(F("#Clips").find(".more:first").attr("href")),strSeeAllClipsLabel:encodeURIComponent(jQuery.trim(F("#Clips").find(".more:first").text())),strSeeAllPicsUrl:encodeURIComponent(F("#Pictures").find(".more:first").attr("href")),strSeeAllPicsLabel:encodeURIComponent(jQuery.trim(F("#Pictures").find(".more:first").text())),primaryColor:F.getCssFromClass("flashPrimaryColor","color",true),secondaryColor:F.getCssFromClass("flashSecondaryColor","color",true),invertSkin:F("body").hasClass("invert-skin")};
E=(c.clips.length===0&&c.pictures.length===0)?352:484;
d.pinRequestCallback="C4.PinController.doPinChecks";
swfobject.embedSWF(swfRoot+"asset/flash/swf/brandhub.swf","flashContainer","625",E,"9.0.115",swfRoot+"asset/flash/swf/expressInstall.swf",d,f,e);
C4.PinController.setFlashPlayer("clipsPlayer")
}},enhanceBrandInfo:function T(){F("#flashContainer").prepend('<p class="info">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>. </p>');
if(swfobject.hasFlashPlayerVersion("9.0.115")){swfobject.addDomLoadEvent(C4.Controller.moveHubPOSH);
swfobject.addDomLoadEvent(C4.Controller.addFlashAccessibilityMessage)
}if(F.browser.safari&&navigator.platform=="Win32"){F(document).ready(function(){R.BrandHub.initialiseHubFlash(R.BrandHub.buildBrandData())
})
}else{R.BrandHub.initialiseHubFlash(R.BrandHub.buildBrandData())
}},enhanceEGS:function O(){},enhanceNewsAndArticles:function H(){F("div#newsAndArticles").find("ul.double").find("li:first").addClass("first").find("h3, p:not(p.editor)").wrapAll("<div />").end().end().find("li:last").addClass("last").find("h3, p:not(p.editor)").wrapAll("<div />").end().end().end().find("ul li div").end().find("a.more")
},enhanceAnnouncement:function V(){F("#announcement").bind("click",L.Announcements.clickLink).bind("mouseenter",L.Announcements.toggleCue).bind("mouseleave",L.Announcements.toggleCue)
}};
return{init:function G(){C4.OO.insistRequired({object:F,names:["metadata","flowfit","poshTabsLite","setadata","toJSON","getCssFromClass","outerHtml"]},{object:swfobject,names:["embedSWF"]},{object:C4.Brand.Views,names:["buildPocketsAndTabs","enhanceQuickLinks"]});
R.enhanceBrandInfo();
R.enhanceEGS();
R.enhanceNewsAndArticles();
C4.Brand.Views.enhanceRelatedLinksList();
C4.Brand.Views.enhanceQuickLinks();
C4.Brand.Views.buildPocketsAndTabs();
C4.Brand.Views.enhanceJumpPointLinks();
C4.Brand.Views.enhanceComments();
C4.Brand.Views.enhanceCommentsIE();
C4.Brand.Views.enhanceBrandPageAds();
C4.Brand.Views.enhanceEpisodeLinks(390)
},moveHubPOSH:function N(){F("#flashHubWrapper").css({minHeight:E});
F("h1").addClass("accessibility");
F("#heroImage").addClass("accessibility");
F("#Category").addClass("accessibility");
F("#Watch").addClass("accessibility");
F("#MerchandiseLinks").addClass("accessibility");
F("#synopsis").parent().addClass("accessibility")
},addFlashAccessibilityMessage:function S(){F("#flashHubWrapper").before('<div class="accessibility">Flash content: <a href="#Watch">skip to accessible alternative</a></div>').addClass("flashEnabled")
},_getSponsorship:function I(){return{strSponsorClickURL:F("#c4ad-Top1 a").attr("href"),strSponsorClickAlt:F("#c4ad-Top1 img").attr("alt"),strSponsorLogo:F("#c4ad-Top1 img").attr("src")}
},_getOmnitureVars:function a(){return"s_prop22="+c4props("vertical")+"|s_account="+s_account+"|mypage="+document.location.href
},_set$:function(c){F=c
},_setViews:function(c){R=c
},_getViews:function(){return R
},_reset:(function(){var c=F,d=R;
return function(){F=c;
R=d
}
})()}
})(jQuery);