/* Contao Open Source CMS, (c) 2005-2015 Leo Feyer, LGPL license */
Request.Contao=new Class({Extends:Request.JSON,options:{followRedirects:!0,url:window.location.href},initialize:function(t){if(t)try{this.options.url=t.field.getParent("form").getAttribute("action")}catch(e){}this.parent(t)},success:function(t){var e,s=this.getHeader("X-Ajax-Location");if(s&&this.options.followRedirects)return void location.replace(s);try{e=this.response.json=JSON.decode(t,this.options.secure)}catch(i){e={content:t}}null==e&&(e={content:""}),""!=e.content&&(e.content=e.content.stripScripts(function(t){e.javascript=t.replace(/<!--|\/\/-->|<!\[CDATA\[\/\/>|<!\]\]>/g,"")}),e.javascript&&this.options.evalScripts&&Browser.exec(e.javascript)),this.onSuccess(e.content,e)}}),Request.Mixed=Request.Contao,Tips.Contao=new Class({Extends:Tips,options:{id:"tip",onShow:function(){this.tip.setStyle("display","block")},onHide:function(){this.tip.setStyle("display","none")},title:"title",text:"",showDelay:1e3,hideDelay:100,className:"tip-wrap",offset:{x:16,y:16},windowPadding:{x:0,y:0},fixed:!0,waiAria:!0},position:function(t){this.tip||document.id(this);var e=window.getSize(),s=window.getScroll(),i={x:this.tip.offsetWidth,y:this.tip.offsetHeight},n={x:"left",y:"top"},o={y:!1,x2:!1,y2:!1,x:!1},a={};for(var r in n)a[n[r]]=t.page[r]+this.options.offset[r],a[n[r]]<0&&(o[r]=!0),a[n[r]]+i[r]-s[r]>e[r]-this.options.windowPadding[r]&&("x"==r&&(a[n[r]]=t.page[r]-this.options.offset[r]-i[r]),o[r+"2"]=!0);var h=this.tip.getElement("div.tip-top");o.x2?(a.left+=24,h.setStyles({left:"auto",right:"9px"})):(a.left-=9,h.setStyles({left:"9px",right:"auto"})),this.fireEvent("bound",o),this.tip.setStyles(a)},hide:function(t){this.tip||document.id(this),this.fireEvent("hide",[this.tip,t])}}),Class.refactor(Drag,{attach:function(){return this.handles.addEvent("touchstart",this.bound.start),this.previous.apply(this,arguments)},detach:function(){return this.handles.removeEvent("touchstart",this.bound.start),this.previous.apply(this,arguments)},start:function(){document.addEvents({touchmove:this.bound.check,touchend:this.bound.cancel}),this.previous.apply(this,arguments)},check:function(t){this.options.preventDefault&&t.preventDefault();var e=Math.round(Math.sqrt(Math.pow(t.page.x-this.mouse.start.x,2)+Math.pow(t.page.y-this.mouse.start.y,2)));e>this.options.snap&&(this.cancel(),this.document.addEvents({mousemove:this.bound.drag,mouseup:this.bound.stop}),document.addEvents({touchmove:this.bound.drag,touchend:this.bound.stop}),this.fireEvent("start",[this.element,t]).fireEvent("snap",this.element))},cancel:function(){return document.removeEvents({touchmove:this.bound.check,touchend:this.bound.cancel}),this.previous.apply(this,arguments)},stop:function(){return document.removeEvents({touchmove:this.bound.drag,touchend:this.bound.stop}),this.previous.apply(this,arguments)}}),Class.refactor(Sortables,{initialize:function(t,e){return e.dragOptions=Object.merge(e.dragOptions||{},{preventDefault:e.dragOptions&&e.dragOptions.preventDefault||Browser.Features.Touch}),this.previous.apply(this,arguments)},addItems:function(){return Array.flatten(arguments).each(function(t){this.elements.push(t);var e=t.retrieve("sortables:start",function(e){this.start.call(this,e,t)}.bind(this));(this.options.handle?t.getElement(this.options.handle)||t:t).addEvents({mousedown:e,touchstart:e})},this),this},removeItems:function(){return $$(Array.flatten(arguments).map(function(t){this.elements.erase(t);var e=t.retrieve("sortables:start");return(this.options.handle?t.getElement(this.options.handle)||t:t).removeEvents({mousedown:e,touchend:e}),t},this))},getClone:function(t,e){if(!this.options.clone)return new Element(e.tagName).inject(document.body);if("function"==typeOf(this.options.clone))return this.options.clone.call(this,t,e,this.list);var s=this.previous.apply(this,arguments);return s.addEvent("touchstart",function(t){e.fireEvent("touchstart",t)}),s}});