var ShadowedPopup=new Class({Extends:Platform.Popup,shadowRatios:[29/640,24/480,698/640,538/480],initialize:function(a){this.parent("shadowedPopup");this.view.addClass(a);this.shadow=this.view.insertBefore(new Element("img",{src:"/m/images/shadow.png"}).addClass("shadow"),this.view.firstChild)},adjust:function(){this.parent();this.adjustShadow()},adjustShadow:function(){this.shadow.style.left=Math.round(-this.view.offsetWidth*this.shadowRatios[0])+"px";this.shadow.style.top=Math.round(-this.view.offsetHeight*this.shadowRatios[1])+"px";this.shadow.style.width=Math.round(this.view.offsetWidth*this.shadowRatios[2])+"px";this.shadow.style.height=Math.round(this.view.offsetHeight*this.shadowRatios[3])+"px"}});if(window.delayed){for(var fct,i=0;fct=window.delayed[i];i++){fct()}}MooTools.More={version:"1.2.2.1"};Fx.Scroll=new Class({Extends:Fx,options:{offset:{x:0,y:0},wheelStops:true},initialize:function(b,a){this.element=this.subject=$(b);this.parent(a);var d=this.cancel.bind(this,false);if($type(this.element)!="element"){this.element=$(this.element.getDocument().body)}var c=this.element;if(this.options.wheelStops){this.addEvent("start",function(){c.addEvent("mousewheel",d)},true);this.addEvent("complete",function(){c.removeEvent("mousewheel",d)},true)}},set:function(){var a=Array.flatten(arguments);this.element.scrollTo(a[0],a[1])},compute:function(c,b,a){return[0,1].map(function(d){return Fx.compute(c[d],b[d],a)})},start:function(c,h){if(!this.check(c,h)){return this}var e=this.element.getSize(),f=this.element.getScrollSize();var b=this.element.getScroll(),d={x:c,y:h};for(var g in d){var a=f[g]-e[g];if($chk(d[g])){d[g]=($type(d[g])=="number")?d[g].limit(0,a):a}else{d[g]=b[g]}d[g]+=this.options.offset[g]}return this.parent([b.x,b.y],[d.x,d.y])},toTop:function(){return this.start(false,0)},toLeft:function(){return this.start(0,false)},toRight:function(){return this.start("right",false)},toBottom:function(){return this.start(false,"bottom")},toElement:function(b){var a=$(b).getPosition(this.element);return this.start(a.x,a.y)}});Wikipediator=new Class({initialize:function(a){this.view=a;this.buffer=[];this.count={};this.input=a.getElement("input");this.status=a.getElement(".status");this.board=a.getElement(".board");this.board.fx=new Fx.Scroll(this.board,{duration:1000});this.popup=new WikipediatorPopup(a.getElement(".core"));this.nextBtn=a.getElement(".next");this.nextBtn.addEvent("click",this.showNextPage.bind(this));this.prevBtn=a.getElement(".prev");this.prevBtn.addEvent("click",this.showPreviousPage.bind(this));this.input.addEvent("keyup",function(){clearTimeout(this.searchTimer);this.searchTimer=setTimeout(function(){this.search(this.input.value,true)}.bind(this),200)}.bind(this))},load:function(a){new Request.JSON({method:"get",url:"./load/"+a+"/300/",onComplete:this.store.bind(this)}).send()},store:function(b){this.buffer=this.buffer.concat(b.results);var a=this.buffer.length;if(b.count>a){this.load(a)}this.search(this.input.value,true)},search:function(g,c){if(c){this.board.scrollTop=0;this.bufferIndex=0;this.lastComputedPage=0;this.currentPage=0;this.hitAnchor=undefined}this.count.visibles=0;this.count.more=0;var f;try{f=new RegExp(g,"i")}catch(h){f=new RegExp("___")}var b=this.bufferIndex;var d;while(this.count.visibles<20&&(d=this.buffer[b++])){if(d.title.search(f)>=0){if(!d.view){d.view=this.buildHit(d);var a=this.hitAnchor?this.hitAnchor.nextSibling:this.board.firstChild;this.board[a?"insertBefore":"appendChild"](d.view,a)}else{d.view.show()}this.hitAnchor=d.view;this.count.visibles++}else{if(d.view){d.view.hide();this.hitAnchor=d.view}}}this.lastComputedPage=this.currentPage;this.bufferIndex=b;while(d=this.buffer[b++]){if(d.title.search(f)>=0){this.count.more++}if(d.view){d.view.hide()}}this.query=g;this.refresh()},showNextPage:function(){if(!this.count.more){return}this.currentPage++;if(this.currentPage>this.lastComputedPage){this.search(this.query)}else{this.count.visibles=Math.min(20,this.count.more);this.count.more-=this.count.visibles;this.refresh()}this.board.fx.cancel();this.board.fx.start(0,this.currentPage*this.board.offsetHeight)},showPreviousPage:function(){if(!this.currentPage){return}this.currentPage--;this.count.more+=this.count.visibles;this.count.visibles=20;this.refresh();this.board.fx.cancel();this.board.fx.start(0,this.currentPage*this.board.offsetHeight)},refresh:function(){if(this.count.visibles){this.view.removeClass("noResults");start=this.currentPage*20;last=start+this.count.visibles;this.status.innerHTML="Showing "+(start+1)+" - "+(last)+" of "+(last+this.count.more)}else{this.view.addClass("noResults");this.status.innerHTML=""}this.prevBtn[this.currentPage?"addClass":"removeClass"]("active");this.nextBtn[this.count.more?"addClass":"removeClass"]("active")},buildHit:function(c){var b=new Element("div").addClass("hit buzy");c.thumbUrl=Wikipediator.MEDIA_ROOT+c.id+"/iphone/thumb.jpg";c.videoUrl=Wikipediator.MEDIA_ROOT+c.id+"/iphone/movie.mp4";c.definitionUrl=Wikipediator.DEFINITION_ROOT+c.id+"/definition";var a=b.appendChild(new Element("img",{title:c.snippet}));a.addEvent("load",function(){b.removeClass("buzy")});a.src=c.thumbUrl;b.addEvent("click",function(){this.popup.load(c)}.bind(this));return b}});var WikipediatorPopup=new Class({Extends:ShadowedPopup,initialize:function(a){this.root=a;this.parent("wikipediatorPopup")},load:function(b){if(!b.preview){b.preview=new Element("div");var c=b.preview.appendChild(new Element("div"));b.preview.appendChild(new Element("p",{html:b.snippet}));var a=b.preview.appendChild(new Element("div").addClass("bar"));remixUrl=Wikipediator.XML_EDITOR_URL+"?load="+encodeURIComponent(b.definitionUrl)+"&name="+encodeURIComponent(b.title+" - WikiVideo Remix");a.appendChild(new Element("a",{href:"./"+b.slug+"/",html:"Bookmark this video"}).addClass("permalink"));player(c,480,320,{file:b.videoUrl,image:b.thumbUrl})}this.setContent(b.preview);this.open({root:this.root})},adjust:function(){this.view.style.marginTop=-this.view.offsetHeight/2+"px";this.view.style.marginLeft=-this.view.offsetWidth/2+"px";this.adjustShadow()}});