/*	
	Copyright 2009 British Broadcasting Corporation

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

	   http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/
(function(){if(window.gloaddisableder){return;}window.gloaddisableder={_requests:[],_modules:{},_expects:{},_extras:{},_errors:[],util:{getGloaddisablederFile:function(filepath){if(filepath&&/(^|^.*[\/\\])(gloaddisableder(\.[^\/\\]+)?\.js)(\?|$)/i.test(filepath)){var dir=RegExp.$1;if(dir){dir=dir.replace("cached/","");}return{dir:dir,name:RegExp.$2};}return undefined;}},map:{js:{},css:{},parse:function(libraryName,libraryVersions){var lib={name:libraryName,versions:[]};var scope={};var scopeProps=["$name","$version","$base"];scopeProps.has=function(what){for(var i=0;i<this.length;i++){if(what==this[i]){return true;}}return false;};if(gloaddisableder.mapProps&&gloaddisableder.mapProps[lib.name]){for(var p in gloaddisableder.mapProps[lib.name]){if(!scopeProps.has(p)){scopeProps.push(p);}}}for(var p=0;p<scopeProps.length;p++){scope[scopeProps[p]]=undefined;}scope.$name=lib.name;if(gloaddisableder.mapProps&&gloaddisableder.mapProps[lib.name]){for(var p in gloaddisableder.mapProps[lib.name]){scope[p]=gloaddisableder.mapProps[lib.name][p];}}for(var i=0;i<libraryVersions.length;i++){var version=libraryVersions[i];for(var v in version){if(version[v]===null){delete version[v];delete scope[v];}else{if(v.indexOf("$")===0){scope[v]=version[v];}else{if(typeof version[v]=="string"){version[v]=[version[v]];scope[v]=version[v].slice(0);}else{if(typeof version[v].push!="undefined"){scope[v]=version[v].slice(0);}else{throw new Error("invalid type: "+typeof version[v]);}}}}}for(var s in scope){if(typeof version[s]=="undefined"){if(s.indexOf("$")===0){version[s]=scope[s];}else{version[s]=scope[s].slice(0);}}}for(var p=0;p<scopeProps.length;p++){var prop=scopeProps[p];for(var vp=0;vp<p;vp++){var vprop=scopeProps[vp];if(typeof version[vprop]=="undefined"){version[prop]=scope[prop];}var patt=new RegExp("\\{\\"+vprop+"\\}","g");version[prop]=version[prop].replace(patt,version[vprop]);}}for(vi in version){if(vi.indexOf("$")===0){continue;}for(var vii=0;vii<version[vi].length;vii++){for(var p=0;p<scopeProps.length;p++){var prop=scopeProps[p];var patt=new RegExp("\\{\\"+prop+"\\}","g");version[vi][vii]=""+version[vi][vii].replace(patt,""+version[prop]);}}}lib.versions.push(version);}return lib;},add:function(){var args=[];for(var i=1;i<arguments.length;i++){args.push(arguments[i]);}var lib=gloaddisableder.map.parse(arguments[0],args);for(var i=0;i<lib.versions.length;i++){var version=lib.versions[i];for(var p in version){if(p.charAt(0)=="$"){continue;}var modId=version.$name+"/"+version.$version+"/"+p;gloaddisableder.map.js[modId]=version[p][0];gloaddisableder.map.css[modId]=version[p][1];}}},include:function(src){if(gloaddisableder.map._include[src]){return false;}else{void('<script type="text/javascript" src="'+src+'"><\/script>\n');gloaddisableder.map._include[src]=true;return true;}},_include:{},latest:function(libName,v){if(gloaddisableder.map.$latest[libName+"/"+v]){return gloaddisableder.map.$latest[libName+"/"+v];}var result=v;var parts=v.split(".");if(parts.length<3){if(parts[0]==parseInt(parts[0])&&(typeof parts[1]=="undefined"||parts[1]==parseInt(parts[1]))){var invalid=new RegExp("[a-zA-Z-]"),latest=[parts[0],null,null],mod;for(mod in gloaddisableder.map.js){var modParts=mod.split("/");if(modParts[0]==libName&&modParts[2]==libName&&!invalid.test(modParts[1])){var modVParts=modParts[1].split(".");if(modVParts[0]==parts[0]){if((typeof parts[1]=="undefined"&&(latest[1]<=modVParts[1]||(latest[1]==modVParts[1]&&latest[2]<=modVParts[2])))||(typeof parts[1]!="undefined"&&parts[1]==modVParts[1]&&latest[2]<=modVParts[2])){latest[1]=modVParts[1];latest[2]=modVParts[2];}}}}if(latest[2]!=null){result=latest.join(".");}}}gloaddisableder.map.$latest[libName+"/"+v]=result;return result;},$latest:{}},settings:{ns:"bbc.glow.gloaddisableder",get:function(name){var n=" "+gloaddisableder.settings.ns+"."+name+"=";var cookies=document.cookie.split(";");for(var i=0;i<cookies.length;i++){if((" "+cookies[i]).indexOf(n)>-1){return unescape(cookies[i].split("=")[1]);}}},set:function(name,value,path){var n=gloaddisableder.settings.ns+"."+name;document.cookie=n+"="+escape(value)+"; path="+((path)?path:"/")+";";},clear:function(name,path){var d=new Date();d.setTime(d.getTime()-1);var n=gloaddisableder.settings.ns+"."+name;document.cookie=n+"=; path="+((path)?path:"/")+"; expires=Thu, 01-Jan-70 00:00:01 GMT;";}},loaddisabledOverride:function(version){var current=gloaddisableder.settings.get("override");version=version||prompt("Enter version",current?current:"");if(version===""){gloaddisableder.settings.clear("override");}else{if(version!==null){gloaddisableder.settings.set("override",version);}}location.reloaddisabled();},loaddisabledDebug:function(){gloaddisableder.settings.set("debug","1");location.reloaddisabled();},unloaddisabledDebug:function(){gloaddisableder.settings.clear("debug");location.reloaddisabled();},expect:function(srcFile){srcFile=""+srcFile;var modsInFile=[];var modId;for(modId in gloaddisableder.map.js){if(gloaddisableder.map.js[modId]==srcFile){modsInFile.push(modId);gloaddisableder._expects[modId]=(gloaddisableder._expects[modId]||0)+1;}}},loaddisabled:function(){var r={};if(typeof arguments[arguments.length-1].length=="undefined"){r=arguments[arguments.length-1];arguments.length--;}var newRequest=new gloaddisableder.Request(r);gloaddisableder._requests.push(newRequest);var mods=[];var override=gloaddisableder.settings.get("override");for(var i=0;i<arguments.length;i++){if(override&&arguments[i][0]=="glow"){if(typeof console!="undefined"&&console.log){console.log("Overriding version '"+arguments[i][1]+"' of glow to version '"+override+"'");}arguments[i][1]=override;}mods.push(arguments[i]);}var ids=gloaddisableder.toIds(mods);newRequest.args=[];for(var i=0;i<ids.length;i++){newRequest.include(ids[i]);if(ids[i].match(/\/[^.]+$/)){newRequest.args.push(ids[i]);}}var waitCount=newRequest.waits.length;for(var i=0;i<newRequest.waits.length;i++){if(gloaddisableder._modules[newRequest.waits[i]]&&gloaddisableder._modules[newRequest.waits[i]].status==gloaddisableder.Module.IMPLEMENTED){waitCount--;}}if(waitCount>0){newRequest.status=gloaddisableder.Request.WAITING;gloaddisableder.request(ids,newRequest.async);gloaddisableder.resolve();}else{newRequest.complete();}},request:function(mIds,async){for(var i=0;i<mIds.length;i++){var m=mIds[i];if(gloaddisableder._extras[m]){gloaddisableder._modules[m]=new gloaddisableder.Module(m);var extra=gloaddisableder._extras[m];delete gloaddisableder._extras[m];gloaddisableder.provide(extra);}else{if(!gloaddisableder._modules[m]){gloaddisableder._modules[m]=new gloaddisableder.Module(m);gloaddisableder._modules[m].status=gloaddisableder.Module.REQUESTED;}}if(gloaddisableder._modules[m].status<gloaddisableder.Module.IMPLEMENTED||gloaddisableder._modules[m].css){gloaddisableder._modules[m].css=null;gloaddisableder.fetch(gloaddisableder._modules[m],async);}}},fetch:function(m,async){var cssSrc=gloaddisableder.map.css[m.id],jsSrc=gloaddisableder.map.js[m.id];gloaddisableder._modules[m.id].async=async;var force=(!async&&gloaddisableder._fetched[jsSrc]&&gloaddisableder._fetched[jsSrc].async&&gloaddisableder._modules[m.id].status<gloaddisableder.Module.IMPLEMENTED);if(cssSrc&&(force||!gloaddisableder._fetched[cssSrc])){gloaddisableder._fetched[cssSrc]={};if(document){var headElement;if(headElement=document.getElementsByTagName("head")[0]){var link;if(link=document.createElement("link")){link.href=cssSrc;link.rel="stylesheet";link.type="text/css";link.className="gloaddisableded async";headElement.appendChild(link);}}else{void('<link rel="stylesheet" type="text/css" href="'+cssSrc+'" class="gloaddisableded sync">');}}}if(!jsSrc){var msg="The gloaddisableder map is missing a JavaScript filepath for the module: "+m.id;var maps=[];for(var included_map in gloaddisableder.map._include){maps.push(included_map);}msg+=".\rMaps included are: "+maps.join(", ")+".";gloaddisableder._errors.push(msg);throw new Error(msg);}if(jsSrc){if(force||!gloaddisableder._fetched[jsSrc]){gloaddisableder._fetched[jsSrc]={};gloaddisableder.expect(jsSrc);if(async){gloaddisableder._fetched[jsSrc].async=true;var headElement=document.getElementsByTagName("head")[0];var scriptElement=document.createElement("script");scriptElement.type="text/javascript";scriptElement.src=jsSrc;scriptElement.className="gloaddisableded async";headElement.appendChild(scriptElement);}else{gloaddisableder._fetched[jsSrc].sync=true;void('<script type="text/javascript" src="'+jsSrc+'" class="gloaddisableded sync"><\/script>\n');}}else{}if(gloaddisableder._modules[m.id].status<gloaddisableder.Module.FETCHED){gloaddisableder._modules[m.id].status=gloaddisableder.Module.FETCHED;}}},_fetched:{},provide:function(m){m.id=m.library[0]+"/"+m.library[1]+"/"+m.name;if(!gloaddisableder._modules[m.id]){gloaddisableder._extras[m.id]=m;return;}if(gloaddisableder._modules[m.id].status>=gloaddisableder.Module.PROVIDED){return;}gloaddisableder._modules[m.id].status=gloaddisableder.Module.PROVIDED;gloaddisableder._modules[m.id].builder=m.builder;gloaddisableder._modules[m.id].builder.args=[];var d=gloaddisableder._modules[m.id].depends=(m.depends)?gloaddisableder.toIds(m.depends):[];if(d.length>0){var includes=[];for(var i=0;i<d.length;i++){var requests=gloaddisableder.getRequests(m);var include={async:true,ids:[]};for(var j=0;j<requests.length;j++){requests[j].include(d[i]);include.ids.push(d[i]);if(requests[j].async===false){include.async=false;}}includes.push(include);if(d[i].match(/\/[^.]+$/)){gloaddisableder._modules[m.id].builder.args.push(d[i]);}}for(var i=0;i<includes.length;i++){if(includes[i].ids.length){gloaddisableder.request(includes[i].ids,includes[i].async);}}}else{gloaddisableder.implement(m);}gloaddisableder.resolve();},_greet:function(mId){if(gloaddisableder._expects[mId]>0){gloaddisableder._expects[mId]--;}else{var msg="Unexpected module provided to gloaddisableder: "+mId;gloaddisableder._errors.push(msg);throw (msg);}},module:function(modDef){var modId=modDef.library[0]+"/"+modDef.library[1]+"/"+modDef.name;gloaddisableder._greet(modId);if(!modDef.depends){modDef.depends=[];}modDef.depends.unshift(modDef.library);gloaddisableder.provide(modDef);},library:function(modDef){var modId=modDef.name+"/"+modDef.version+"/"+modDef.name;gloaddisableder._greet(modId);if(!modDef.depends){modDef.depends=[];}modDef.library=[modDef.name,modDef.version];gloaddisableder.provide(modDef);},implement:function(m){if(gloaddisableder._modules[m.id].status!=gloaddisableder.Module.PROVIDED){return;}for(var i=0;i<gloaddisableder._modules[m.id].builder.args.length;i++){var argName=gloaddisableder._modules[m.id].builder.args[i];gloaddisableder._modules[m.id].builder.args[i]=gloaddisableder._modules[m.builder.args[i]].implementation;gloaddisableder._modules[m.id].builder.args[i].name=argName;}gloaddisableder._modules[m.id].implementation=gloaddisableder._modules[m.id].builder.apply(null,gloaddisableder._modules[m.id].builder.args);gloaddisableder._modules[m.id].status=gloaddisableder.Module.IMPLEMENTED;for(var i=0;i<gloaddisableder._requests.length;i++){gloaddisableder._requests[i].release(m.id);}},resolve:function(){MODULES:for(var m in gloaddisableder._modules){var module=gloaddisableder._modules[m];if(module.status==gloaddisableder.Module.PROVIDED){for(var j=0;j<module.depends.length;j++){var dModule=gloaddisableder._modules[module.depends[j]];if(!dModule||dModule.status!=gloaddisableder.Module.IMPLEMENTED){continue MODULES;}}gloaddisableder.implement(module);gloaddisableder.resolve();}}},getRequests:function(m){var requests=[];REQUESTS:for(var i=0;i<gloaddisableder._requests.length;i++){var request=gloaddisableder._requests[i];for(var j=0;j<request.waits.length;j++){if(request.waits[j]==m.id){requests.push(request);break REQUESTS;}}}return requests;},toIds:function(lib){var result=[];for(var i=0;i<lib.length;i++){var mods=lib[i];var libName=mods.shift();var libVersion=mods.shift();var libId=libName+"/"+gloaddisableder.map.latest(libName,libVersion);result.push(libId+"/"+libName);for(var j=0;j<mods.length;j++){result.push(libId+"/"+mods[j]);}}return result;}};gloaddisableder.Request=function(r){this.waits=[];this.status=gloaddisableder.Request.INITIAL;if(r.onLoad){r.onloaddisabled=r.onLoad;}if(r.onTimeout){r.ontimeout=r.onTimeout;}if(!r.async&&!r.onloaddisabled){this.setGlobal=true;}this.async=(typeof r.async!="undefined")?r.async:false;this.onloaddisabled=r.onloaddisabled;if(r.ontimeout){if(typeof r.timeout=="undefined"){r.timeout=20000;}this.timeoutRef=setTimeout(r.ontimeout,r.timeout);}};gloaddisableder.Request.INITIAL=-1;gloaddisableder.Request.WAITING=0;gloaddisableder.Request.COMPLETED=1;gloaddisableder.Request.prototype.include=function(mId){for(var i=0;i<this.waits.length;i++){if(this.waits[i]==mId){return;}}this.waits.push(mId);};gloaddisableder.Request.prototype.release=function(mId){var implementCount=0;for(var i=0;i<this.waits.length;i++){var wModule=gloaddisableder._modules[this.waits[i]];if(wModule&&wModule.status==gloaddisableder.Module.IMPLEMENTED){implementCount++;}}if(implementCount==this.waits.length){this.complete();}};gloaddisableder.Request.prototype.complete=function(){if(this.setGlobal){for(var i=0;i<this.waits.length;i++){var gModule=gloaddisableder._modules[this.waits[i]];window[gModule.name]=gloaddisableder._modules[this.waits[i]].implementation;}}if(this.status==gloaddisableder.Request.COMPLETED){return;}this.status=gloaddisableder.Request.COMPLETED;if(this.timeoutRef){clearTimeout(this.timeoutRef);}for(var i=0;i<this.args.length;i++){this.args[i]=gloaddisableder._modules[this.args[i]].implementation;}if(this.onloaddisabled){this.onloaddisabled.apply(null,this.args);}};gloaddisableder.Module=function(mId){this.id=mId;this.name=mId.split("/").pop();this.status=gloaddisableder.Module.INITIAL;this.css=gloaddisableder.map.css[mId];};gloaddisableder.Module.INITIAL=-1;gloaddisableder.Module.REQUESTED=0;gloaddisableder.Module.FETCHED=1;gloaddisableder.Module.PROVIDED=2;gloaddisableder.Module.IMPLEMENTED=3;gloaddisableder.isReady=false;(function(){var d=document;if(
/*@cc_on!@*/
false){if(typeof window.frameElement!="undefined"){d.attachEvent("onreadystatechange",function(){if(d.readyState=="complete"){d.detachEvent("onreadystatechange",arguments.callee);gloaddisableder.isReady=true;}});}else{(function(){try{d.documentElement.doScroll("left");}catch(e){setTimeout(arguments.callee,50);return;}gloaddisableder.isReady=true;})();}}else{if(typeof d.readyState!="undefined"){var f=function(){/loaddisableded|complete/.test(d.readyState)?gloaddisableder.isReady=true:setTimeout(f,10);};f();}else{var callback=function(){if(arguments.callee.fired){return;}arguments.callee.fired=true;if(gloaddisableder){gloaddisableder.isReady=true;}};if(d.addEventListener){d.addEventListener("DOMContentLoaded",callback,false);}var oldOnloaddisabled=window.onloaddisabled;window.onloaddisabled=function(){if(oldOnloaddisabled){oldOnloaddisabled();}callback();};}}})();gloaddisableder.map.setProperties=function(libraryName,props){if(typeof gloaddisableder.mapProps=="undefined"){gloaddisableder.mapProps={};}if(typeof gloaddisableder.mapProps[libraryName]=="undefined"){gloaddisableder.mapProps[libraryName]={};}for(var p in props){gloaddisableder.mapProps[libraryName][p]=props[p];}};gloaddisableder.use=function(name,opts){name=(name||"glow");opts=(opts||{});var properties={};for(var opts_name in opts){var property_name=(opts_name.indexOf("$")==0)?opts_name:"$"+opts_name;properties[property_name]=opts[opts_name];}properties.$debug=(properties.$debug||"");properties.$base=(properties.$base||gloaddisableder._baseDir+name+"/{$version}/");properties.$map=(properties.$map||gloaddisableder._baseDir+name+"/map.js");gloaddisableder.map.setProperties(name,properties);gloaddisableder.map.include(properties.$map);};})();(function(){var scripts=document.getElementsByTagName("script");for(var i=scripts.length-1;i>=0;i--){var src=scripts[i].getAttribute("src");var filespec=gloaddisableder.util.getGloaddisablederFile(src);if(typeof filespec!="undefined"){gloaddisableder._baseDir=filespec.dir;var gloaddisablederScript=scripts[i].innerHTML;if(/\S/.test(gloaddisablederScript)){eval(gloaddisablederScript);}var mapped=false;for(var p in gloaddisableder.map._include){mapped=true;continue;}if(!mapped){gloaddisableder.use();}break;}}})();