(function(){var E;gloader.load(["glow","1","glow.net","glow.widgets.Carousel"],{async:true,onLoad:function(F){E=F;E.ready(D)}});function D(){E.dom.get("#carousel").get("li").slice(-1).prependTo("#carousel");var F=E.dom.get("#carousel li").length;var H=new E.widgets.Carousel("#carousel",{loop:true,pageNav:true,theme:"dark",id:"outcarousel",size:3});E.events.addListener("#carousel .emplink","click",function(){if((E.dom.get(this).attr("class")=="emp_video carlink emplink")||(E.dom.get(this).attr("class")=="emp_audio carlink emplink")||(E.dom.get(this).attr("class")=="emp_video emplink")||(E.dom.get(this).attr("class")=="emp_audio emplink")){var channel;if((E.dom.get(this).attr("class")=="emp_video emplink")||(E.dom.get(this).attr("class")=="emp_audio emplink")){channel=this.id.replace(/_hptext/g,"");A(channel,channel)}else{channel=this.id;A(channel,channel)}return false}else{return true}});E.events.addListener("ol.schedule a","mouseenter",function(){E.dom.get("#schedtxt").text(E.dom.get(this).text());E.dom.get("#schedimg").attr("src","http://static.bbc.co.uk/switch/img/m/206x116/"+E.dom.get(this).attr("class")+".jpg");E.dom.get("#schedtxt2").attr("href",E.dom.get(this).attr("href"));E.dom.get("#schedtxt").attr("href",E.dom.get(this).attr("href"));E.dom.get("#schedimg").attr("alt",E.dom.get(this).text());E.dom.get("#whtext").text(E.dom.get("#carousel ."+(E.dom.get(this).attr("class"))+" .synop").text())});var G;H.items.each(function(I){if(this.id=="override"){G=I}});if(G!==undefined){H.moveTo(G-1,false)}else{H.moveTo(Math.floor(Math.random()*F),false)}if(E.env.ie<7){E.dom.create('<a href="#" id="carousel-leftc" />').appendTo(E.dom.get(".carousel-dark"));E.dom.create('<a href="#" id="carousel-rightc" />').appendTo(E.dom.get(".carousel-dark"));E.dom.create('<a href="#" id="carousel-left" />').appendTo(E.dom.get("#carousel-leftc"));E.dom.create('<a href="#" id="carousel-right" />').appendTo(E.dom.get("#carousel-rightc"))}else{E.dom.create('<a href="#" id="carousel-left" />').appendTo(E.dom.get(".carousel-dark"));E.dom.create('<a href="#" id="carousel-right" />').appendTo(E.dom.get(".carousel-dark"))}E.events.addListener("#carousel-left","click",function(){H.moveBy(-1,true);return false});E.events.addListener("#carousel-right","click",function(){H.moveBy(+1,true);return false});E.net.get("/switch/feed/nownext?format=xml",{onLoad:function(I){C(parseInt(E.dom.get(I.xml()).get("countdown").text()),parseInt(E.dom.get(I.xml()).get("duration").text()),E.dom.get(I.xml()).get("tvshow").text(),E.dom.get(I.xml()).get("channel").text())}})}function C(I,H,F,G){if(I>0){I--;setTimeout(function(){C(I,H,F,G)},1000)}else{if(I<=0){if(E.dom.get("#carousel").length){A(G,F)}I="onair";setTimeout(function(){C(I,H,F,G)},1000)}else{if(H>0){H--;setTimeout(function(){C(I,H,F,G)},1000)}else{if(H==0){E.net.get("/switch/feed/nownext?format=xml",{onLoad:function(J){if(parseInt(E.dom.get(J.xml()).get("countdown").text())<=0){B(E.dom.get(J.xml()).get("tvshow").text(),E.dom.get(J.xml()).get("channel").text());C("onair",parseInt(E.dom.get(J.xml()).get("duration").text()),E.dom.get(J.xml()).get("tvshow").text(),E.dom.get(J.xml()).get("channel").text())}else{if(E.dom.get("#carousel").length){E.dom.get("#left-vid").destroy();var L=E.anim.css("#outcarousel",1,{width:946,"margin-left":0});var K=E.anim.css(".carousel-dark",1,{"margin-left":-304});new E.anim.Timeline([[L],[K]]).start();E.dom.get(".carousel-dark .pageNav").css("visibility","visible")}}}})}}}}}function B(F,G){if((G=="online")||(G=="http://www.bbc.co.uk/switch/the519show/xml/live.xml")){E.net.get("/switch/xml/playlist/"+F+".xml",{useCache:true,onLoad:function(H){E.dom.get("#left-vid .text").html('<div id="emptitle">'+E.dom.get(H.xml()).get("title").text()+"</div>"+E.dom.get(H.xml()).get("summary").text()+'<div id="emplnk">Visit <a href="'+E.dom.get(H.xml()).get("site").text()+'">'+E.dom.get(H.xml()).get("title").text().substr(0,E.dom.get(H.xml()).get("title").text().indexOf(": "))+"</a> Website</div>")}})}else{E.net.get("/iplayer/playlist/"+F,{useCache:true,onLoad:function(H){E.dom.get("#left-vid .text").html('<div id="emptitle">'+E.dom.get(H.xml()).get("title").text()+"</div>"+E.dom.get(H.xml()).get("summary").text()+'<div id="emplnk">Visit <a href="/programmes/'+F+'/microsite">'+E.dom.get(H.xml()).get("title").text().substr(0,E.dom.get(H.xml()).get("title").text().indexOf(": "))+"</a> Website</div>")}})}}function A(I,F){if(I=="radio1"){I="http://www.bbc.co.uk/switch/xml/radio1.xml"}else{if(I=="bbcone"){I="http://www.bbc.co.uk/emp/simulcast/bbc_one_london.xml"}else{if(I=="bbctwo"){I="http://www.bbc.co.uk/emp/simulcast/bbc_two_england.xml"}else{if(I=="bbcthree"){I="http://www.bbc.co.uk/emp/simulcast/bbc_three.xml"}else{if(I=="online"){I="http://www.bbc.co.uk/switch/the519show/xml/live.xml"}else{I="http://www.bbc.co.uk/iplayer/playlist/"+I}}}}}E.dom.create('<div id="left-vid"><div class="text"></div><div id="vid"></div><a href="#" id="closeemp">Close Player</a></div>').appendTo(E.dom.get("#carousel-container"));var K=new embeddedMedia.Player();K.setWidth("512");K.setHeight("324");K.setDomId("vid");K.setPlaylist(I);K.set("config_settings_autoPlay",true);K.set("config_settings_skin","black");var J=E.anim.css("#outcarousel",1,{width:512,"margin-left":217});var H=E.anim.css(".carousel-dark",1,{"margin-left":-521});var G=new E.anim.Timeline([[J],[H]]);G.start();E.events.addListener(G,"complete",function(){E.events.addListener("#closeemp","click",function(){E.dom.get("#left-vid").destroy();var M=E.anim.css("#outcarousel",1,{width:946,"margin-left":0});var L=E.anim.css(".carousel-dark",1,{"margin-left":-304});new E.anim.Timeline([[M],[L]]).start();E.dom.get(".carousel-dark .pageNav").css("visibility","visible");return false});E.dom.get(".carousel-dark .pageNav").css("visibility","hidden");E.dom.get("#vid").html('In order to see this video, you must have Flash 9 or greater installed.  Visit <a href="/webwise/askbruce/articles/download/howdoidownloadflashplayer_1.shtml">BBC Webwise</a> for full instructions.');K.write();B(F,I);E.dom.get("#closeemp").css("visibility","visible")})}})();