var MultiBox=new Class({Implements:[Events,Options],options:{initialWidth:250,initialHeight:250,container:null,useOverlay:false,overlayOptions:{},contentColor:'#FFF',contentFade:false,waitDuration:2000,width:400,height:300,requestOptions:{evalScripts:true,autoCancel:true,method:'get',salt:true,timestamp:true}},descriptions:[],initialize:function(className,options){this.options.container=this.options.container?$(this.options.container):document.body;this.setOptions(options);this.openClosePos={};this.timer=0;this.contentToLoad={};this.index=0;this.opened=false;this.contentObj={};this.containerDefaults={};if(this.options.useOverlay!=false){this.options.overlay.container=this.options.container;this.options.overlay.onClick=this.close.bind(this);this.overlay=new Overlay(this.options.overlay);}
this.content=$$('.'+className);if(this.options.descClassName){this.descriptions=$$('.'+this.options.descClassName);this.descriptions.each(function(el){el.setStyle('display','none');});}
this.container=new Element('div',{'class':'MultiBoxContainer'}).inject(this.options.container);this.box=new Element('div',{'class':'MultiBoxContent'});this.closeButton=new Element('div',{'class':'MultiBoxClose','events':{'click':this.close.bind(this)}});this.container.adopt([this.box,this.closeButton]);this.attatch();this.containerEffects=new Fx.Morph(this.container,{duration:400,transition:'sine:in:out'});this.reset();},attatch:function(content){var stack=true;if(!$defined(content)){content=this.content;stack=false;}
content.each(function(el,i){if(stack)this.content.push(el);el.index=i;el.addEvent('click',function(e){e.stop();this.open(el);}.bind(this));if(el.href.indexOf('#')>-1){el.content=$(el.href.substr(el.href.indexOf('#')+1));if(el.content){el.content.setStyle('display','none');}}},this);},setContentType:function(link){var str=link.href.substr(link.href.lastIndexOf('.')+1).toLowerCase();var contentOptions={};if($chk(link.rel)){var optArr=link.rel.split(',');optArr.each(function(el){var ta=el.split(':');contentOptions[ta[0]]=ta[1];});}
if($defined(contentOptions.type)){str=contentOptions.type;}
this.contentObj={};this.contentObj.requestOptions={'url':link.href};if(contentOptions.salt){this.contentObj.requestOptions.salt=(contentOptions.salt=='true');}
if(contentOptions.timestamp){this.contentObj.requestOptions.timestamp=(contentOptions.timestamp=='true');}
this.contentObj.xH=0;if(contentOptions.width){this.contentObj.width=contentOptions.width;}else{this.contentObj.width=this.options.width;}
if(contentOptions.height){this.contentObj.height=contentOptions.height;}else{this.contentObj.height=this.options.height;}
if(contentOptions.panel){this.panelPosition=contentOptions.panel;}else{this.panelPosition=this.options.panel;}
if(contentOptions.panel){this.panelPosition=contentOptions.panel;}else{this.panelPosition=this.options.panel;}
if(contentOptions.panel){this.panelPosition=contentOptions.panel;}else{this.panelPosition=this.options.panel;}
this.type='ajax';},reset:function(){this.container.setStyles({'opacity':0,'display':'none'});this.removeContent();this.opened=false;},getOpenClosePos:function(el){if(el.getFirst()){var w=el.getFirst().getCoordinates().width-(this.container.getStyle('border').toInt()*2);if(w<0){w=0}
var h=el.getFirst().getCoordinates().height-(this.container.getStyle('border').toInt()*2);if(h<0){h=0}
this.openClosePos={width:w,height:h,top:el.getFirst().getCoordinates().top,left:el.getFirst().getCoordinates().left};}else{var w=el.getCoordinates().width-(this.container.getStyle('border').toInt()*2);if(w<0){w=0}
var h=el.getCoordinates().height-(this.container.getStyle('border').toInt()*2);if(h<0){h=0}
this.openClosePos={width:w,height:h,top:el.getCoordinates().top,left:el.getCoordinates().left};}
return this.openClosePos;},open:function(el){this.fireEvent('onOpen',el);this.index=this.content.indexOf(el);this.openId=el.getProperty('id');if(!this.opened){this.opened=true;if(this.options.useOverlay){this.overlay.show();}
this.container.setStyles(this.getOpenClosePos(el));this.container.setStyles({opacity:0,display:'block'});this.containerEffects.start({width:this.options.initialWidth,height:this.options.initialHeight,top:(window.getHeight()/2)-(this.options.initialHeight/2)-this.container.getStyle('border').toInt(),left:(window.getWidth()/2)-(this.options.initialWidth/2)-this.container.getStyle('border').toInt(),opacity:[0,1]});this.load(this.index);}else{this.getOpenClosePos(this.content[this.index]);this.timer=this.hideContent.bind(this).delay(500);this.timer=this.load.pass(this.index,this).delay(1100);}},getContent:function(index){this.setContentType(this.content[index]);var desc=null;this.contentToLoad={title:this.content[index].title,desc:desc,number:index+1};},close:function(){if(this.options.useOverlay){this.overlay.hide();}
this.hideContent();this.containerEffects.cancel();this.zoomOut.bind(this).delay(100);this.fireEvent('onClose');},zoomOut:function(){this.containerEffects.start({width:this.openClosePos.width,height:this.openClosePos.height,top:this.openClosePos.top,left:this.openClosePos.left,opacity:0});this.reset.bind(this).delay(500);},load:function(index){this.box.addClass('MultiBoxLoading');this.getContent(index);this.resize();},loaded:function(text){this.box.removeClass('MultiBoxLoading');if(this.options.contentFade){this.contentEffects.start({opacity:1});}else{this.contentEffects.set({opacity:1});}},resize:function(){var top=(window.getHeight()/2)-((Number(this.contentObj.height)+this.contentObj.xH)/2)-this.container.getStyle('border').toInt()+window.getScrollTop();var left=(window.getWidth()/2)-(this.contentObj.width/2)-this.container.getStyle('border').toInt();if(top<0){top=0}
if(left<0){left=0}
this.containerEffects.cancel();this.containerEffects.start({width:this.contentObj.width,height:Number(this.contentObj.height)+this.contentObj.xH,top:top,left:left,opacity:1});$clear(this.timer);this.showContent();},showContent:function(){this.removeContent();this.contentContainer=new Element('div',{'id':'MultiBoxContentContainer','styles':{'opacity':0,'width':this.contentObj.width+'px','height':(Number(this.contentObj.height)+this.contentObj.xH)+'px'}}).inject(this.box);this.contentEffects=new Fx.Morph(this.contentContainer,{duration:500,transition:'linear'});var loaded=this.loaded.bind(this);var close=this.close.bind(this);var requestOptions=$extend(this.options.requestOptions,this.contentObj.requestOptions);this.contentContainer.set('load',requestOptions);this.contentContainer.get('load').addEvent('success',function(tree,elements,text){if(Response.auth(text)){loaded();}else{close();}});this.contentContainer.load();},hideContent:function(){this.box.addClass('MultiBoxLoading');if(this.options.contentFade){this.contentEffects.start({opacity:0});}else{this.contentEffects.set({opacity:0});}
this.removeContent.bind(this).delay(500);},removeContent:function(){if($('MultiBoxContentContainer')){$('MultiBoxContentContainer').dispose();}}});var Overlay=new Class({Implements:Options,options:{color:'#000',opacity:0.7,zIndex:1,container:document.body,onClick:$empty},layed:false,initialize:function(options){this.setOptions(options);this.options.container=$(this.options.container);this.overlay=new Element('div').setProperty('id','Overlay').setStyles({position:'absolute',left:'0px',top:'0px',width:'100%',zIndex:this.options.zIndex,backgroundColor:this.options.color}).inject(this.options.container);this.overlay.addEvent('click',function(){this.options.onClick();}.bind(this));this.fade=new Fx.Tween(this.overlay).set('opacity',0);this.position();window.addEvent('resize',this.position.bind(this));},position:function(){if(this.options.container==document.body){var h=window.getScrollHeight()+'px';this.overlay.setStyles({top:'0px',height:h});}else{var myCoords=this.options.container.getCoordinates();this.overlay.setStyles({top:myCoords.top+'px',height:myCoords.height+'px',left:myCoords.left+'px',width:myCoords.width+'px'});}},show:function(){this.fade.start('opacity',0,this.options.opacity);this.layed=true;},hide:function(){this.fade.start('opacity',this.options.opacity,0);this.layed=false;}});Overlay.implement(new Options);var Autocompleter={};Autocompleter.Base=new Class({options:{minLength:1,markQuery:true,width:'inherit',maxChoices:10,injectChoice:null,customChoices:null,className:'autocompleter-choices',zIndex:42,delay:100,observerOptions:{},fxOptions:{},onOver:$empty,onSelect:$empty,onSelection:$empty,onShow:$empty,onHide:$empty,onBlur:$empty,onFocus:$empty,autoSubmit:false,overflow:false,overflowMargin:25,selectFirst:false,filter:null,filterCase:false,filterSubset:false,forceSelect:false,selectMode:true,choicesMatch:null,multiple:false,separator:', ',separatorSplit:/\s*[,;]\s*/,autoTrim:true,allowDupes:false,cache:true,relative:false},initialize:function(element,options){this.element=$(element);this.setOptions(options);this.build();this.observer=new Observer(this.element,this.prefetch.bind(this),$merge({'delay':this.options.delay},this.options.observerOptions));this.queryValue=null;if(this.options.filter)this.filter=this.options.filter.bind(this);var mode=this.options.selectMode;this.typeAhead=(mode=='type-ahead');this.selectMode=(mode===true)?'selection':mode;this.cached=[];},build:function(){if($(this.options.customChoices)){this.choices=this.options.customChoices;}else{this.choices=new Element('ul',{'class':this.options.className,'styles':{'zIndex':this.options.zIndex}}).inject(document.body);this.relative=false;if(this.options.relative){this.choices.inject(this.element,'after');this.relative=this.element.getOffsetParent();}
this.fix=new OverlayFix(this.choices);}
if(!this.options.separator.test(this.options.separatorSplit)){this.options.separatorSplit=this.options.separator;}
this.fx=(!this.options.fxOptions)?null:new Fx.Tween(this.choices,$merge({'property':'opacity','link':'cancel','duration':200},this.options.fxOptions)).addEvent('onStart',Chain.prototype.clearChain).set(0);this.element.setProperty('autocomplete','off').addEvent((Browser.Engine.trident||Browser.Engine.webkit)?'keydown':'keypress',this.onCommand.bind(this)).addEvent('click',this.onCommand.bind(this,[false])).addEvent('focus',this.toggleFocus.create({bind:this,arguments:true,delay:100})).addEvent('blur',this.toggleFocus.create({bind:this,arguments:false,delay:100}));},destroy:function(){if(this.fix)this.fix.destroy();this.choices=this.selected=this.choices.destroy();},toggleFocus:function(state){this.focussed=state;if(!state)this.hideChoices(true);this.fireEvent((state)?'onFocus':'onBlur',[this.element]);},onCommand:function(e){if(!e&&this.focussed)return this.prefetch();if(e&&e.key&&!e.shift){switch(e.key){case'enter':if(this.element.value!=this.opted)return true;if(this.selected&&this.visible){this.choiceSelect(this.selected);return!!(this.options.autoSubmit);}
break;case'up':case'down':if(!this.prefetch()&&this.queryValue!==null){var up=(e.key=='up');this.choiceOver((this.selected||this.choices)[(this.selected)?((up)?'getPrevious':'getNext'):((up)?'getLast':'getFirst')](this.options.choicesMatch),true);}
return false;case'esc':case'tab':this.hideChoices(true);break;}}
return true;},hideChoices:function(clear){if(clear){var value=this.element.value;if(this.options.forceSelect)value=this.opted;if(this.options.autoTrim){value=value.split(this.options.separatorSplit).filter($arguments(0)).join(this.options.separator);}
this.observer.setValue(value);}
if(!this.visible)return;this.visible=false;this.observer.clear();var hide=function(){this.choices.setStyle('display','none');this.fix.hide();}.bind(this);if(this.fx)this.fx.start(0).chain(hide);else hide();this.fireEvent('onHide',[this.element,this.choices]);},prefetch:function(){var value=this.element.value,query=value;if(this.options.multiple){var split=this.options.separatorSplit;var values=value.split(split);var index=this.element.getCaretPosition();var toIndex=value.substr(0,index).split(split);var last=toIndex.length-1;index-=toIndex[last].length;query=values[last];}
if(query.length<this.options.minLength){this.hideChoices();}else{if(query===this.queryValue||(this.visible&&query==this.selectedValue)){if(this.visible)return false;this.showChoices();}else{this.queryValue=query;this.queryIndex=index;if(!this.fetchCached())this.query();}}
return true;},fetchCached:function(){return false;if(!this.options.cache||!this.cached||!this.cached.length||this.cached.length>=this.options.maxChoices||this.queryValue)return false;this.update(this.filter(this.cached));return true;},choiceOver:function(choice,selection){if(!choice||choice==this.selected)return;if(this.selected)this.selected.removeClass('autocompleter-selected');this.selected=choice.addClass('autocompleter-selected');this.fireEvent('onSelect',[this.element,this.selected,selection]);if(!selection)return;this.selectedValue=this.selected.inputValue;if(this.overflown){var coords=this.selected.getCoordinates(this.choices),margin=this.options.overflowMargin,top=this.choices.scrollTop,height=this.choices.offsetHeight,bottom=top+height;if(coords.top-margin<top&&top)this.choices.scrollTop=Math.max(coords.top-margin,0);else if(coords.bottom+margin>bottom)this.choices.scrollTop=Math.min(coords.bottom-height+margin,bottom);}
if(this.selectMode)this.setSelection();},choiceSelect:function(choice){if(choice)this.choiceOver(choice);this.setSelection(true);this.queryValue=false;this.hideChoices();},markQueryValue:function(str){return(!this.options.markQuery||!this.queryValue)?str:str.replace(new RegExp('('+((this.options.filterSubset)?'':'^')+this.queryValue.escapeRegExp()+')',(this.options.filterCase)?'':'i'),'<span class="autocompleter-queried">$1</span>');},addChoiceEvents:function(el){return el.addEvents({'mouseover':this.choiceOver.bind(this,[el]),'click':this.choiceSelect.bind(this,[el])});}});Autocompleter.Base.implement(new Events);Autocompleter.Base.implement(new Options);var OverlayFix=new Class({initialize:function(el){if(Browser.Engine.trident){this.element=$(el);this.relative=this.element.getOffsetParent();this.fix=new Element('iframe',{'frameborder':'0','scrolling':'no','src':'javascript:false;','styles':{'position':'absolute','border':'none','display':'none','filter':'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'}}).inject(this.element,'after');}},show:function(){if(this.fix){var coords=this.element.getCoordinates(this.relative);delete coords.right;delete coords.bottom;this.fix.setStyles($extend(coords,{'display':'','zIndex':(this.element.getStyle('zIndex')||1)-1}));}
return this;},hide:function(){if(this.fix)this.fix.setStyle('display','none');return this;},destroy:function(){this.fix=this.fix.destroy();}});Element.implement({getCaretPosition:function(){if(!Browser.Engine.trident)return this.selectionStart;this.focus();var work=document.selection.createRange();var all=this.createTextRange();work.setEndPoint('StartToStart',all);return work.text.length;},selectRange:function(start,end){if(Browser.Engine.trident){var range=this.createTextRange();range.collapse(true);range.moveEnd('character',end);range.moveStart('character',start);range.select();}else{this.focus();this.setSelectionRange(start,end);}
return this;}});var Observer=new Class({Implements:[Options,Events],options:{periodical:false,delay:1000},initialize:function(el,onFired,options){this.setOptions(options);this.addEvent('onFired',onFired);this.element=$(el)||$$(el);this.value=this.element.get('value');if(this.options.periodical)this.timer=this.changed.periodical(this.options.periodical,this);else this.element.addEvent('keyup',this.changed.bind(this));},changed:function(){var value=this.element.get('value');if($equals(this.value,value))return;this.clear();this.value=value;this.timeout=this.onFired.delay(this.options.delay,this);},setValue:function(value){this.value=value;this.element.set('value',value);return this.clear();},onFired:function(){this.fireEvent('onFired',[this.value,this.element]);},clear:function(){$clear(this.timeout||null);return this;}});var $equals=function(obj1,obj2){return(obj1==obj2||JSON.encode(obj1)==JSON.encode(obj2));};Autocompleter.ZeadooBK=new Class({Extends:Autocompleter.Base,friends:{},_friends:{},matches:{},emails:{},_emails:{},options:{delay:0,minLength:1,overflow:true,multiple:false,filterSubset:true,fields:{id:'data[Bookmark][shareIds][]',email:'data[Bookmark][shareEmails][]'}},initialize:function(element,friends,options){this.friends=new Hash();this._friends=new Hash();this.emails=new Hash();this._emails=new Hash();$each(friends,function(f,i){this.friends.include(i,new Hash(f));},this);this.parent(element,options);},query:function(){this.update(this.filter());},filter:function(){var matches=new Hash();var eregex='[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?';if(this.queryValue.test(eregex)){var end=this.queryValue.charAt(this.queryValue.length-1);if(end.test('^[ ,;]$')){this.queryValue=this.queryValue.substr(0,this.queryValue.length-1);var id=this.escapeEmail(this.queryValue);var eObj={display:this.queryValue};this.emails.include(id,eObj);auto=true;this.createToItem(id);this.observer.setValue('');return false;}else{var id=this.escapeEmail(this.queryValue);var eObj={display:this.queryValue};this.emails.include(id,eObj);matches.include(id,eObj);}}else{var regex=new RegExp(((this.options.filterSubset)?'':'^')+this.queryValue.escapeRegExp(),(this.options.filterCase)?'':'i');this.friends.each(function(f,i){var values=f.getValues();if(values.filter(function(item){return regex.test(item);}).length>0){matches.include(i,f);}},this);}
return matches;},setSelection:function(finish,id){var input=this.selected.inputValue,value=input;if(finish){this.observer.setValue('');}else{this.observer.setValue(value);}
this.opted=value;this.fireEvent('onSelection',[this.element,this.selected,value,input]);},showChoices:function(){var match=this.options.choicesMatch,first=this.choices.getFirst(match);this.selected=this.selectedValue=null;if(this.fix){var pos=this.element.getParent().getCoordinates(this.relative),width=this.options.width||'auto';this.choices.setStyles({'left':pos.left,'top':pos.bottom,'width':(width===true||width=='inherit')?pos.width:width});}
if(!first)return;if(!this.visible){this.visible=true;this.choices.setStyle('display','');if(this.fx)this.fx.start(1);this.fireEvent('onShow',[this.element,this.choices]);}
if(this.options.selectFirst||this.typeAhead||first.inputValue==this.queryValue)this.choiceOver(first,true);var items=this.choices.getChildren(match),max=this.options.maxChoices;var styles={'overflowY':'hidden','height':''};this.overflown=false;if(items.length>max){var item=items[max-1];styles.overflowY='scroll';styles.height=item.getCoordinates(this.choices).bottom;this.overflown=true;};this.choices.setStyles(styles);this.fix.show();},update:function(friends){this.choices.empty();if(!friends){this.hideChoices();}else{if(this.options.maxChoices<friends.length&&!this.options.overflow)friends.length=this.options.maxChoices;friends.each(this.options.injectChoice||function(friend,i){var choice=new Element('li',{'html':this.markQueryValue(friend.display),'id':'ch-'+i});choice.inputValue=friend.display;this.addChoiceEvents(choice).inject(this.choices);},this);this.showChoices();}},choiceSelect:function(choice){this.parent(choice);this.createToItem(choice.get('id').replace('ch-',''));this.element.focus();},createToItem:function(id){if(this.emails.has(id)&&!this._emails.has(id)){var match=this.emails.get(id);if(match){this._emails.include(id,match);this.emails.erase(id);}
this.createToEle(id,match.display,this.options.fields.email,match.display,true);}else if(this.friends.has(id)&&!this._friends.has(id)){var match=this.friends.get(id);if(match){this._friends.include(id,match);this.friends.erase(id);}
this.createToEle(id,match.display.replace(' ','&nbsp;'),this.options.fields.id,match.id,false);}},createToEle:function(id,html,name,value,email){var block=new Element('div',{'class':'rec','html':html.replace(' ','&nbsp;'),'title':'Click to remove','styles':{'cursor':'pointer'}});var field=new Element('input',{'type':'hidden','name':name,'value':value});block.grab(field);block.addEvent('click',this.removeToItem.bind(this,[block,id,email]));this.element.getParent().grab(block,'top');},removeToItem:function(block,id,email){if($defined(email)&&email==true){this._emails.erase(id);}else{var match=this._friends.get(id);this.friends.include(id,match);this._friends.erase(id);}
block.destroy();this.element.focus();},escapeEmail:function(email){return email.replace(/[^a-zA-Z0-9]/g,'_');}});
/* Thu, 19 Mar 2009 02:23:41 GMT js/mootools-plug.js */
