/* Contao Open Source CMS, (c) 2005-2016 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(t){}this.parent(t)},success:function(t){var e,i=this.getHeader("X-Ajax-Location");if(i&&this.options.followRedirects)return void location.replace(i);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(),i=window.getScroll(),s={x:this.tip.offsetWidth,y:this.tip.offsetHeight},n={x:"left",y:"top"},o={y:!1,x2:!1,y2:!1,x:!1},r={};for(var h in n)r[n[h]]=t.page[h]+this.options.offset[h],r[n[h]]<0&&(o[h]=!0),r[n[h]]+s[h]-i[h]>e[h]-this.options.windowPadding[h]&&("x"==h&&(r[n[h]]=t.page[h]-this.options.offset[h]-s[h]),o[h+"2"]=!0);var a=this.tip.getElement("div.tip-top");o.x2?(r.left+=24,a.setStyles({left:"auto",right:"9px"})):(r.left-=9,a.setStyles({left:"9px",right:"auto"})),this.fireEvent("bound",o),this.tip.setStyles(r)},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 i=this.previous.apply(this,arguments);return i.addEvent("touchstart",function(t){e.fireEvent("touchstart",t)}),i}}),Class.refactor(Request.Queue,{onComplete:function(){this.fireEvent("complete",arguments)},onCancel:function(){this.options.autoAdvance&&!this.error&&this.resume(),this.fireEvent("cancel",arguments)},onSuccess:function(){this.options.autoAdvance&&!this.error&&this.resume(),this.fireEvent("success",arguments),this.queue.length||this.isRunning()||this.fireEvent("end")},onFailure:function(){this.error=!0,!this.options.stopOnFailure&&this.options.autoAdvance&&this.resume(),this.fireEvent("failure",arguments),this.queue.length||this.isRunning()||this.fireEvent("end")},onException:function(){this.error=!0,!this.options.stopOnFailure&&this.options.autoAdvance&&this.resume(),this.fireEvent("exception",arguments)}});