
var ContentLoader=new Class({Implements:[Events,Options],options:{container:'loader',contentSelector:'.loader-content',handleSelector:'.handle',closeSelector:'.close'},initialize:function(options){this.setOptions(options);this.element=$(this.options.container);this.bounds={setContent:this.setContent.bind(this),lateCenterPosition:this.lateCenterPosition.bind(this)};if($chk(window.Drag)){new Drag(this.element,{handle:this.element.getElement(this.options.handleSelector)});this.element.makeResizable({handle:this.element.getElement('.resize'),modifiers:{y:null}});}
this.element.set('morph',{onComplete:function(){if(this.element.get('opacity')==0)
this.element.setStyle('display','none');}});this.content=this.element.getElement(this.options.contentSelector);this.element.getElement(this.options.closeSelector).addEvent('mouseup',function(evt){evt.stop();this.close();}.bind(this));$extend(this,this.element.getPosition());},setAjaxContent:function(url){new Request.HTML({url:url,onSuccess:this.bounds.setContent}).send();return this;},setPosition:function(x,y){this.removeEvent('contentLoaded',this.bounds.lateCenterPosition);if($type(x)=='object'){this.x=x.x;this.y=x.y;}
else if(x=='center'){this.addEvent('contentLoaded',this.bounds.lateCenterPosition);}
else{this.x=x;this.y=y;}
return this;},lateCenterPosition:function(){this.element.setStyle('display','block');this.x=(document.getScroll().x+document.getSize().x/2-this.element.getSize().x/2);this.y=(document.getScroll().y+document.getSize().y/2-this.element.getSize().y/2);this.element.setStyle('display','none');},setContent:function(nodes){this.content.empty().adopt(nodes);this.fireEvent('contentLoaded');this.open();this.removeEvents('contentLoaded');return this;},open:function(){this.element.setStyle('display','block').get('morph',{transition:'bounce:out'}).start({left:this.x,top:this.y,opacity:1});return this;},close:function(){this.fireEvent('beforeClose');this.removeEvents('beforeClose');this.element.morph({'opacity':0});},toElement:function(){return this.element;}});