var C4=C4||{};
C4.Controller=(function homePageControllerInit(D){var Q={Home:{getHighlightsData:function U(){var Y=[];
D("#TonightsHighlights ul li").each(function X(){var Z=D(this);
Y.push({title:D.trim(Z.find("h3").text()),time:D.trim(Z.find("p.highlight-tx").text()),url:Z.find("h3 a").attr("href")||"",synopsis:D.trim(Z.find("p:last").text()),thumb:{src:Z.find("img").attr("src")||"",alt:Z.find("img").attr("alt")||""},img:{src:Z.find("img").metadata().rolloverImgSrc||"",alt:Z.find("img").metadata().rolloverImgAlt||""}})
});
return Y
},getSpotlightData:function A(){var Y,X,a,Z;
if(D("#Spotlight").length){Y=D("#Spotlight").metadata();
X=D.trim(Y.shortText);
a=Y.smallImageSrc;
Z=Y.smallImageAlt;
bgColor_small=Y.bgColor_small;
txtColor_small=Y.txtColor_small
}else{X=a=Z=""
}return{bgColor:C4.Home.getHexColor(D("#Spotlight div p a").css("background-color"),"0x")||"",txtColor:C4.Home.getHexColor(D("#Spotlight span.spotlight-text span").css("background-color"),"0x")||"",bgColor_small:C4.Home.getHexColor(bgColor_small,"0x")||"",txtColor_small:C4.Home.getHexColor(txtColor_small,"0x")||"",txt:C4.Home.replaceLineBreaks(decodeURI(X||"")),txt_full:C4.Home.replaceLineBreaks(D("#Spotlight div p a span.spotlight-text span").html()||""),url:D("#Spotlight div p a").attr("href")||"",img:{src:a||"",alt:Z||""},img_full:{src:D("#Spotlight div p a img").attr("src")||"",alt:D("#Spotlight div p a img").attr("alt")||""}}
},getCatchUpData:function L(){var X=[];
D("#CatchUpHighlights ul li").each(function Y(){var Z=D(this);
X.push({title:D.trim(Z.find("span.highlight-programme").text()),url:Z.find("a").attr("href")||"",img:{src:Z.find("img").attr("src")||"",alt:Z.find("img").attr("alt")||""}})
});
return X
},getNavigationData:function K(){var X=[],Z=function Z(b){var a={title:b.find("a").html(),url:b.find("a").attr("href")||"",subnav:[]};
b.find("ul > li").each(function(){var c=D(this);
a.subnav.push(Z(c))
});
return a
};
D("#HomeNavigation > ul > li").each(function Y(){var a=D(this);
X.push(Z(a))
});
return X
},getOnNowData:function E(){return D("#OnNowProgramme").text()
},getOnNowURLData:function G(){return D("#OnNow a").attr("href")||""
},showLogo:function T(){return D("meta[name=showLogo]").attr("content")
},getPromoData:function V(){var X={title:D.trim(D("#PromoText h2").text()),titleLink:D("#PromoText h2 a").attr("href")||"",subText:D.trim(D("#PromoTx span").text()),linkText:D.trim(D("#PromoLink a").text()),linkURL:D("#PromoLink a").attr("href")||"",txtColor:C4.Home.getHexColor(D("#PromoText h2").css("color"),"0x"),bgColor:C4.Home.getHexColor(D("#PromoText h2").css("background-color"),"0x"),img:{src:D("#PromoImage").attr("src")||"",alt:D("#PromoImage").attr("alt")||""}};
return X
},getTakeoverData:function M(){return D("meta[name='takeoverId']").attr("content")
},trackPromotionalLinks:function H(X){var Z,Y;
if(typeof X!=="object"||typeof X.length!=="number"){return 
}for(Y=0;
Y<X.length;
Y+=1){Z=X[Y];
if(typeof Z.selector!=="string"||typeof Z.name!=="string"){continue
}D(Z.selector).find("a").each(function(){D(this).click(Q.Home.getPromoLinkHandler(D(this).attr("href"),Z.name))
})
}},getPromoLinkHandler:function I(Y,b){var Z=Y,X=b||null;
return function a(){var c=Q.Home.getIntCmpValue(Z,X);
if(c){D.cookie("omn_intcmp",c)
}}
},getIntCmpValue:function B(Y,c){var a=Y,X=c||null;
if(typeof a!=="string"){return null
}var Z=a.match(/^(?:https?:\/\/[\w-.]+)?\/?(?:programmes|video)\/([\w-]+)(?:\/|$)/i),b=a.match(/intcmp=([\w-_]+)/i);
if(b&&typeof b[1]==="string"){return b[1]
}else{if(Z&&typeof Z[1]==="string"){return(typeof X==="string")?c+"_"+Z[1]:Z[1]
}else{return null
}}},initialiseFlashContent:function R(){var Z=[{pattern:/"/gi,replaceStr:"@%_#"},{pattern:/\&/gi,replaceStr:"c4_flash_amp"}];
var a={salign:"t",allowFullScreen:"true",bgcolor:"#000000",allowScriptAccess:"always",wmode:"opaque"},Y={id:"c4HomeFlashContent"},X={strQuotesEscapeChar:Z[0].replaceStr,highlights:encodeURIComponent(D.toJSON(Q.Home.getHighlightsData())),catchup:encodeURIComponent(D.toJSON(Q.Home.getCatchUpData())),spotlight:encodeURIComponent(D.toJSON(Q.Home.getSpotlightData())),navigation:encodeURIComponent(D.toJSON(Q.Home.getNavigationData())),onNow:encodeURIComponent(Q.Home.getOnNowData()),onNowURL:encodeURIComponent(Q.Home.getOnNowURLData()),promo:encodeURIComponent(D.toJSON(Q.Home.getPromoData())),invertSkin:D("body").hasClass("invert-skin"),showFour:Q.Home.showLogo()};
window.swfobject.embedSWF(window.swfRoot+"swf/home.swf","c4HomeFlashContainer","960","746","9.0.115",window.swfRoot+"swf/expressInstall.swf",X,a,Y);
if(window.swfobject.hasFlashPlayerVersion("9.0.115")){D("#InnerContainer").addClass("flashEnabled");
D("#PromoImage").prependTo("#InnerContainer");
D("#MainPromo").addClass("accessibility");
D("#OnNow").addClass("accessibility");
D("#TonightsHighlights").addClass("accessibility");
D("#CatchUpHighlights").addClass("accessibility");
D("#Spotlight").addClass("accessibility");
D("#c4HomeFlashContainer").before('<div class="accessibility"><a href="#MainPromo">Skip over Flash content to accessible alternative</a></div>')
}else{D("#c4HomeFlashContainer").removeClass("accessibility");
D("#c4HomeFlashContainer").css("font-size","1em");
D("#c4HomeFlashContainer").css("height","auto");
D("#c4HomeFlashContainer").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>')
}},moveGlobalNav:function J(){D(document.body).append(D("#c4acResultsSmall"));
D("#globalHeaderSpace").append(D("#c4nav"));
D(document.body).removeClass("noscript")
},fixAnnouncementGaps:function O(){D("#Announcement span.main-text, #Announcement span.main-text-inner").css("line-height","1.15")
},revealFlash:function S(){D("#c4HomeFlashContainer").removeClass("accessibility")
}}};
return{init:function N(){C4.OO.insistRequired({object:D,names:["metadata","toJSON","cookie"]},{object:C4.Home,names:["getHexColor","replaceLineBreaks","escapeStringForFlash"]});
if(D.browser.safari){Q.Home.fixAnnouncementGaps()
}Q.Home.moveGlobalNav();
Q.Home.trackPromotionalLinks([{selector:"#PromoText",name:"homepage_main"},{selector:"#CatchUpHighlights",name:"homepage_catchup"},{selector:"#TonightsHighlights",name:"homepage_piok-of-the-day"},{selector:"#Spotlight",name:"homepage_spotlight"}]);
Q.Home.initialiseFlashContent()
},handleFlash:function F(Z,a){var X=a||null,Y;
if(typeof Z==="string"){Y=Q.Home.getPromoLinkHandler(Z,X);
Y()
}},getTakeoverContentUrl:function P(){var X,e,b,d,a,Z,Y,c;
e="http://realmedia.channel4.com/RealMedia/ads/adstream_sx.ads/";
c=(location.hostname).split(".")[0];
if(c==="admin"){c=(location.hostname).split(".")[1]
}if(c==="channel4"){c="www"
}b=c+".channel4.com/takeover/";
position="Top2";
a=C4.Controller.getRandomNumber(10);
X=Q.Home.getTakeoverData();
if(X){Y=e+b+X+"/"+a+"@"+position+"?"
}else{Y=""
}return Y
},getRandomNumber:function C(X){currentTime=new Date();
randomNumber=currentTime.getTime();
randomNumber=randomNumber+"";
randomNumber=randomNumber.substring((randomNumber.length-X));
randomNumber=randomNumber*1;
return randomNumber
},revealFlash:function S(){Q.Home.revealFlash();
return true
},_getViews:function(){return Q
},_getOmnitureVars:function W(){return"s_prop22="+c4props("vertical")+"|s_account="+s_account+"|mypage="+document.location.href
}}
})(window.jQuery);