
Array.implement({setBlock:function(){this.each(function(item){item.setBlock();});return this;},setNone:function(){this.each(function(item){item.setNone();});return this;},setHref:function(h){this.each(function(item){item.setHref(h);});return this;}});
var Corner=new Class({initialize:function(container,options){this.container=container.setOpacity(1).setStyle('display','block');var cs=this.container.getSize(),cr={top:{},middle:{},bottom:{}};$each(cr,function(prop,name){['left','center','right'].each(function(classname){prop[classname]=new Element('div',{'class':'corner '+name+' '+classname}).inject(container,'top');prop[classname].size=prop[classname].getSize();});});var value={top:{top:0,height:cr.top.left.size.y},middle:{top:cr.top.left.size.y,height:cs.y-cr.top.left.size.y-cr.bottom.left.size.y},bottom:{top:cs.y-cr.bottom.left.size.y,height:cr.bottom.left.size.y}}
$each(cr,function(prop,name){prop.left.setStyles({height:value[name].height,left:0,top:value[name].top});prop.center.setStyles({height:value[name].height,width:cs.x-prop.left.size.x-prop.right.size.x,left:prop.left.size.x,top:value[name].top});prop.right.setStyles({height:value[name].height,left:cs.x-prop.right.size.x,top:value[name].top});});this.container.setStyle('display','block');}});
var Dialog=new Class({Implements:[Events,Options],options:{transition:Fx.Transitions.Bounce.easeOut,overflow:{left:0,top:0},duration:300,distance:20},initialize:function(container,options){this.run=false;this.container=container;this.arrow=container.getElement('.arrow');this.setOptions(options);this.current=null;this.fx=new Fx.Morph(this.container,{duration:this.options.duration,link:'ignore'});this._detect=this.detect.bindWithEvent(this);},detect:function(event){var t=$(new Event(event).target);if(this.container==t||this.container.hasChild(t)||(t.hasClass('bulle')&&t!=this.current))
return;this.hide();},chain:function(event,target){this.fireEvent('onShow',event);this.current=target;this.run=false;},hide:function(){if(this.run||!this.top)
return;this.run=true;this.fx.start({opacity:(Browser.Engine.trident)?1:0,top:this.top-((Browser.Engine.trident)?0:this.options.distance)}).chain((function(){this.run=false;this.current=null;document.removeEvent('click',this._detect);this.fireEvent('onHide');this.container.setStyles({visibility:'hidden',display:'none'});}).bind(this));},show:function(event){this.event=event;var scrolltop,eoo,moo,target=event;var scrolltop,eoo,moo,target=$(new Event(event).target);if(this.current==target||this.run)
return;this.run=true;this.container.setBlock();eoo=target.getCoordinates();moo=this.container.getCoordinates();this.top=eoo.top-moo.height;this.left=eoo.left-moo.width+this.options.overflow.left;if(this.left<0)this.left=0;if(this.top<0){this.arrow.addClass('top');this.top+=moo.height+eoo.height-this.options.overflow.top;}else this.arrow.removeClass('top');this.arrow.setStyles({left:eoo.left-this.left-this.arrow.getStyle('margin-right').toInt(),top:eoo.top-this.top});if(this.current){this.fx.start({left:this.left,top:this.top}).chain((function(){this.chain(event,target);}).bind(this));}else{this.container.setStyles({left:this.left,top:this.top+((Browser.Engine.trident)?0:this.options.distance),visibility:'visible',opacity:(Browser.Engine.trident)?1:0});this.fx.start({opacity:1,top:this.top}).chain((function(){document.addEvent('click',this._detect);this.chain(event,target);}).bind(this));}
return this;}});
var Discreet=new Class({Implements:[Events,Options],options:{duration:300,hide:0.2},initialize:function(container,element,options){this.setOptions(options);this.container=container;this.element=element;this.container.addEvents({mouseenter:this.enter.bind(this),mouseleave:this.leave.bind(this)});this.element.setOpacity(this.options.hide);this.fx=new Fx.Tween(this.element,{duration:this.options.duration,link:'ignore'});},enter:function(){this.fx.start('opacity',1);},leave:function(){this.fx.start('opacity',this.options.hide);}})
Element.implement({getCharacterSize:function(){var element=this.clone(),size,style;style=new Hash(this.getStyles('font-size','font-weight')).extend({position:'absolute',visibility:'hidden',display:'block',top:0});element.setStyles(style).inject(document.body);size=element.getSize();element.destroy();return size;},getElementsWithAssociate:function(filter){var reg=new RegExp("[.]|#","g"),a=filter.split(',').map(function(item){return item.trim().replace(reg,'');});return this.getElements(filter).associate(a);},diselected:function(){with(this){onselectstart=function(){return false;};['MozUser','KhtmlUser','User'].each(function(p){setStyle(p+'Select','none');});}
return this;},center:function(container){var eoo=this.getCoordinates(),coo=container.getCoordinates(),h,w;h=(eoo&&eoo.height)?eoo.height:this.height;w=(eoo&&eoo.width)?eoo.width:this.width;this.setStyles({'top':-(h/2)+(coo.height/2),'left':-(w/2)+(coo.width/2),'height':h,'width':w});return this;},setHref:function(h){h=h||'javascript:void(0);';if(this.get('tag')!='a')
return this;return this.set('href',h);},setBlock:function(){return this.setStyle('display','block');},setNone:function(){return this.setStyle('display','none');}});
var Form=new Class({initialize:function(){this.checkbox=$$('span.checkbox');this.checkbox.removeEvents();this.checkbox.each((function(item){item.addEvent('click',this.checkbox_check.bind(this,[item,'toggle']));}).bind(this));this.price=$('result_price');},checkbox_check:function(item,act){if(act=='toggle')
item.toggleClass('selected');else{if(act=='add')
item.addClass('selected');else
item.removeClass('selected');}
if($defined(this.price))
this.calculate(this.checkbox);if(act=='toggle'){if(item.get('depends'))
this.checkbox_check($$(item.get('depends')),'add');if(item.get('needs'))
this.checkbox_check($$(item.get('needs')),'remove');if(item.get('group'))
this.checkbox_check($$(item.get('group')),'remove');}},calculate:function(element){price=0;element.each(function(item){if(item.hasClass('selected'))
price+=item.get('text').split('.')[0].toInt();});this.price.set('text',price);}});
var History=(function(){var HistoryClass=new Class({Implements:Events,initialize:function(){this.detect.periodical(250,this);this.href=null;},detect:function(){if(this.href&&this.href!=window.location.href)
this.fireEvent('onChange');this.href=window.location.href;}});return new HistoryClass();})();
var Inputs=new Class({options:{container:false},initialize:function(container,options){this.options.container=$(window);this.search=$('searchUsr');this.search.removeEvents();this.search.addEvent('keyup',this.keyup.bindWithEvent(this));this.sb=new Scrollbar($('usrResult'),$$('#usrResult .wrapper')[0].diselected(),{orientation:'vertical',discreet:true,wheel:true});this.list();},toggle:function(){this.element.fade('toggle');return this;},keyup:function(event){event=new Event(event);var filter=/^up|down|left|right|enter$/;if(this.search.value.length==0)
return;if(!filter.test(event.key))
this.list();},list:function(){this.row=[];this.sb.wrapper.empty();new Request.JSON({url:"ajax.administration.php",onComplete:(function(response){response.each(function(player,index){var row=new Element('span',{'class':(index%2)?'lite':'dark'}).adopt([new Element('div',{'class':(player.member==1)?'member':'nomember'}),new Element('div',{'class':'label','text':player.name+' '+player.surname})]);row.addEvent('click',this.select.bind(this,row));row.store('id',player.id);row.inject(this.sb.wrapper);this.row.push(row);},this);this.sb.setCursor();}).bind(this)}).send(JSON.encode({'userGetList':{filter:this.search.value}}));},select:function(row){console.log(row);},start:function(event){var target=$(new Event(event).target);if(target.hasClass('title'))
this.parent(event);}});
var Tabpanel=new Class({Implements:[Options],options:{duration:500,selected:0},initialize:function(content,options){this.content=content;this.setOptions(options);this.tab=this.content.getElements('a.tab');this.panel=this.content.getElements('div.panel');this.tab.each(function(tab,index){tab.setHref().addEvent('click',this.click.bind(this,index));},this);if(this.options.selected!==false)
this.select(this.options.selected,true);},click:function(index){this.select(index);},select:function(index,initialize){if(!(index<this.panel.length||index>0)||this.index==index)return;if(this.tab.length){this.tab.each(function(panel){panel.removeClass('selected');});this.tab[index].addClass('selected');}
this.index=index;this.panel.each(function(panel){panel.setNone();});this.panel[index].setStyles({opacity:(initialize)?1:0,display:'block'});if(initialize)return;var fx=new Fx.Tween(this.panel[index]);fx.start('opacity',1);return this;}});
var Template=new Class({set:function(property,data){if(!this.element||$type(this.element)!='array')
return;this.element.each(function(element,index){var value=($type(data[index])=='element')?data[index].get('text'):data[index];element.set(property,value);});}});
var Tips={};Tips.Base=new Class({Implements:[Options],options:{delay:1500,autohide:true,className:'tooltip',transition:{show:Fx.Transitions.Bounce.easeOut,hide:Fx.Transitions.linear},duration:{show:400,hide:100}},initialize:function(element,options){this.element=element;this.setOptions(options);this.container=new Element('a',{'class':this.options.className,opacity:0,events:{'click':this.setHide.bind(this,1)}});['left','middle','right'].each(function(cn,i){new Element('span',{'class':cn}).inject(this);},this.container);this.run=false;this.fx=new Fx.Tween(this.container.inject(document.body),{transition:this.options.transition,link:'ignore'});return this;},setValue:function(value){this.container.getElement('span.middle').set('html',value);return this;},setShow:function(){if(this.run)return;this.run=true;var ic=this.element.getCoordinates(),tc=this.container.getCoordinates();this.container.setStyles({top:ic.top-(tc.height/2)+(ic.height/2),left:ic.left-tc.width-100,opacity:1});this.fx.options.duration=this.options.duration.show;this.fx.options.transition=this.options.transition.show;this.fx.start('left',ic.left-tc.width+5);if(this.options.autohide)
this.setHide();},setHide:function(delay){(function(){if(!this.run)return;if(Browser.Engine.trident){this.container.set('opacity',0);this.run=false;return;}
this.fx.options.duration=this.options.duration.hide;this.fx.options.transition=this.options.transition.hide;this.fx.start('opacity',0).chain((function(){this.run=false;}).bind(this));}).bind(this).delay(delay||this.options.delay);}});Tips.Info=new Class({Extends:Tips.Base,initialize:function(element,options){this.parent(element,options);this.element.addEvents({mouseenter:this.mouse.bindWithEvent(this),mouseleave:this.mouse.bindWithEvent(this),click:this.mouse.bindWithEvent(this)});this.setValue(this.element.getProperty('tip'));this.container.addEvent('mouseleave',(function(event){if(new Event(event).relatedTarget!=this.element)
this.setVisibility(0);}).bind(this));},mouse:function(event){var event=new Event(event),rt=event.relatedTarget;switch(event.type){case'mouseover':if(!this.container.hasChild(rt))this.setShow();break;case'mouseout':if(!this.container.hasChild(rt))this.setVisibility(0);break;case'click':this.setVisibility(0);break;}},setVisibility:function(opacity){if(Browser.Engine.trident)this.container.setOpacity(opacity);else this.container.fade(opacity);},setShow:function(){var ic=this.element.getCoordinates(),tc=this.container.getCoordinates();this.container.setStyles({top:ic.top-(tc.height/2)+(ic.height/2),left:ic.left-tc.width+5});this.setVisibility(1);}});
var Validator=new Class({Implements:[Events],initialize:function(form){this.form=form||null;},get:function(form){this.form=form||this.form;this.elements=this.form.getElements('[name!=""]');this.data={};this.elements.each(function(el){switch(el.getProperty('type')||el.type){case'keyword':this.data[el.getProperty('name')]=el.get();break;case'image':this.data[el.name]=el.src;break;case'radio':if(!this.data[el.name])this.data[el.name]=(el.checked)?el.value:null;break;default:this.data[el.name]=el.value;break;}},this);return this;},check:function(method){if(!method)return;this.send={};this.send[method]=this.data;new Request.JSON({url:this.form.action,method:'post',onComplete:(function(response){if(response.validate==true){console.log(response);this.fireEvent('onValidate',response);return;}
this.run=false;this.elements.each(function(element){if(this.run||element.name!=response.type)
return;this.error(element,response.message);},this);}).bind(this)}).send(JSON.encode(this.send));},error:function(element,message){if(element.focus)
element.focus();if(!element.tooltip)
element.tooltip=new Tips.Base(element);element.tooltip.setValue(message).setShow();this.run=true;}});