(function(){var h;gloader.load(["glow","1","glow.net","glow.widgets.Carousel"],{async:true,onLoad:function(g){h=g;h.ready(init)}});function init(){h.dom.get("#carousel").get("li").slice(-1).prependTo("#carousel");var b=h.dom.get("#carousel li").length,myCarousel=new h.widgets.Carousel("#carousel",{loop:true,pageNav:true,theme:"dark",id:"outcarousel",size:3}),index;myCarousel.items.each(function(i){if(this.id==="override"){if(index===undefined)index=i}});if(index!==undefined){myCarousel.moveTo(index-1,false)}else{myCarousel.moveBy(Math.floor(Math.random()*b),false)}h.events.addListener('#carousel .emplink','click',function(){if((h.dom.get(this).attr("class")=="emp_video carlink emplink")||(h.dom.get(this).attr("class")=="emp_audio carlink emplink")||(h.dom.get(this).attr("class")=="emp_video emplink")||(h.dom.get(this).attr("class")=="emp_audio emplink")){var a;if((h.dom.get(this).attr("class")=="emp_video emplink")||(h.dom.get(this).attr("class")=="emp_audio emplink")){a=this.id.replace(/_hptext/g,"");fireemp(a,a)}else{a=this.id;fireemp(a,a)}return false}else{return true}});if(h.env.ie<7){h.dom.create("<div id=\"carousel-leftc\"><a href=\"#\" id=\"carousel-left\" title=\"previous\"></a></div><div id=\"carousel-rightc\"><a href=\"#\" id=\"carousel-right\" title=\"next\"></a></div>").appendTo(".carousel-dark")}else{h.dom.create("<a href=\"#\" id=\"carousel-left\" title=\"previous\" /><a href=\"#\" id=\"carousel-right\" title=\"next\" />").appendTo(".carousel-dark")}h.events.addListener('#carousel-left','click',function(){myCarousel.moveBy(-1,true);return false});h.events.addListener('#carousel-right','click',function(){myCarousel.moveBy(+1,true);return false});h.events.addListener('ol.schedule a','mouseenter',function(){h.dom.get("#schedimg").attr("src","http://static.bbc.co.uk/switch/img/m/206x116/"+h.dom.get(this).attr("class")+".jpg").attr("alt",h.dom.get(this).text());h.dom.get("#schedtxt").text(h.dom.get(this).text());h.dom.get("#schedtxt","#schedtxt2").attr("href",h.dom.get(this).attr("href"));h.dom.get("#whtext").text(h.dom.get("#carousel ."+(h.dom.get(this).attr("class"))+" .synop").text())});h.net.get("/switch/feed/nownext?format=xml",{onLoad:function(a){countdown(parseInt(h.dom.get(a.xml()).get("countdown").text()),parseInt(h.dom.get(a.xml()).get("duration").text()),h.dom.get(a.xml()).get("tvshow").text(),h.dom.get(a.xml()).get("channel").text())}})}function countdown(d,e,f,g){if(d>0){d--;setTimeout(function(){countdown(d,e,f,g)},1000)}else if(d<=0){if(h.dom.get("#carousel").length){fireemp(g,f)}d="onair";setTimeout(function(){countdown(d,e,f,g)},1000)}else if(e>0){e--;setTimeout(function(){countdown(d,e,f,g)},1000)}else if(e==0){h.net.get("/switch/feed/nownext?format=xml",{onLoad:function(a){if(parseInt(h.dom.get(a.xml()).get("countdown").text())<=0){showinfo(h.dom.get(a.xml()).get("tvshow").text(),h.dom.get(a.xml()).get("channel").text());countdown("onair",parseInt(h.dom.get(a.xml()).get("duration").text()),h.dom.get(a.xml()).get("tvshow").text(),h.dom.get(a.xml()).get("channel").text())}else{if(h.dom.get("#carousel").length){h.dom.get("#left-vid").destroy();if(h.dom.get("#live").length){h.dom.get("#live").destroy();if(h.env.ie<7){h.dom.create("<link rel=\"stylesheet\" type=\"text/css\" id=\"live\" href=\"/switch/css/live/reset_ie6.css\" />").appendTo("head")}}var b=h.anim.css("#outcarousel",1,{"width":946,"margin-left":0});var c=h.anim.css(".carousel-dark",1,{"margin-left":-304});new h.anim.Timeline([[b],[c]]).start();h.dom.get(".carousel-dark .pageNav").css("visibility","visible")}}}})}}function showinfo(b,c){if((c=="online")||(c=="http://www.bbc.co.uk/switch/the519show/xml/live.xml")){h.net.get("/switch/xml/playlist/"+b+".xml",{useCache:true,onLoad:function(a){h.dom.get("#left-vid .text").html("<div id=\"emptitle\">"+h.dom.get(a.xml()).get("title").text()+"</div>"+h.dom.get(a.xml()).get("summary").text()+"<div id=\"emplnk\">Visit <a href=\""+h.dom.get(a.xml()).get("site").text()+"\">"+h.dom.get(a.xml()).get("title").text().substr(0,h.dom.get(a.xml()).get("title").text().indexOf(': '))+"</a> Website</div>")}})}else{h.net.get("/iplayer/playlist/"+b,{useCache:true,onLoad:function(a){h.dom.get("#left-vid .text").html("<div id=\"emptitle\">"+h.dom.get(a.xml()).get("title").text()+"</div>"+h.dom.get(a.xml()).get("summary").text()+"<div id=\"emplnk\">Visit <a href=\"/programmes/"+b+"/microsite\">"+h.dom.get(a.xml()).get("title").text().substr(0,h.dom.get(a.xml()).get("title").text().indexOf(': '))+"</a> Website</div>")}})}if((c=="radio1")||(c=="http://www.bbc.co.uk/switch/xml/radio1.xml")){customSite()}}function fireemp(b,c){if(b=="radio1"){b="http://www.bbc.co.uk/switch/xml/radio1.xml"}else if(b=="bbcone"){b="http://www.bbc.co.uk/emp/simulcast/bbc_one_london.xml"}else if(b=="bbctwo"){b="http://www.bbc.co.uk/emp/simulcast/bbc_two_england.xml"}else if(b=="bbcthree"){b="http://www.bbc.co.uk/emp/simulcast/bbc_three.xml"}else if(b=="online"){b="http://www.bbc.co.uk/switch/the519show/xml/live.xml"}else{b="http://www.bbc.co.uk/iplayer/playlist/"+b}h.dom.create("<div id=\"left-vid\"><div class=\"text\"></div><div id=\"vid\"></div><a href=\"#\" id=\"closeemp\">Close Player</a></div>").appendTo(h.dom.get("#carousel-container"));var d=new embeddedMedia.Player();d.setWidth("512");d.setHeight("324");d.setDomId("vid");if(b=="http://www.bbc.co.uk/switch/xml/radio1.xml"){d.setWidth("467");d.setHeight("35")}d.setPlaylist(b);d.set("config_settings_autoPlay",true);d.set("config_settings_skin","black");var e=h.anim.css("#outcarousel",1,{"width":512,"margin-left":217}),shrink2=h.anim.css(".carousel-dark",1,{"margin-left":-521}),myTimeline=new h.anim.Timeline([[e],[shrink2]]);myTimeline.start();h.events.addListener(myTimeline,"complete",function(){h.events.addListener('#closeemp','click',function(){h.dom.get("#left-vid").destroy();if(h.dom.get("#live").length){h.dom.get("#live").destroy();if(h.env.ie<7){h.dom.create("<link rel=\"stylesheet\" type=\"text/css\" id=\"live\" href=\"/switch/css/live/reset_ie6.css\" />").appendTo("head")}}var a=h.anim.css("#outcarousel",1,{"width":946,"margin-left":0}),grow2=h.anim.css(".carousel-dark",1,{"margin-left":-304});new h.anim.Timeline([[a],[grow2]]).start();h.dom.get(".carousel-dark .pageNav").css("visibility","visible");return false});h.dom.get(".carousel-dark .pageNav").css("visibility","hidden");h.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.");d.write();showinfo(c,b);h.dom.get("#closeemp").css("visibility","visible")})}function customSite(){var b=new Date(); var time=b.getHours();if(h.dom.get("#live").length){h.dom.get("#live").destroy()}h.dom.get("#closeemp").text("Close");h.dom.create("<div id=\"quest\"><div id=\"thanks\">Send us a message!</div><form action=\"\"><input type=\"text\" id=\"name\" value=\"Name\" /><textarea id=\"question\" rows=\"5\" cols=\"80\">Got something to say? Tell us!</textarea><input type=\"submit\" id=\"submit\" value=\"Send Message\" /></form></div>").appendTo("#left-vid");h.events.addListener("#question","focus",function(){h.dom.get("#question")[0].value=""});h.events.addListener("#name","focus",function(){h.dom.get("#name")[0].value=""});h.events.addListener("#submit","click",function(){h.net.post("/cgi-bin/cgiemail/switch/contact.txt",{name:h.dom.get("#name")[0].value,question:h.dom.get("#question")[0].value},{useCache:true,onLoad:function(a){h.dom.get("#thanks").text("Thanks for sending a message!");h.dom.get("#name")[0].value="Name";h.dom.get("#question")[0].value="Got something to say? Tell us!"}});return false});if(time<21){if(h.env.ie<7){h.dom.create("<link rel=\"stylesheet\" type=\"text/css\" id=\"live\" href=\"/switch/css/live/519.css\" />").appendTo("head")}else{h.dom.create("<link rel=\"stylesheet\" type=\"text/css\" id=\"live\" href=\"/switch/css/live/519.css\" />").appendTo("head")}}else if(time==21){if(h.env.ie<7){h.dom.create("<link rel=\"stylesheet\" type=\"text/css\" id=\"live\" href=\"/switch/css/live/surgery_ie6.css\" />").appendTo("head")}else{h.dom.create("<link rel=\"stylesheet\" type=\"text/css\" id=\"live\" href=\"/switch/css/live/surgery.css\" />").appendTo("head")}}else{if(h.env.ie<7){h.dom.create("<link rel=\"stylesheet\" type=\"text/css\" id=\"live\" href=\"/switch/css/live/nick_ie6.css\" />").appendTo("head")}else{h.dom.create("<link rel=\"stylesheet\" type=\"text/css\" id=\"live\" href=\"/switch/css/live/nick.css\" />").appendTo("head")}}}})();