var Roar=new Class({Implements:[Options,Events,Chain],options:{duration:3000,position:"upperLeft",container:null,bodyFx:null,itemFx:null,margin:{x:10,y:10},offset:10,className:"roar",onShow:$empty,onHide:$empty,onRender:$empty},initialize:function(a){this.setOptions(a);this.items=[];this.container=$(this.options.container)||document},alert:function(e,c,b){var d=Array.link(arguments,{title:String.type,message:String.type,options:Object.type});var a=[new Element("h3",{html:$pick(d.title,"")})];if(d.message){a.push(new Element("p",{html:d.message}))}return this.inject(a,d.options)},inject:function(a,i){if(!this.body){this.render()}i=i||{};var c=[-this.options.offset,0];var g=this.items.getLast();if(g){c[0]=g.retrieve("roar:offset");c[1]=c[0]+g.offsetHeight+this.options.offset}var f={opacity:1};f[this.align.y]=c;var h=new Element("div",{"class":this.options.className,opacity:0}).adopt(new Element("div",{"class":"roar-bg",opacity:0.8}),a);h.setStyle(this.align.x,0).store("roar:offset",c[1]).set("morph",$merge({unit:"px",link:"cancel",onStart:Chain.prototype.clearChain,transition:Fx.Transitions.Back.easeOut},this.options.itemFx));var d=this.remove.create({bind:this,arguments:[h],delay:10});this.items.push(h.addEvent("click",d));if(this.options.duration){var e=false;var b=(function(){b=null;if(!e){d()}}).delay(this.options.duration);h.addEvents({mouseover:function(){e=true},mouseout:function(){e=false;if(!b){d()}}})}h.inject(this.body).morph(f);return this.fireEvent("onShow",[h,this.items.length])},remove:function(b){var a=this.items.indexOf(b);if(a==-1){return this}this.items.splice(a,1);b.removeEvents();var c={opacity:0};c[this.align.y]=b.getStyle(this.align.y).toInt()-b.offsetHeight-this.options.offset;b.morph(c).get("morph").chain(b.destroy.bind(b),this.restack());return this.fireEvent("onHide",[b,this.items.length]).callChain(b)},empty:function(){while(this.items.length){this.remove(this.items[0])}return this},render:function(){this.position=this.options.position;if($type(this.position)=="string"){var a={x:"center",y:"center"};this.align={x:"left",y:"top"};if((/left|west/i).test(this.position)){a.x="left"}else{if((/right|east/i).test(this.position)){this.align.x=a.x="right"}}if((/upper|top|north/i).test(this.position)){a.y="top"}else{if((/bottom|lower|south/i).test(this.position)){this.align.y=a.y="bottom"}}this.position=a}this.body=new Element("div",{"class":"roar-body"}).inject(document.body);if(Browser.Engine.trident4){this.body.addClass("roar-body-ugly")}this.moveTo=this.body.setStyles.bind(this.body);this.reposition();if(this.options.bodyFx){var c=new Fx.Morph(this.body,$merge({unit:"px",chain:"cancel",transition:Fx.Transitions.Circ.easeOut},this.options.bodyFx));this.moveTo=c.start.bind(c)}var b=this.reposition.bind(this);window.addEvents({scroll:b,resize:b});this.fireEvent("onRender",this.body)},reposition:function(){var c=document.getCoordinates(),b=document.getScroll(),d=this.options.margin;c.left+=b.x;c.right+=b.x;c.top+=b.y;c.bottom+=b.y;var a=($type(this.container)=="element")?this.container.getCoordinates():c;this.moveTo({left:(this.position.x=="right")?(Math.min(a.right,c.right)-d.x):(Math.max(a.left,c.left)+d.x),top:(this.position.y=="bottom")?(Math.min(a.bottom,c.bottom)-d.y):(Math.max(a.top,c.top)+d.y)})},restack:function(){var b={},a=0;this.items.each(function(c){b[this.align.y]=a;c.store("roar:offset",a).morph(b).get("morph");a+=c.offsetHeight+this.options.offset},this);this.reposition()}});Element.implement({getCaretPosition:function(){if(this.createTextRange){var a=document.selection.createRange().duplicate();a.moveEnd("character",this.value.length);if(a.text===""){return this.value.length}return this.value.lastIndexOf(a.text)}else{return this.selectionStart}}});var ResizableTextbox=new Class({Implements:Options,options:{min:5,max:500,step:7},initialize:function(b,a){var c=this;this.setOptions(a);this.el=$(b);this.width=this.el.offsetWidth;this.el.addEvents({keydown:function(){this.store("rt-value",this.get("value").length)},keyup:function(){var d=c.options.step*this.get("value").length;if(d<=c.options.min){d=c.width}if(!(this.get("value").length==this.retrieve("rt-value")||d<=c.options.min||d>=c.options.max)){this.setStyle("width",d)}}})}});var TextboxList=new Class({Implements:[Events,Options],options:{resizable:{},className:"bit",separator:"###",extrainputs:true,startinput:true,hideempty:true},initialize:function(b,a){this.setOptions(a);this.element=$(b).setStyle("display","none");this.bits=new Hash;this.events=new Hash;this.count=0;this.current=false;this.maininput=this.createInput({"class":"maininput"});this.holder=new Element("ul",{"class":"holder",events:{click:function(c){c=new Event(c).stop();if(this.maininput!=this.current){this.focus(this.maininput)}}.bind(this)}}).inject(this.element,"before").adopt(this.maininput);this.makeResizable(this.maininput);this.setEvents()},setEvents:function(){document.addEvent(Browser.Engine.trident?"keydown":"keypress",function(a){if(!this.current){return}if(this.current.retrieve("type")=="box"&&a.code==Event.Keys.backspace){new Event(a).stop()}}.bind(this));document.addEvents({keyup:function(a){a=new Event(a).stop();if(!this.current){return}switch(a.code){case Event.Keys.left:return this.move("left");case Event.Keys.right:return this.move("right");case Event.Keys.backspace:return this.moveDispose()}}.bind(this),click:function(){this.fireEvent("onBlur").blur()}.bind(this)})},update:function(){this.element.set("value",this.bits.getValues().join(this.options.separator));return this},add:function(c,a){var d=this.options.className+"-"+this.count++;var b=this.createBox($pick(a,c),{id:d}).inject(this.current||this.maininput,"before");b.addEvent("click",function(f){f=new Event(f).stop();this.focus(b)}.bind(this));this.bits.set(d,c.id);if(this.options.extrainputs&&(this.options.startinput||b.getPrevious())){this.addSmallInput(b,"before")}return b},addSmallInput:function(c,b){var a=this.createInput({"class":"smallinput"}).inject(c,b);a.store("small",true);this.makeResizable(a);if(this.options.hideempty){a.setStyle("display","none")}return a},dispose:function(a){this.bits.erase(a.id);if(a.getPrevious().retrieve("small")){a.getPrevious().destroy()}if(this.current==a){this.focus(a.getNext())}if(a.retrieve("type")=="box"){this.fireEvent("onBoxDispose",a)}a.destroy();return this},focus:function(b,a){if(!this.current){this.fireEvent("onFocus",b)}else{if(this.current==b){return this}}this.blur();b.addClass(this.options.className+"-"+b.retrieve("type")+"-focus");if(b.retrieve("small")){b.setStyle("display","block")}if(b.retrieve("type")=="input"){this.fireEvent("onInputFocus",b);if(!a){this.callEvent(b.retrieve("input"),"focus")}}else{this.fireEvent("onBoxFocus",b)}this.current=b;return this},blur:function(b){if(!this.current){return this}if(this.current.retrieve("type")=="input"){var a=this.current.retrieve("input");if(!b){this.callEvent(a,"blur")}this.fireEvent("onInputBlur",a)}else{this.fireEvent("onBoxBlur",this.current)}if(this.current.retrieve("small")&&!a.get("value")&&this.options.hideempty){this.current.setStyle("display","none")}this.current.removeClass(this.options.className+"-"+this.current.retrieve("type")+"-focus");this.current=false;return this},createBox:function(b,a){return new Element("li",$extend(a,{"class":this.options.className+"-box"})).set("html",b.name).store("type","box")},createInput:function(b){var a=new Element("li",{"class":this.options.className+"-input"});var c=new Element("input",$extend(b,{type:"text",autocomplete:"off",name:this.options.inputName,events:{click:function(d){d=new Event(d).stop()},focus:function(d){if(!this.isSelfEvent("focus")){this.focus(a,true)}}.bind(this),blur:function(){if(!this.isSelfEvent("blur")){this.blur(true)}}.bind(this),keydown:function(d){this.store("lastvalue",this.value).store("lastcaret",this.getCaretPosition())}}}));return a.store("type","input").store("input",c).adopt(c)},callEvent:function(b,a){this.events.set(a,b);b[a]()},isSelfEvent:function(a){return(this.events.get(a))?!!this.events.erase(a):false},makeResizable:function(a){var b=a.retrieve("input");b.store("resizable",new ResizableTextbox(b,$extend(this.options.resizable,{min:b.offsetWidth,max:this.element.getStyle("width").toInt()})));return this},checkInput:function(){var a=this.current.retrieve("input");return(!a.retrieve("lastvalue")||(a.getCaretPosition()===0&&a.retrieve("lastcaret")===0))},move:function(b){var a=this.current["get"+(b=="left"?"Previous":"Next")]();if(a&&(!this.current.retrieve("input")||((this.checkInput()||b=="right")))){this.focus(a)}return this},moveDispose:function(){if(this.current.retrieve("type")=="box"){return this.dispose(this.current)}if(this.checkInput()&&this.bits.getKeys().length&&this.current.getPrevious()){return this.focus(this.current.getPrevious())}}});var FacebookList=new Class({Extends:TextboxList,options:{onBoxDispose:function(a){this.autoFeed(JSON.decode(a.retrieve("text")))},onInputFocus:function(){this.autoShow()},onInputBlur:function(a){this.lastinput=a;this.blurhide=this.autoHide.delay(200,this)},autocomplete:{opacity:0.8,maxresults:10,minchars:1}},initialize:function(c,d,a){this.parent(c,a);this.data=[];this.autoholder=$(d).setStyle("opacity",this.options.autocomplete.opacity);this.autoresults=this.autoholder.getElement("ul");var b=this.autoresults.getElements("li");b.each(function(e){this.add({id:e.get("value"),name:e.innerHTML})},this)},autoShow:function(a){this.autoholder.setStyle("display","block");this.autoholder.getChildren().setStyle("display","none");if(!a||!a.trim()||(!a.length||a.length<this.options.autocomplete.minchars)){this.autoholder.getElement(".default").setStyle("display","block");this.resultsshown=false}else{this.resultsshown=true;this.autoresults.setStyle("display","block").empty();this.autoresults.empty();this.data.filter(function(b){if(typeof(b)=="string"){if(b){b=JSON.decode(b).name}return b?b.test(a,"i"):false}else{return false}}).each(function(b,d){if(d>=this.options.autocomplete.maxresults){return}var e=this;var c=new Element("li").addEvents({mouseenter:function(){e.autoFocus(this)},click:function(f){new Event(f).stop();e.autoAdd(this)}}).set("html",this.autoHighlight(JSON.decode(b).name,a)).inject(this.autoresults);c.store("result",JSON.decode(b));if(d==0){this.autoFocus(c)}},this)}return this},autoHighlight:function(b,a){if(typeof(b)!="undefined"){return b.replace(new RegExp(a,"gi"),function(c){return"<em>"+c+"</em>"})}else{return""}},autoHide:function(){this.resultsshown=false;this.autoholder.setStyle("display","none");return this},autoFocus:function(a){if(!a){return}if(this.autocurrent){this.autocurrent.removeClass("auto-focus")}this.autocurrent=a.addClass("auto-focus");return this},autoMove:function(a){if(!this.resultsshown){return}if(typeof(this.autocurrent)=="undefined"){}else{this.autoFocus(this.autocurrent["get"+(a=="up"?"Previous":"Next")]())}return this},autoFeed:function(a){if(this.data.indexOf(Object.toJSON(a))==-1){this.data.include(Object.toJSON(a))}return this},autoAdd:function(b){if(!b||!b.retrieve("result")){return}this.add(b.retrieve("result"));delete this.data[this.data.indexOf(Object.toJSON(b.retrieve("result")))];this.autoHide();var a=this.lastinput||this.current.retrieve("input");a.set("value","").focus();return this},createInput:function(c){var a=this.parent(c);var b=a.retrieve("input");b.addEvents({keydown:function(g){this.dosearch=false;switch(new Event(g).code){case Event.Keys.up:return this.autoMove("up");case Event.Keys.down:return this.autoMove("down");case Event.Keys.enter:if(!this.autocurrent){var f=this;new Request.JSON({url:webPath+this.options.fetchFile,onSuccess:function(e){if(e!=null&&e.length>0){e.each(function(h){f.autoFeed(h)}.bind(f));f.autoShow(b.value);f.autoAdd(f.autocurrent)}}}).get({action:"add",q:b.value});var d=new Event(g);d.stop();break}this.autoAdd(this.autocurrent);this.autocurrent=false;this.autoenter=true;break;case Event.Keys.esc:this.autoHide();if(this.current&&this.current.retrieve("input")){this.current.retrieve("input").set("value","")}break;default:this.dosearch=true}}.bind(this),keyup:function(f){switch(new Event(f).code){case Event.Keys.up:case Event.Keys.down:break;case Event.Keys.enter:break;default:if(typeof(this.options.fetchFile)!="undefined"){var d=this;new Request.JSON({url:webPath+this.options.fetchFile,onSuccess:function(e){if(e!=null&&e.length>0){e.each(function(g){d.autoFeed(g)}.bind(d))}}}).get({q:b.value});this.autocurrent=false}if(this.dosearch){this.autoShow(b.value)}}}.bind(this)});b.addEvent(Browser.Engine.trident?"keydown":"keypress",function(d){if(this.autoenter){new Event(d).stop()}this.autoenter=false}.bind(this));return a},createBox:function(c,b){var a=this.parent(c,b);return a.addEvents({mouseenter:function(){this.addClass("bit-hover")},mouseleave:function(){this.removeClass("bit-hover")}}).adopt(new Element("a",{href:"#","class":"closebutton",events:{click:function(d){new Event(d).stop();if(!this.current){this.focus(this.maininput)}this.dispose(a)}.bind(this)}})).store("text",Object.toJSON(c))},addSmallInput:function(c,b){var a=this.parent(c,b);var d=a.getChildren("input")[0].set("value",JSON.decode(c.retrieve("text")).id);return a}});var ext={toJSON:function(a){return JSON.encode(a)}};$extend(Object,ext);window.addEvent("domready",function(b){if(document.referrer&&document.referrer!=""){if(self!=top){top.location.replace(self.location)}var a=new Request({method:"get",data:"ref="+escape(document.referrer.replace("http://","")),url:webPath+"ajax/record_friendsblock.php",onComplete:function(c){}}).send()}});
