/*
	Copyright 2010 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.
*/
Glow.provide(function(d){var b=d.NodeList,a=b.prototype,c;a.focusable=function(e){return new d.ui.Focusable(this,e);};});Glow.provide(function(a){a.ui=a.ui||{};});Glow.provide(function(b){function a(){}b.util.extend(a,b.events.Target);b.ui.Behaviour=a;});Glow.provide(function(l){var j,s,h=[],n,m,w=l(document),b=false;w.on("blur",function(A){n=j;if(h.length){setTimeout(k,0);}}).on("focus",function(A){if(m&&!m.container.contains(A.source)){(m.activeChild[0]||m.container[0]).focus();return false;}n=A.source;if(b){return;}b=true;d();setTimeout(p,0);});function p(){b=false;}function k(){!n&&d();}function d(){var B=h.slice(0),A=B.length;while(A--){B[A].active((n&&B[A].container.contains(n)&&n)||false);}}function u(A){A.children=A.container.get(A._opts.children);l(A.children).push(A.container).prop("tabIndex",-1);}function x(A,B){return function(C){switch(C.key){case"up":return !(B&&this.prev());case"left":return !(A&&this.prev());case"down":return !(B&&this.next());case"right":return !(A&&this.next());}};}var i={arrows:x(1,1),"arrows-x":x(1,0),"arrows-y":x(0,1)};function o(A){this._activeMethod="hover";this._activeEvent=A;this.active(A.source);this._activeEvent=this._activeMethod=j;}function t(C,A,B){return function(E){var D;C._activeMethod=A;C._activeEvent=E;D=B.apply(this,arguments);C._activeEvent=C._activeMethod=j;return D;};}function v(A,C){var B;C=this._opts=l.util.apply({children:"",keyboardNav:"arrows",setFocus:true,activeChildClass:"active"},C||{});this.container=l(A);B=C.keyboardNav;this._keyHandler=t(this,"key",(typeof B==="string"?i[B]:B));u(this);this.container[0].tabIndex=0;if(C.activateOnHover){this.container.on("mouseover",o,this);}this.container.on("click",y,this);h.push(this);}l.util.extend(v,l.ui.Behaviour);s=v.prototype;s._active=false;s._modal=false;s._disabled=false;s.activeChild=l();s.children=l();s.modal=function(A){if(A===j){return this._modal;}if(!this._disabled){if(A&&!this._modal){if(m){m.modal(false);}m=this;this.active(true);}else{if(!A&&this._modal){m=j;}}this._modal=!!A;}return this;};function q(F,A){var C=F.activeChild[0],B=F._opts.activeChildClass,E=F.activeChild=l(F.children[A]),D={item:E,itemIndex:A,method:F._activeMethod||"api",methodEvent:F._activeEvent};F.activeIndex=A;if(C===E||F.fire("childActivate",D).defaultPrevented()){return;}if(C){C.tabIndex=-1;l(C).removeClass(B);}F.activeChild[0].tabIndex=0;F.activeChild.addClass(B);F._opts.setFocus&&F.activeChild[0].focus();}function g(D,E){var B,A=D.children,C=A[0];if(!C){return -1;}E=l(E).item(0);if(E[0]){B=A.length;while(B--){if(l(A[B]).contains(E)){return B;}}}return -1;}function z(C,A){var B=C.children.length;if(C._opts.loop){A=A%B;if(A<0){A=B+A;}}else{A=Math.max(Math.min(A,B-1),0);}return A;}function e(A){if(A.fire("deactivate").defaultPrevented()){return;}A.activeChild.removeClass(A._opts.activeChildClass);A._lastActiveChild=A.activeChild[0];(A.activeChild[0]||A.container[0]).blur();A.activeIndex=j;A.activeChild=s.activeChild;A._active=false;w.detach("keypress",A._keyHandler).detach("keydown",a);A.container.prop("tabIndex",0);}function f(E,C){var B=E._active,D,A=-1;if(!B){if(E.fire("activate").defaultPrevented()){return;}u(E);E._active=true;w.on("keypress",E._keyHandler,E).on("keydown",a,E);D=true;}if(E.children[0]){if(typeof C==="number"){A=z(E,C);}else{if(typeof C!=="boolean"){A=g(E,C);}}if(A===-1&&!B){A=g(E,E._lastActiveChild);A=A!==-1?A:0;}}if(A!==-1&&A!==E.activeIndex){q(E,A);}else{if(D){E._opts.setFocus&&E.container[0].focus();}}}s.active=function(B){var A=this._active;if(B===j){return A;}if(!this._disabled){if(B===false){if(!this._modal&&A){e(this);}}else{f(this,B);}}return this;};function c(A){return function(){if(this._active){this.active(this.activeIndex+A);}return this;};}s.next=c(1);s.prev=c(-1);s.disabled=function(A){if(A===j){return this._disabled;}if(A){this.active(false);this._disabled=!!A;}else{this._disabled=!!A;if(this._modal){this.active(true);}}return this;};s.destroy=function(){var A=h.length;l.events.removeAllListeners([this]);this.modal(false).active(false).container.detach("mouseover",o).detach("click",y).prop("tabIndex",-1);this.container=j;while(A--){if(h[A]===this){h.splice(A,1);break;}}};function y(){if(this.activeChild[0]){return !this.fire("select",{item:this.activeChild,itemIndex:this.activeIndex}).defaultPrevented();}}function a(A){if(A.key==="return"){return y.call(this);}}l.ui.Focusable=v;});Glow.provide(function(e){var d,a;function c(f,g){this._name=f;this._locale="en";this.phase="constructed";this._observers=[];this._opts=g||{};}e.util.extend(c,e.events.Target);a=c.prototype;a._disabled=false;function b(f){if(f.disabled!==d){this.disabled(f.disabled);}else{if(f.destroy){this.destroy();}}}a._tie=function(){var g=Array.prototype.slice.call(arguments),f=g.length;while(f--){g[f].on("_sync",b);}this._observers=this._observers.concat(g);return this;};a._sync=function(f){e.events.fire(this._observers,"_sync",f||{});return this;};a.disabled=function(f){if(f===d){return this._disabled;}f=!!f;if(f!==this._disabled&&!this.fire("disabled",{disabled:f}).defaultPrevented()){this._sync({disabled:f});this._stateElm[f?"addClass":"removeClass"]("disabled");this._disabled=!!f;}return this;};a._init=function(){this.phase="initialised";};a._build=function(i){var f,g=this._name,h=this._opts;i=this.content=e(i||"<div></div>");f=this.container=e('<div class="glow200b1-'+g+'"><div class="'+g+'-theme"><div class="'+g+'-state"></div></div></div>');i.addClass(g+"-content").wrap(f);this._stateElm=i.parent();this._themeElm=this._stateElm.parent();if(h.className){f.addClass(h.className);}if(h.id){f[0].id=h.id;}this.phase="built";};a._bind=function(){this.phase="ready";};a._updateUi=function(){};a.destroy=function(){if(!this.fire("destroy").defaultPrevented()){this._sync({destroy:1});e.events.removeAllListeners([this]);this.container.destroy();this.phase="destroyed";}return this;};e.ui.Widget=c;});Glow.provide(function(m){var i,n=m.ui.Widget.prototype,e=0,d,a={};var c={SHOWING:2,SHOWN:1,HIDING:-1,HIDDEN:-2};function b(s,q){var p=this,o;q=m.util.apply({},q);b.base.call(this,"overlay",q);this.uid="overlayId_"+m.UID+"_"+(++e);a[this.uid]=this;this._init(q);this._build(s);this._bind();}m.util.extend(b,m.ui.Widget);i=b.prototype;i._init=function(){n._init.call(this);this.shown=false;return this;};i.destroy=function(){n.destroy.call(this);delete a[this.uid];};i._build=function(p){var o=this;n._build.call(this,p);if(this._opts.hideWhenShown===d){ua=navigator.userAgent;this._whatToHide=(m.env.opera&&!/macintosh/i.test(ua)||/rv:1\.9\.0.*\bgecko\//i.test(ua)||m.env.webkit&&!/macintosh/i.test(ua))?function(){return m("object, embed");}:function(){return m();};}else{if(!this._opts.hideWhenShown){this._whatToHide=function(){return m();};}else{if(typeof this._opts.hideWhenShown==="function"){this._whatToHide=this._opts.hideWhenShown;}else{if(this._opts.hideWhenShown.length!==d){this._whatToHide=function(){return m("*").filter(this._opts.hideWhenShown);};}}}}if(m.env.ie){this._iframe=m('<iframe src="javascript:\'\'" style="display:block;width:100%;height:1000px;margin:0;padding:0;border:none;position:absolute;top:0;left:0;filter:alpha(opacity=0);"></iframe>');this._iframe.css("z-index",0);this._iframe.insertBefore(this.content);}this.content.css("position","relative").css("z-index",1).css("top",0).css("left",0);return this;};i.hideFlash=function(){var p,s=this,t="";p=this._whatToHide();for(var q=0,o=p.length;q<o;q++){t=(p.item(q).data("overlayHidBy")||"");if(t===""){p.item(q).data("overlayOrigVisibility",p.item(q).css("visibility"));p.item(q).css("visibility","hidden");}if(t.indexOf("["+this.uid+"]")===-1){p.item(q).data("overlayHidBy",t+"["+this.uid+"]");}}if(p.length&&!s._doShowFlash){s._doShowFlash=true;s.on("afterHide",function(){s.showFlash();});}this._hiddenElements=p;};i.showFlash=function(){var s="";if(!this._hiddenElements||this._hiddenElements.length===0){return;}var o=this._hiddenElements;for(var q=0,p=o.length;q<p;q++){s=(o.item(q).data("overlayHidBy")||"");if(s.indexOf("["+this.uid+"]")>-1){s=s.replace("["+this.uid+"]","");o.item(q).data("overlayHidBy",s);}if(s==""){o.item(q).css("visibility",o.item(q).data("overlayOrigVisibility"));}}};var j={slide:[function(o){o.container.height(0);},function(p,s){var q,o=this.container;if(p){q=o.slideOpen(0.5).data("glow_slideOpen");}else{q=o.slideShut(0.5).data("glow_slideShut");}q.on("complete",s);}],fade:[function(o){o.container.css("opacity",0);},function(p,s){var q,o=this.container;if(p){q=o.fadeIn(0.5).data("glow_fadeIn");}else{q=o.fadeOut(0.5).data("glow_fadeOut");}q.on("complete",s);}]};i.setAnim=function(o){if(o===null){delete this._animDef;delete this._animator;}else{if(typeof o==="string"){j[o][0](this);this._animator=j[o][1];}else{if(typeof o==="function"){this._animator=o;}else{this._animDef=o;this._animDef[2]=this._animDef[2]||{};this._animDef[2].destroyOnComplete=false;}}}return this;};i.show=function(o){var p=this;if(!this.fire("show").defaultPrevented()){if(this._timer){clearTimeout(this._timer);}if(o){this._timer=setTimeout(function(){l.call(p);},o*1000);}else{l.call(p);}}return this;};function l(){var o=this;if(this.state===c.SHOWING||this.state===c.SHOWN){return;}f(o,true);if(this._whatToHide){this.hideFlash();}if(this._animator){o.state=c.SHOWING;this._animator.call(this,true,function(){k.call(o);});}else{if(this._animDef){if(this._anim){this.state=c.SHOWING;this._anim.reverse();}else{this.state=c.SHOWING;this._anim=this.container.anim(this._animDef[0],this._animDef[1],this._animDef[2]);this._anim.on("complete",function(){if(o.state===c.SHOWING){f(o,true);k.call(o);}else{if(o.state===c.HIDING){f(o,false);g.call(o);}}});}this._anim.start();}else{k.call(this);}}}function k(){this.state=c.SHOWN;this.fire("afterShow");}function f(p,o){var q=p._stateElm;p.shown=o;if(o){q.removeClass("hidden");q.addClass("shown");}else{q.removeClass("shown");q.addClass("hidden");}}function h(){var o=this;if(this.state===c.HIDING||this.state===c.HIDDEN){return;}if(this._animator){this._animator.call(this,false,function(){f(o,false);g.call(o);});}else{if(this._anim){this.state=c.HIDING;this._anim.reverse();this._anim.start();}else{f(o,false);g.call(this);}}}function g(){this.state=c.HIDDEN;this.fire("afterHide");}i.hide=function(o){var p=this;if(!this.fire("hide").defaultPrevented()){if(this._timer){clearTimeout(this._timer);}if(o){this._timer=setTimeout(function(){h.call(p);},o*1000);}else{h.call(p);}}return this;};m.ui=m.ui||{};m.ui.Overlay=b;});Glow.provide(function(h){var b,m,f=h.ui.Widget,i=f.prototype,p=h("<div></div>");function c(q){q=h.util.apply({minLength:3,keyboardNav:"arrows-y",activateFirst:true},q);f.call(this,"AutoSuggest",q);this._init();}h.util.extend(c,f);m=c.prototype;m._data=[];m._filter=function(t,q){var s=this.name.slice(0,t.length);s=q?s:s.toLowerCase();return s===t;};m._format=function(q,v){var u=p.text(q.name).html(),t=u.toLowerCase().indexOf(v.toLowerCase()),s=t+v.length;if(t!==-1){u=u.slice(0,t)+'<em class="AutoSuggest-match">'+u.slice(t,s)+"</em>"+u.slice(s);}return u;};m._init=function(){i._init.call(this);this._build();};m._build=function(){i._build.call(this,"<ol></ol>");var s=this._opts,q=s.width;content=this.content;this.focusable=content.focusable({children:"> li",keyboardNav:this._opts.keyboardNav,setFocus:false,activateOnHover:true});q&&this.container.width(q);this._bind();};function g(q){return !this.fire("select",{li:q.item,item:q.item.data("as_data")}).defaultPrevented();}function j(s){var q=s.item,t=this.focusable;}function a(){return false;}m._bind=function(){var q=this.focusable.on("select",g,this).on("childActivate",j,this);this._tie(q);this.container.on("mousedown",a);i._bind.call(this);};m.setFilter=function(q){this._filter=q;return this;};m.setFormat=function(q){this._format=q;return this;};function e(u,v){var q,t,s=u.fire("data",{data:v});if(!s.defaultPrevented()){v=s.data;if(v instanceof h.net.XhrResponse){v=v.json();}if(typeof v[0]==="string"){t=[];q=v.length;while(q--){t[q]={name:v[q]};}v=t;}u._data=v;}}function l(s,q){s._dataFunc=function(w){var t=s.input,v=s._bindOpts,u=(v&&v.loadingClass)||"";s._loading=true;t.addClass(u);q.call(this,w,function(y){var x=s._pendingFind;s._loading=false;t.removeClass(u);y&&e(s,y);if(x){k(s,x);s._pendingFind=b;}});};}function o(q){var t,s;return function(u,v){if(t){return v();}if(!s){s=h.net.get(q).on("load",function(w){t=1;v(w);});}};}function d(q){var s;return function(u,v){var t=h.util.interpolate(q,{val:u});s&&s.abort();s=h.net.get(t).on("load",function(w){v(w);});};}m.data=function(q){if(typeof q==="string"){if(q.indexOf("{val}")===-1){q=o(q);}else{q=d(q);}}if(typeof q==="function"){l(this,q);}else{if(q.push){this._dataFunc=b;e(this,q);}}return this;};function n(z,u,t){var x=z.content,A=u.length,v=A,s,w,q=z._opts,y=z.focusable;y.active(false);if(!A&&z.overlay){z._hideOverlay();return;}x.children().destroy();while(v--){w=z._format(u[v],t);s=h('<li class="AutoSuggest-item"></li>').data("as_data",u[v]).prependTo(x);(typeof w==="string")?s.html(w):s.append(w);}if(A){q.activateFirst&&y.active(true);z._showOverlay();}else{z._hideOverlay();}}function k(A,x){var z=[],s=0,u=A._data,w=A.fire("find",{val:x}),q,y=A._opts.caseSensitive;if(!w.defaultPrevented()){x=w.val;x=y?x:x.toLowerCase();for(var t=0,v=u.length;t<v;t++){if(A._filter.call(u[t],x,y)){z[s++]=u[t];if(s===A._opts.maxResults){break;}}}q=A.fire("results",{results:z});if(q.defaultPrevented()){z=[];}else{z=q.results;}n(A,z,w.val);}}m.find=function(q){if(q.length>=this._opts.minLength){this._dataFunc&&this._dataFunc(q);if(this._loading){this._pendingFind=q;}else{k(this,q);}}else{this.hide();}return this;};m.hide=function(){clearTimeout(this._inputTimeout);n(this,[],"");return this;};m.destroy=function(){this._data=b;this.input.detach("keypress",this._inputPress).detach("blur",this._inputBlur).detach("onbeforedeactivate",this._inputDeact);i.destroy.call(this);};h.ui.AutoSuggest=c;});Glow.provide(function(i){var c,n=i.ui.AutoSuggest.prototype;n.input=i();function o(t){var q=this,v=q.focusable,w,s=v.activeIndex,u;if(t.keyChar||t.key==="delete"||t.key==="backspace"){clearTimeout(q._inputTimeout);q._inputTimeout=setTimeout(function(){q.find(m(q));},q._bindOpts.delay*1000);}else{w=v.active();switch(t.key){case"escape":q.hide();f(q);return false;case"up":if(w&&!s){v.active(false);f(q);return false;}case"down":if(!w&&(u=q.content.children().length)){v.active(t.key=="up"?u-1:0);t.stopPropagation();return false;}}}}n._inputPress=o;function m(u){var s=u.input,w=u._bindOpts.delim,v=s.val(),q,t;if(w){t=a(u);v=v.slice(0,t);q=v.lastIndexOf(w);if(q!==-1){v=v.slice(v.lastIndexOf(w)+w.length);}}return i.util.trim(v);}function h(){this.hide();}n._inputBlur=h;function p(q){if(this.container.contains(q.related)){return false;}}n._inputDeact=p;function j(q){g(this.hide(),q.item.name);e(this,this.input.val().length);}function l(q){if(q.method!=="hover"){g(this,q.item.data("as_data").name,true);}}function g(B,t,y){f(B);var x=B.input,z=x.val(),v=a(B),A=v,q=t.length,s=B._bindOpts.delim,w,u="";if(s){w=z.slice(0,v).lastIndexOf(s);if(w!==-1){u=z.slice(0,w)+s+" ";}t=u+t+s+" ";q=t.length;t+=z.slice(v);}x.val(t);y&&e(B,A,q);}function e(u,w,q){q=(q===c)?w:q;var t=u.input[0],v="character",s;if(!window.opera&&t.createTextRange){s=t.createTextRange();s.moveStart(v,w);s.moveEnd(v,q-t.value.length);s.select();}else{t.select();t.selectionStart=w;t.selectionEnd=q;}}function a(t){var q=t.input[0],s;if(i.env.ie){range=document.selection.createRange();range.collapse();range.setEndPoint("StartToStart",q.createTextRange());s=range.text.length;}else{s=q.selectionStart;}return s;}function f(s){var q=s.input[0],u=q.value,t;if(i.env.ie){document.selection.createRange().text="";}else{t=q.selectionStart;q.value=u.slice(0,t)+u.slice(q.selectionEnd);q.selectionStart=t;}}n._showOverlay=function(){var s=this.overlay,v=this._opts,u=this._bindOpts,q=this.input,t;if(!s){return;}if(!v.width){this.container.width(q[0].offsetWidth);}if(u.autoPosition){t=q.offset();s.container.css({top:t.top+q[0].offsetHeight,left:t.left});}s.show();};n._hideOverlay=function(){var q=this.overlay;q&&q.hide();};n.bindInput=function(s,v){var w=this._bindOpts=i.util.apply({autoPosition:true,autoComplete:true,delay:0.5,loadingClass:"glow200b1-AutoSuggest-loading"},v),u=w.appendTo,q=this.container,t,x=this._opts;this.input=i(s).attr("autocomplete","off").on("keypress",o,this).on("blur",h,this).on("beforedeactivate",p,this);if(w.autoComplete){this.on("select",j,this).focusable.on("childActivate",l,this);}if(u){i(u).append(q);}else{this.overlay=t=new i.ui.Overlay(q).on("hide",b,this).on("afterShow",k,this).hide();this.focusable.disabled(true);t.container.appendTo(document.body);if(w.anim==="slide"){w.anim=d;}w.anim&&t.setAnim(w.anim);this._tie(t);}return this;};function d(s,v){var u,q=this.container,t={lockToBottom:true};if(s){q.height(0);u=q.slideOpen(0.5,t).data("glow_slideOpen");}else{u=q.slideShut(0.5,t).data("glow_slideShut");}u.on("complete",v);}function b(){this.focusable.disabled(true);}function k(){var q=this.focusable;q.disabled(false);if(this._opts.activateFirst){q.active(true);}}});Glow.provide(function(f){var e,b,h=f.ui.Widget.prototype;function s(w,y){var x=this;y=f.util.apply({duration:0.2,tween:"easeBoth",step:1,loop:false,page:false,axis:"x"},y||{});f.ui.Widget.call(this,"CarouselPane",y);if(f(w).length>0){this._init(w,y);}}f.util.extend(s,f.ui.Widget);b=s.prototype;function n(x){var z;this.range={min:0,max:0};this.items={};this.meta={};for(var y=0,w=x.length;y<w;y++){this.addItem(y,x.item(y));}}n.prototype.addItem=function(w,x,y){this.range.min=Math.min(this.range.min,w);this.range.max=Math.max(this.range.max,w);this.items[w]=x;this.meta[w]=y||{};};n.prototype.addMeta=function(w,x){if(this.meta[w]){this.meta[w]=f.util.apply(this.meta[w],x);}};n.prototype.place=function(y,x){for(var w in this.items){if(y!==e){this.items[w].css("top",y);}this.items[w].css("left",(x===e)?this.meta[w].offset:x);}};n.prototype.dump=function(y){if(typeof console!=="undefined"){for(var x=y._itemList.range.min,w=y._itemList.range.max;x<=w;x++){if(y._itemList.meta[x]){console.log(">> "+x+": "+(y._itemList.meta[x].isClone?"clone":"real")+" at "+y._itemList.meta[x].offset+" "+y._itemList.items[x][0].children[0].alt);}else{console.log(">> "+x+": "+y._itemList.meta[x]);}}}};n.prototype.swap=function(x,w){this.items[x].css("left",this.meta[w].offset);this.items[w].css("left",this.meta[x].offset);};b._init=function(w){h._init.call(this);this._step=this._opts.step;this._geom=(this._opts.axis==="y")?["height","top"]:["width","left"];this.stage=f(w).item(0);this._focusable=this.stage.focusable({children:"> *",loop:true,setFocus:true});this._viewport=f('<div class="CarouselPane-viewport"></div>');f(this.stage).wrap(this._viewport);this.items=this.stage.children();this._itemList=new n(this.items);if(this._opts.spotlight>this.items.length){this._opts.spotlight=this.items.length;}this._index=0;this._build();};b._build=function(){h._build.call(this,this._viewport);this.stage.css({margin:0,listStyleType:"none"});this.items.css({position:"absolute","z-index":2});this._itemDimensions=j(this.items);this.items.css({margin:0,width:this._itemDimensions.innerWidth,height:this._itemDimensions.innerHeight});this._wingSize=Math.ceil(this.items.length*this._itemDimensions[this._geom[0]]*1.5);this._viewport.css({overflow:"scroll",overflowX:"hidden",overflowY:"hidden",position:"relative",padding:0,margin:0,width:this._opts.axis==="x"?"100%":this._itemDimensions.width,height:this._opts.axis==="y"?"100%":this._itemDimensions.height});this._spot=s._getSpot(this._viewport.width(),this.items,this._itemDimensions,this._opts);if(this._opts.step===true){this._step=this._spot.capacity;}else{if(this._opts.step>this._spot.capacity){this._step=this._spot.capacity;}}if(this._opts.page&&this._step!==this._spot.capacity){this._step=this._spot.capacity;}this._gap=a(this);this.stage.css({width:this.stage.width()+this._wingSize*2,height:"100%"});t.call(this);this._bind();p.call(this);};function a(w){var y={size:0,count:0},x=w.items.length%w._step;if(w._opts.page&&w._step>1){y.count=x?w._spot.capacity-x:0;y.size=y.count*w._itemDimensions[w._geom[0]];}return y;}b._bind=function(){var w=this;h._bind.call(w);q(w,w._focusable,"childActivate",function(A){var z=A.itemIndex,y=w.spotlightIndexes(true),x=(" "+y.join(" ")+" ").indexOf(" "+z+" ")>-1;if(z!==e&&!x){w.moveTo(z,{tween:""});w._index=z;}});this._focusable.on("select",function(x){x.itemIndex=x.item.data("itemIndex");w.fire("select",x);});};function q(w,z,x,y){z.on(x,y);w._addedEvents=w._addedEvents||[];w._addedEvents.push({target:z,name:x,handler:y});}function i(w){var x=w._addedEvents?w._addedEvents.length:0,y;while(x--){y=w._addedEvents[x];y.target.detach(y.name,y.handler);}}b.updateUi=function(){h._updateUi.call(this);this.stage.css({width:this.stage.width()+this._wingSize*2,height:"100%"});this._spot=s._getSpot(this._viewport.width(),this.items,this._itemDimensions,this._opts);if(this._opts.step===true){this._step=this._spot.capacity;}t.call(this);this._index=0;this.fire("updateUi",{});};b.moveStop=function(){this._gliderBrake=true;};b.moveStart=function(x){var y=(x?-1:1)*this._step,w=this;if(!w._inMotion){w._gliderBrake=false;w.moveTo(w._index+y,{callback:function(){if(!w._gliderBrake){if(w._opts.loop||((x&&w._index>0)||(!x&&w._index+w._spot.capacity<w.items.length))){if(w._step===1){m.call(w,x);}else{w.moveStart(x);}}}}});}return w;};b.moveToggle=function(w){if(this._inMotion&&!this._gliderBrake){this.moveStop();}else{this.moveStart(w);}return this;};var m=function(F){var x=(F?-1:1),w=[],y=this.content[0].scrollLeft,A=this._itemDimensions[this._geom[0]],D,E,B=this,C,H=y+(F?-this._index*A:(this.items.length-this._index)*A);k.call(this,"back");for(var z=0,G=this.items.length;z<G;z+=this._step){D=y+x*z*A;E=y+x*(z+this._step)*A;if((F&&D===H)||(!F&&E===H)){y-=x*this.items.length*A;}C=this.content.anim(this._opts.duration,{scrollLeft:[D,E]},{tween:"linear",startNow:false}).on("start",function(){v.call(B);if(B.fire("move",{moveBy:x,currentIndex:B._index}).defaultPrevented()){o.call(B);}}).on("complete",function(){B._index+=x;if(B._gliderBrake||(!B._opts.loop&&(B._index+B._spot.capacity===B.items.length||B._index===0))){o.call(B);B.fire("afterMove",{currentIndex:B._index});}});w.push(C);}this._glider=new f.anim.Timeline({loop:true});f.anim.Timeline.prototype.track.apply(this._glider,w);this._inMotion=true;this._gliderBrake=false;this._glider.start();};function v(w){if(w!==e){this._index=w;}this._index=this._index%this.items.length;while(this._index<0){this._index+=this.items.length;}return this._index;}function l(w){return v.call(this,this._index+=w);}function o(){this._glider.stop();this._glider.destroy();this._inMotion=false;this._index=p.call(this);d.call(this);k.call(this);}b.spotlightIndexes=function(B){var z=[],x=p.call(this),y,w=(this._opts.loop)?this._spot.capacity:Math.min(this._spot.capacity,this.items.length);for(var A=0;A<w;A++){y=B?(x+A):(x+A)%(this.items.length+this._gap.count);if(y>=this.items.length||y<0){continue;}z.push(y);}return z;};b.spotlightItems=function(){var x=f(),y=this.spotlightIndexes();for(var z=0,w=y.length;z<w;z++){x.push(this.items[y[z]]);}return x;};function p(){var w=this.content[0].scrollLeft-(this._wingSize+this._spot.offset.left);w+=this._spot.offset.left;w/=this._itemDimensions.width;return w;}b.moveTo=function(z,B){var x,w,y,C;if(this._inMotion){return false;}B=B||{};if(!this._opts.loop&&z>this.items.length-this._spot.capacity){z=this.items.length-this._spot.capacity+(this._opts.page?this._gap.count:0);}else{if(!this._opts.loop&&z<0){z=0;}}x=(z!==this._index&&c.call(this,z));if(!B.jump){var D=new f.events.Event({currentIndex:this._index,moveBy:(this._index<z)?(z-this._index):(-Math.abs(this._index-z))});if(!B.jump&&x&&this.fire("move",D).defaultPrevented()){return this;}else{z=this._index+D.moveBy;}}if(this._opts.page){z=Math.floor(z/this._step)*this._step;}if(z>this.items.length+this._step||z<0-this._step){z=this._index+(this._index<z)?-this._step:this._step;}w=this._wingSize+z*this._itemDimensions.width;k.call(this,"back");y=B.tween||this._opts.tween;var A=this;if(B.jump===true||B.tween===""){this.content[0].scrollLeft=w;this._index=z;d.call(this);k.call(this);this._index=this._index%(this.items.length+this._gap.count);if(!B.jump&&x){this.fire("afterMove",{currentIndex:this._index});}this._inMotion=false;}else{if(x){this._inMotion=true;C=this.content.anim(this._opts.duration,{scrollLeft:w},{tween:B.tween||this._opts.tween});this._index=z;C.on("complete",function(){A._inMotion=false;d.call(A);k.call(A);A._index=A._index%(A.items.length+A._gap.count);A.fire("afterMove",{currentIndex:A._index});if(B.callback){B.callback();}});}}return this;};function d(){if(this._index<0){this.moveTo(this.items.length+this._gap.count+this._index,{jump:true});}else{if(this._index>=this.items.length){this.moveTo(this._index-(this.items.length+this._gap.count),{jump:true});}}}function k(y){var w;if(!this._opts.loop){return;}if(y){this._itemList.place();}else{for(var z=0,x=this._spot.capacity-this._gap.count;z<x;z++){w=(this._index+z);if(w>=this.items.length){this._itemList.swap(w,w%this.items.length);}}}}b.moveBy=function(w){this.moveTo(this._index+w);return this;};b.next=function(){this.moveTo(this._index+this._step);return this;};b.prev=function(){this.moveTo(this._index-this._step);return this;};function c(w){if(this._opts.loop){return true;}if(w<0){return false;}if(w-this._step>=this.items.length-this._spot.capacity){return false;}return true;}function j(E){var z,x=0,y=0,F=0,G=0,B=0,D=0,A=0,w=0,C=0;E.each(function(){z=f(this);G=Math.max(this.offsetHeight,G);F=Math.max(this.offsetWidth,F);x=Math.max(z.width(),x);y=Math.max(z.height(),y);D=Math.max(g(z.css("margin-right")),D);A=Math.max(g(z.css("margin-left")),A);w=Math.max(g(z.css("margin-top")),w);C=Math.max(g(z.css("margin-bottom")),C);});B=Math.max(A,D);return{width:F+B,height:G+w+C,innerWidth:x,innerHeight:y,marginLeft:A,marginRight:D,marginTop:w,marginBottom:C};}function g(w){if(w==="auto"){return 0;}else{return parseInt(w);}}s._getSpot=function(w,x,y,A){var z={capacity:0,top:0,left:0,width:0,height:0,offset:{top:0,right:0,bottom:0,left:0}},A=A||{};if(!y){y=j(x);}if(A.axis="x"){if(x.length===0){z.capacity=0;}else{if(A.spotlight){if(A.spotlight>x.length){throw new Error("spotlight cannot be larger than item count.");}z.capacity=A.spotlight;}else{z.capacity=Math.floor(w/y.width);}}if(z.capacity>x.length){z.capacity=x.length;}z.width=z.capacity*y.width+Math.min(y.marginLeft,y.marginRight);z.height=y.height;z.offset.left=Math.floor((w-z.width)/2);z.offset.right=w-(z.offset.left+z.width);}else{throw Error("y axis (vertical) not yet implemented");}return z;};function u(x){position={top:0,left:0};var w=this._itemDimensions.width,y=this._spot.offset.left+this._wingSize+this._itemDimensions.marginLeft,z=0;if(this._opts.page&&x<0){z=-(1+Math.floor(Math.abs(x+this._gap.count)/this.items.length))*this._gap.count*w;}else{if(this._opts.page&&x>=this.items.length){z=Math.floor(x/this.items.length)*this._gap.count*w;}}position.left=y+(x*w)+z;position.top=this._itemDimensions.marginTop;return position;}function t(){var B,A;this.content[0].scrollLeft=this._wingSize;for(var y=0,x=this.items.length;y<x;y++){this._itemList.addMeta(y,{offset:u.call(this,y).left,isClone:false});this.items.item(y).data("itemIndex",+y);}if(this._opts.loop){this.stage.get(".carousel-clone").remove();var z=1+Math.ceil(this._spot.offset.left/(this._itemDimensions.width*this.items.length+this._gap.size));for(var w=1;w<=z;w++){y=this.items.length;while(y--){B=this.items.item(y).copy();B.removeClass("carousel-item").addClass("carousel-clone").css({"z-index":1,margin:0});A=u.call(this,0-(w*this.items.length-y)).left;this._itemList.addItem(0-(w*this.items.length-y),B,{isClone:true,offset:A});this.stage[0].appendChild(B[0]);B=B.copy();A=u.call(this,w*this.items.length+y).left;this._itemList.addItem(w*this.items.length+y+this._gap.count,B,{isClone:true,offset:A});this.stage[0].appendChild(B[0]);}}}this.items.addClass("carousel-item");this._itemList.place(this._itemDimensions.marginTop,e);}b.destroy=function(){this.stage.get(".carousel-clone").remove();i(this);this.stage.insertBefore(this.container).children().css("position","");h.destroy.call(this);};f.ui.CarouselPane=s;});Glow.provide(function(k){var d,g,j=k.ui.Widget,l=j.prototype;function i(o,q){var p;j.call(this,"Carousel",q);q=this._opts;if(q.page){q.step=q.page;q.page=true;}this.itemContainer=o=k(o).item(0);p=k.ui.CarouselPane._getSpot(o.parent().width(),o.children().css("position","absolute"),0,q);if(p.offset.left<50){q.spotlight=p.capacity-1;}this._init();}k.util.extend(i,k.ui.Widget);g=i.prototype;g._init=function(){l._init.call(this);this._build();};g._build=function(){var s,p=this.itemContainer,t,o,q;l._build.call(this,p.wrap("<div></div>").parent());s=this.content;t=this._pane=new k.ui.CarouselPane(p,this._opts);q=t._spot;o=this.items=t.items;this.itemContainer=t.itemContainer;t.moveTo(0,{tween:null});this._prevBtn=k('<div class="Carousel-prev"><div class="Carousel-btnIcon"></div></div>').prependTo(s).css({width:q.offset.left,height:q.height});this._nextBtn=k('<div class="Carousel-next"><div class="Carousel-btnIcon"></div></div>').prependTo(s).css({width:q.offset.right,height:q.height});m(this);this._bind();};function m(q){if(q._opts.loop){return;}var o=q.spotlightIndexes(),s=o[o.length-1],p=q.items.length-1;q._prevBtn[(o[0]===0)?"addClass":"removeClass"]("Carousel-prev-disabled");q._nextBtn[(s===p)?"addClass":"removeClass"]("Carousel-next-disabled");}function a(o){this.fire("select",o);}function b(o){var p=this._pane;if(!this.fire("move",o).defaultPrevented()){this._updateNav((p._index+o.moveBy)%this.items.length/p._step);}}function f(o){if(!this.fire("afterMove",o).defaultPrevented()){m(this);}}function c(o){if(o.button===0){this._pane.moveStart(true);return false;}}function n(o){if(o.button===0){this._pane.moveStart();return false;}}function h(){this._pane.moveStop();}g._bind=function(){var p=this._pane,o=this;this._tie(p);p.on("select",a,this).on("afterMove",f,this).on("move",b,this);this._prevBtn.on("mousedown",c,this).on("mouseup",h,this).on("mouseleave",h,this);this._nextBtn.on("mousedown",n,this).on("mouseup",h,this).on("mouseleave",h,this);l._bind.call(this);};g.spotlightItems=function(){return this._pane.spotlightItems();};g.spotlightIndexes=function(){return this._pane.spotlightIndexes();};g.moveTo=function(p,o){this._pane.moveTo(p,o);return this;};function e(o){return function(){this._pane.moveBy(this._pane._step*o);return this;};}g.next=e(1);g.prev=e(-1);g.destroy=function(){this._pane.container.insertBefore(this.container);l.destroy.call(this);};k.ui.Carousel=i;});Glow.provide(function(f){var e,a=f.ui.Carousel.prototype;a.addPageNav=function(h){h=f.util.apply({position:"belowLast"},h);var g="Carousel-pageNav";if(h.useNumbers){g+="Numbers";}this._pageNav=f('<div class="'+g+'"></div>').delegate("click","div",d,this);this._pageNavOpts=h;b(this);return this;};function d(g){var h=(f(g.attachedTo).text()-1)*this._pane._step;this.moveTo(h);}function c(i){var j=i._pane,g=i.items.length,h=j._step;if(i._opts.loop){r=Math.ceil(g/h);}else{r=1+Math.ceil((g-j._spot.capacity)/h);}return Math.max(r,0);}function b(k){var h=k._pageNav,g=k._pageNavOpts.position,i=g.slice(0,5),j=g.slice(5),n=k._pane,m=c(k),l="";k.container[(i==="below")?"append":"prepend"](h);h.css("text-align",(j=="Middle")?"center":"right");if(j==="Last"){h.css("margin-right",k._nextBtn.width()+n._itemDimensions.marginRight);}do{l="<div>"+m+"</div>"+l;}while(--m);h.html(l);k._updateNav(n._index/n._step);}a._updateNav=function(g){if(this._pageNav){var h="active";this._pageNav.children().removeClass(h).item(g).addClass(h);}};});Glow.complete("ui","2.0.0b1");
