var basketSetup=function(){var price=Ojay(".total-price .number");var updatePrice=function(){Ojay.HTTP.GET("/basket-total.html",{},{onSuccess:function(response){price.setContent("&pound;"+response.responseText)}})};Ojay("a.remove").on("click",function(link,evnt){var container=link;while(!container.hasClass("basket-item")){container=container.parents()}if(!container.hasClass("upsell")){return }evnt.stopDefault();Ojay.HTTP.GET(link.node.href,{},{onSuccess:function(response){container.remove();updatePrice();var removers=Ojay("a.remove").toArray(),index=0;removers.forEach(function(rem,i){var uri=Ojay.URI.parse(rem.href);if(uri.params.index===undefined){return }uri.params.index=(index++);rem.href=uri.toString()});var table=Ojay(".basket-upsells");table.insert(response.responseText,"after");table.remove()}})});var overlay=new PanelOverlay({className:"basket-overlay",width:850});var addFormListeners={accommodation:function(){var type=Ojay.byId("site/transfer.sku"),duration=Ojay.byId("site/accommodation.duration"),update=function(){Ojay.HTTP.GET("/ajax-accommodation-upsell-price.html",{Psku:type.node.value,duration:duration.node.value}).insertInto(".upsell-price")};[type,duration].forEach({on:["change",update]});update()},transfer:function(){var type=Ojay.byId("site/transfer.sku"),update=function(){Ojay.HTTP.GET("/ajax-transfer-upsell-price.html",{Psku:type.node.value}).insertInto(".upsell-price")};type.on("change",update);update()}};Ojay("body").on("click",Ojay.delegateEvent({"a.add-button":function(link,evnt){evnt.stopDefault();var type=Ojay.URI.parse(link.node.href).params.type;Ojay.HTTP.GET(link.node.href).insertInto(overlay)._(overlay).fitToContent().center().show("fade")._(Ojay.Forms.reattach)._(addFormListeners[type])}}));Ojay.Forms(function(){with(this){["accommodation","transfer"].forEach(function(field){form("site/"+field).submitsUsingAjax();when("site/"+field).responseArrives(function(response){response.insertInto(overlay);response.evalScripts();overlay.fitToContent().center();Ojay.Forms.reattach()})})}});Ojay.Overlay.on("redirect")._(overlay).hide()};if(top.location!=location){top.location.href=document.location.href}Ojay.HtmlBuilder.include({input:Ojay.HTML.input.wrap(function(){var B=Array.from(arguments),A=B.shift().apply(null,B);Ojay(A).addClass(A.type);return A})});Checkout={TITLE_FIELD:"Eothercommerce/ExpressBasket.billingAddress.title",FIRST_NAME_FIELD:"othercommerce/ExpressBasket.user.firstName",SURNAME_FIELD:"othercommerce/ExpressBasket.user.lastName",DELIVERY:"othercommerce/ExpressBasket.deliveryAddress.",BILLING:"othercommerce/ExpressBasket.billingAddress.",ADDRESS1_FIELD:"address1",ADDRESS2_FIELD:"address2",CITY_FIELD:"city",COUNTY_FIELD:"county",POSTCODE_FIELD:"postcode",COUNTRY_FIELD:"country",CARD_TYPE_FIELD:"Eothercommerce/ExpressBasket.payment.cardType",SECTION_CLASS:".section",FADE_OPACITY:0.5,FADE_TIME:0.4,getInputs:function(C,B){var A=C.descendants("input, textarea, select");if(B){A=A.filter(function(D){return D.node.name==B})}return A},highlightActiveSection:function(B){var E=B.descendants(this.SECTION_CLASS),A=this.getInputs(B),C=B.descendants(".invalid"),D=(C.node?C.ancestors(this.SECTION_CLASS):E).at(0);D.addClass("current-section");(C.node?this.getInputs(C):A).node.focus();A.on("focus",this.focus,this);E.on("click",this.swapSection,this);E.forEach(function(H,F){if(F==E.length-1){return }var G=Ojay.HTML.input({type:"submit",value:"Next section",className:"next-section"});Ojay(G).on("click",function(I,K){K.stopEvent();var J=E.at(F+1);this.swapSection(J);J.descendants("select, input, textarea").node.focus()},this);H.insert(G)},this);this._sections=E;this._activeSection=D},focus:function(A){A=Ojay(A);A.node.focus();var B=A.ancestors(this.SECTION_CLASS);this.swapSection(B)},swapSection:function(A){if(this._activeSection){if(Checkout.loginRequired&&this._activeSection.node==this._sections.at(0).node){return Checkout._accountLookup._checkAddress()}if(this._activeSection.node==A.node){return }this._activeSection.removeClass("current-section")}A.addClass("current-section");Ojay(document.documentElement).scroll([0,A.getRegion().top],1.5);this._activeSection=A},toggle:function(D,C){D=Ojay(D);var A=Ojay(C.using);function B(){var E=A.node.checked;if(C.invert){E=!E}D[E?"show":"hide"]()}A.on("click",B);B()},AccountLookup:new JS.Class({include:Ojay.Observable,extend:{CHECK_URL:"/shop/checkout/ajax/ajax-login.html",RESET_URL:"/shop/checkout/ajax/reset-password.html",DATA_URL:"/shop/addressBook/addresses.js",EMAIL_FIELD:"othercommerce/ExpressBasket.credentials.email",ECONFIRM_FIELD:"othercommerce/ExpressBasket.confirmEmail",PASSWORD_FIELD:"othercommerce/ExpressBasket.credentials.password",PCONFIRM_FIELD:"othercommerce/ExpressBasket.recipientUser.confirmPassword",WRAPPER_SELECTOR:".opc-fields"},initialize:function(C,J){Checkout._accountLookup=this;this._form=Ojay(C);this._options=J||{};this._checkUrl=this._options.checkUrl||this.klass.CHECK_URL;this._resetUrl=this._options.resetUrl||this.klass.RESET_URL;this._dataUrl=this._options.dataUrl||this.klass.DATA_URL;var G=this._options.emailField||this.klass.EMAIL_FIELD,A=this._options.confirmField||this.klass.ECONFIRM_FIELD,H=this._options.passwordField||this.klass.PASSWORD_FIELD,I=this._options.pconfirmField||this.klass.PCONFIRM_FIELD;this._email=Checkout.getInputs(this._form,G);this._confirm=Checkout.getInputs(this._form,A);this._password=Checkout.getInputs(this._form,H);this._pconfirm=Checkout.getInputs(this._form,I);this._selector=this._options.wrapper||this.klass.WRAPPER_SELECTOR;var F=Checkout.DELIVERY;this._titleField=Checkout.getInputs(this._form,Checkout.TITLE_FIELD);this._firstNameField=Checkout.getInputs(this._form,Checkout.FIRST_NAME_FIELD);this._lastNameField=Checkout.getInputs(this._form,Checkout.SURNAME_FIELD);this._address1Field=Checkout.getInputs(this._form,F+Checkout.ADDRESS1_FIELD);this._address2Field=Checkout.getInputs(this._form,F+Checkout.ADDRESS2_FIELD);this._cityField=Checkout.getInputs(this._form,F+Checkout.CITY_FIELD);this._countyField=Checkout.getInputs(this._form,F+Checkout.COUNTY_FIELD);this._postcodeField=Checkout.getInputs(this._form,F+Checkout.POSTCODE_FIELD);this._countryField=Checkout.getInputs(this._form,"P"+F+Checkout.COUNTRY_FIELD);var E,D,B=Ojay.HTML.span({className:"account-lookup"},function(K){E=Ojay(K.button({className:"account-lookup"},"Sign in"));D=Ojay(K.span({className:"login-status"}))});this._password.insert(B,"after");E.on("click",Ojay.stopDefault)._(this)._lookupData();this._statusDisplay=D;this._signinButton=E;this._generateToggles()},_generateToggles:function(){var A=Ojay("input[type=radio]").filter(function(C){return C.node.name==(this._options.radioName||"othercommerce/ExpressBasket.newCustomer")},this).toArray();if(!A[0]){return }var B=function(){var C=A.filter("checked")[0];if(C===A[0]){[this._confirm,this._pconfirm].forEach(it().ancestors(this._selector).show());Ojay(".password-snippet").show();this._signinButton.hide()}else{[this._confirm,this._pconfirm].forEach(it().ancestors(this._selector).hide());Ojay(".password-snippet").hide();this._signinButton.show()}}.bind(this);B();A.forEach(function(C){Ojay(C).on("click",B)})},_lookupData:function(){this._statusDisplay.setContent("");var A={email:this._email.node.value,password:this._password.node.value};Ojay.HTTP.POST(this._dataUrl,A,{onSuccess:function(B){var C=B.parseJSON(),D=C.addresses;if(C.error){return this._statusDisplay.setContent(C.error)}this.notifyObservers("populate",C);if(!D[0]){return }Checkout.loginRequired=false;["title","firstName","lastName"].forEach(function(E){Ojay.Forms.setValue(this["_"+E+"Field"],D[0][E])},this);Checkout.Address.FIELDS.forEach(function(F){var E=this["_"+F+"Field"];if(!E){return }Ojay.Forms.setValue(E,D[0][F])},this)}.bind(this)})}}),AddressHelper:new JS.Class({extend:{SEARCH_URL:"/shop/checkout/ajax/addresses.xml"},initialize:function(B,A,C){this._form=Ojay(B);this._container=this._form.descendants(A);this._container.insert(this.getHTML());C=C||Checkout.DELIVERY;this._address1Field=Checkout.getInputs(this._form,C+Checkout.ADDRESS1_FIELD);this._address2Field=Checkout.getInputs(this._form,C+Checkout.ADDRESS2_FIELD);this._cityField=Checkout.getInputs(this._form,C+Checkout.CITY_FIELD);this._countyField=Checkout.getInputs(this._form,C+Checkout.COUNTY_FIELD);this._postcodeField=Checkout.getInputs(this._form,C+Checkout.POSTCODE_FIELD);this._countryField=Checkout.getInputs(this._form,"P"+C+Checkout.COUNTRY_FIELD)},getHTML:function(){if(this._html){return this._html}this._html=Ojay(Ojay.HTML.form(function(A){A.p("Enter a postcode and search:");this._postcode=A.input({type:"text"});this._button=A.input({type:"submit",value:"Search"});this._menu=Ojay(A.div(function(B){B.p({className:"choose-address"},"Choose your address from the list:");this._select=Ojay(B.select())}.bind(this)))}.bind(this)));this._html.on("submit",Ojay.stopDefault)._(this)._postcodeSearch();this._select.on("change")._(this)._selectAddress();this._menu.hide();return this._html},getMenu:function(){return this._menu},_postcodeSearch:function(){var A=this._postcode.value;this._button.value="Searching...";Ojay.HTTP.GET(this.klass.SEARCH_URL,{postcode:A},{onSuccess:function(B){var C=Checkout.Address.fromXML(B.responseXML);this.setAddresses(C);this._select.node.focus()}.bind(this),onComplete:function(){this._button.value="Search"}.bind(this)})},_selectAddress:function(B){B=(B===undefined)?Number(this._select.node.value):B;var A=this._addresses[B];if(!A){return }Checkout.Address.FIELDS.forEach(function(D){var C=this["_"+D+"Field"];if(!C){return }Ojay.Forms.setValue(C,A[D])},this)},setAddresses:function(C,D){this._addresses=C||[];var A;if(C.length===0){A="<option>No addresses found</option>"}else{A="<option>Please select an address</option>";C.forEach(function(E,F){A+='<option value="'+F+'">'+E.toShortAddress()+"</option>"})}this._select.setContent(A);this._select.node.options[0].selected=true;var B=(this._addresses.length>0);this._menu[B?"show":"hide"]();if(D){this._selectAddress(0)}}}),Address:new JS.Class({initialize:function(A){this.klass.FIELDS.forEach(function(B){this[B]=""},this);this.set(A)},set:function(A){JS.extend(this,A)},toString:function(){return this.klass.FIELDS.map(function(A){return this[A]},this).join(", ")},toShortAddress:function(){return this.address1+(this.address2?", "+this.address2:"")+", "+this.city},extend:{fromXML:function(B){var F=B.documentElement;var E=F.getElementsByTagName("address");var G=[],A,D;for(var C=0,H=E.length;C<H;C++){D=E.item(C).firstChild,A=new this;G.push(A);while(D){if(D.nodeType==Ojay.HTML.ELEMENT_NODE&&D.firstChild){A[D.nodeName]=D.firstChild.data}D=D.nextSibling}}return G},FIELDS:"addressName title firstName lastName address1 address2 address3 city county country postcode".split(" ")}}),AddressBook:new JS.Class({include:Ojay.Observable,extend:{INDEX_URL:"/shop/addressBook/addresses.js",CREATE_URL:"/shop/addressBook/editAddress.js",UPDATE_URL:"/shop/addressBook/editAddress.js",DELETE_URL:"/shop/addressBook/deleteAddress.js",COUNTRIES_URL:"/shop/addressBook/countries.js",TITLES_URL:"/shop/addressBook/titles.js",MASK_COLOR:"#FFFFFF",MASK_OPACITY:0.5,CONTAINER_CLASS:"address-book",getMetadata:function(){Ojay.HTTP.GET(this.COUNTRIES_URL,{},{onSuccess:function(A){this.COUNTRIES=A.parseJSON().countries;if(this.TITLES){this.notifyObservers("metadataready")}}.bind(this)});Ojay.HTTP.GET(this.TITLES_URL,{},{onSuccess:function(A){this.TITLES=A.parseJSON().titles;if(this.COUNTRIES){this.notifyObservers("metadataready")}}.bind(this)})},populateSelect:function(A,B){A.setContent(B.map(function(C){return'<option value="'+C.id+'">'+C.name+"</option>"}).join(""));A.node.options[0].selected=true},Address:new JS.Class({initialize:function(A,B){this._book=A;this._elements={};this.getHTML();this.set(new Checkout.Address(B))},getHTML:function(){var A=this,B=A._elements;if(B._li){return B._li}B._li=Ojay(Ojay.HTML.li(function(C){B._destroy=Ojay(C.span({className:"delete"},"Delete"));B._name=Ojay(C.span({className:"address-name"}))}));B._name.on("click")._(this._book).load(this);B._destroy.on("click")._(this._book).destroy(this);return B._li},load:function(){this._elements._li.addClass("selected")},unload:function(){this._elements._li.removeClass("selected")},set:function(A){if(this._address){this._id=this._address.id}if(!A.id){A.id=this._id}this._address=A;this._elements._name.setContent(A.addressName||A.address1);this._elements._destroy[A.defaultAddress?"hide":"show"]()},save:function(A,C,B){this.set(A);Ojay.HTTP.POST(this._book.klass.UPDATE_URL,this.getPostData(),{onComplete:C.bind(B||null),onSuccess:function(D){var E=D.parseJSON();if(!this._address.id&&E.id){this._id=this._address.id=E.id}}.bind(this)})},destroy:function(B,A){Ojay.HTTP.POST(this._book.klass.DELETE_URL,{id:this._address.id},{onComplete:B.bind(A||null)})},getPostData:function(){if(!this._address){return{}}var A={};Checkout.Address.FIELDS.forEach(function(B){A[B]=this._address[B]},this);if(this._address.id){A.id=this._address.id}return A}})},initialize:function(){this._mask=new Ojay.PageMask({color:this.klass.MASK_COLOR,opacity:this.klass.MASK_OPACITY});this._overlay=new Ojay.ContentOverlay({className:this.klass.CONTAINER_CLASS+"-overlay",width:728,height:520});this._mask.positionBehind(this._overlay);this._overlay.getContentElement().addClass("clear");var A=Ojay(Ojay.HTML.div({className:"close-button"},"Close"));A.on("click")._(this).hide();this._overlay.getContainer().insert(A,"top");this._elements={};this._overlay.setContent(this.getHTML())},getHTML:function(){var A=this,B=A._elements;if(B._container){return B._container}B._container=Ojay(Ojay.HTML.div({className:this.klass.CONTAINER_CLASS},function(C){C.h2("Your address book"),C.p({className:"address-msg"},"Choose an address from the list to edit it, or enter a new address and click 'Save' to add it to your address book.");C.div({className:"list"},B._list=Ojay(C.ul()),B._add=Ojay(C.button({className:"add-address"},"New address")));B._form=Ojay(C.form(function(D){D.div(function(E){E.label("Address name");B._addressName=E.input({type:"text"})});D.div({className:"address-name"},function(E){E.label("Name");B._title=Ojay(E.select());B._firstName=E.input({type:"text"});B._lastName=E.input({type:"text"})});D.div(function(E){E.label("Address");B._address1=E.input({type:"text"})});D.div(function(E){B._address2=E.input({type:"text"})});D.div(function(E){E.label("Town or city");B._city=E.input({type:"text"})});D.div(function(E){E.label("Postcode");B._postcode=E.input({type:"text"})});D.div(function(E){E.label("County");B._county=E.input({type:"text"})});D.div(function(E){E.label("Country");B._country=Ojay(E.select())});D.div(function(E){B._save=Ojay(E.input({type:"submit",value:"Save"}))})}))}));this._populateSelects();B._add.on("click",Ojay.stopDefault)._(this).addAddress();B._form.on("submit",Ojay.stopDefault)._(this).save();return B._container},_populateSelects:function(){if(!this.klass.COUNTRIES||!this.klass.TITLES){return this.klass.on("metadataready")._(this)._populateSelects()}this.klass.populateSelect(this._elements._title,this.klass.TITLES);this.klass.populateSelect(this._elements._country,this.klass.COUNTRIES)},_updateAddresses:function(B,A){Ojay.HTTP.GET(this.klass.INDEX_URL,{},{onSuccess:function(C){var D=C.parseJSON(),E=D.addresses;if(D.error){return }this._elements._list.setContent("");this._addresses=E.map(function(G){var F=new this.klass.Address(this,G);this._elements._list.insert(F.getHTML());return F},this);if(this._addresses[0]){this.load(this._addresses[0])}B.call(A||null)}.bind(this)})},show:function(){this._updateAddresses(function(){this._mask.show("fade");this._overlay.center().show("fade")},this)},hide:function(){this._mask.hide("fade");this._overlay.hide("fade");this.notifyObservers("close")},addAddress:function(B){var A=new this.klass.Address(this,new Checkout.Address({addressName:"New address"}));this._addresses.push(A);this._elements._list.insert(A.getHTML());this.load(A,B)},getAddresses:function(){return this._addresses.map("_address")},load:function(A,B){if(this._activeAddress){this._activeAddress.unload()}this._activeAddress=A;A.load();if(B!==false){Checkout.Address.FIELDS.forEach(function(D){var C=this._elements["_"+D];if(!C){return }Ojay.Forms.setValue(C,A._address[D])},this)}this._elements._addressName.focus()},save:function(){if(!this._activeAddress){this.addAddress(false)}var B={};Checkout.Address.FIELDS.forEach(function(D){var C=this._elements["_"+D];if(!C){return }B[D]=(C.node||C).value},this);var A=new Checkout.Address(B);this._elements._save.node.value="Saving...";this._activeAddress.save(A,function(){this._elements._save.node.value="Save"},this)},destroy:function(A){A.destroy(function(){var B=this._addresses.indexOf(A);this._addresses.splice(B,1);A.getHTML().remove()},this)}}),CardHelper:new JS.Class({extend:{CONTAINER_CLASS:"card-helper",INNER_CLASS:"image",MAESTRO_ONLY:["othercommerce/ExpressBasket.payment.issueNumber","Dothercommerce/ExpressBasket.payment.startDate:MONTH","Dothercommerce/ExpressBasket.payment.startDate:YEAR"],FIELD_CONTAINER:".opc-fieldcol"},initialize:function(B,A){this._form=Ojay(B);this._container=Ojay(A);this._select=this._container.descendants("select");this._container.insert(this.getHTML());this._maestroFields=Ojay(this.klass.MAESTRO_ONLY.map(function(C){return Checkout.getInputs(this._form,C).node},this)).ancestors(this.klass.FIELD_CONTAINER);this._maestroFields.setStyle({overflow:"hidden"});this._height=this._maestroFields.getHeight();this._isMaestro=true;this._select.on("change")._(this).update();this.update()},getHTML:function(){if(this._html){return this._html}this._html=Ojay.HTML.div({className:this.klass.CONTAINER_CLASS},function(A){this._image=Ojay(A.div({className:this.klass.INNER_CLASS}))}.bind(this));return this._html},update:function(){var A=this._select.node.value;A=A.match(/[a-z]+/ig).pop().toLowerCase();this._image.setClass(this.klass.INNER_CLASS+" "+A);var B=(A=="switch");if(B!=this._isMaestro){if(B){this._maestroFields.show()}this._maestroFields.animate({height:{to:B?this._height:0},opacity:{to:B?1:0}},0.4)._(function(C){if(!B){C._maestroFields.hide()}},this)}this._isMaestro=B}})};function panel(B,D,C){var A=(typeof D=="function");C=C||Ojay.HTML;return C.div({className:"panel "+B},function(F){var E=F.div({className:"panel-c"},function(G){G.div({className:"panel-t"});if(A){D(G)}});if(!A){Ojay(E).insert(D,"bottom")}F.div({className:"panel-b"},function(G){G.div()})})}var Panel=new JS.Class({initialize:function(A,C,B){this._classes=A;this._block=C;this._HTML=B;this.getHTML()},getHTML:function(){if(this._html){return this._html}var B=this,C=B._classes,E=B._block,D=B._HTML;var A=(typeof E=="function");D=D||Ojay.HTML;this._html=Ojay(D.div({className:"panel"+(C?" "+C:"")},function(F){F.div({className:"panel-c"},function(G){G.div({className:"panel-t"});B._content=Ojay(G.div(function(H){if(A){E(H)}}))});if(!A){B._content.insert(E,"bottom")}F.div({className:"panel-b"},function(G){G.div()})}));return this.getHTML()},setContent:function(){this._content.setContent.apply(this._content,arguments);return this},insert:function(){this._content.insert.apply(this._content,arguments);return this}});parseDate=function(C){var B=Number(C.substr(0,4)),D=Number(C.substr(4,2))-1,A=Number(C.substr(6,2));return new Date(B,D,A)};Ojay.onDOMReady(function(){var A=new PanelOverlay({className:"basket-overlay"});Ojay("body").on("click",Ojay.delegateEvent({"a.more-info":function(B,C){C.stopDefault();Ojay.HTTP.GET(B.node.href).insertInto(A)._(A).fitToContent().center().show("fade")},"a.popup-link":function(D,E){E.stopDefault();var C=new PanelOverlay({width:600,height:600});var B=Ojay(Ojay.HTML.div({className:"overflow-box"}));C.insert(B);Ojay.HTTP.GET(D.node.href).insertInto(B)._(C).center().show("fade")}}));Ojay("a.new-window").set({target:"_blank"})});InfiniteList=new JS.Class({extend:{PER_PAGE:9},initialize:function(A,C,B){this._container=A;this._trigger=C;this._options=B||{};this._options.perPage=this._options.perPage||this.klass.PER_PAGE},getInitialState:function(){return{page:1}},changeState:function(A){this._gotoPage(A.page);return this},setup:function(){this._container=Ojay(this._container);this._trigger=Ojay(this._trigger);this._trigger.on("click",Ojay.stopDefault)._(this).getNext();this._state=this.getInitialState();this._gotoPage(this._state.page);return this},getNext:function(){this.changeState({page:this._state.page+1});return this},getPages:function(){if(!this._options.total){return 0}return(this._options.total/this._options.perPage).ceil()},_gotoPage:function(E){E=Number(E);this._state.page=E;var C=this._trigger.node.innerHTML.stripTags(),A=this.getPages(),B=this._trigger;B.show().setContent(Ojay.HTML.img({src:this.klass.LOADER_IMAGE}));var D=Ojay.URI.parse(this._trigger.node.href);D.setParam("pageNo",1);D.setParam("pageLen",this._options.perPage*E);Ojay.HTTP.GET(D).insertInto(this._container)._(function(F){B[E===A?"hide":"show"]();if(C){B.setContent(F._format(C))}},this)},_format:function(B){var A=this.getPages();var C=(A==this._state.page+1)?(this._options.total-1)%this._options.perPage+1:this._options.perPage;return B.replace(/\d+/g,C)}});MenuAutocomplete=new JS.Class({include:Ojay.Observable,initialize:function(A,B){this._textField=Ojay(A);this._options=B||{};this._queryURL=this.getQueryURL();this._queryParam=this.getQueryParam();this._dirty=false;this._timeout=this._options.timeout||this.klass.TIMEOUT;setInterval(this.method("_check"),1000*this._timeout/4);this._textField.on("keydown",function(){this._dirty=true;this._lastKeyPress=Number(new Date)},this);this._overlay=new Ojay.ContentOverlay({className:"autocomplete-overlay"});var C=this._elements={};this._elements._container=Ojay.HTML.div(function(D){C._categories=Ojay(D.div({className:"categories"}));C._results=Ojay(D.div({className:"results"},function(E){C._summary=Ojay(E.div({className:"summary"}));C._listing=Ojay(E.div({className:"listing"}))}))});this._overlay.setContent(C._container);this._textField.node.setAttribute("autocomplete","off");Ojay("body").on("click",function(D,G){var F=G.getTarget().node,E=this._overlay.getContainer().node;while(F){if(F==E){return }F=F.parentNode}this._overlay.hide()},this)},getQueryURL:function(){var A=this._textField.ancestors("form");if(!A.node){return this._options.queryURL}return A.node.action},getQueryParam:function(){return this._options.queryParam||this._textField.node.name},getQueryData:function(){var A={};A[this._queryParam]=this._textField.node.value;return A},_check:function(){var A=(Number(new Date)-this._lastKeyPress)/1000;if(this._dirty&&A>this._timeout){this.request(this.getQueryData(),true)}},request:function(A,B){this._dirty=false;Ojay.HTTP.GET(this._queryURL,A,{onSuccess:function(C){this._updateResults(C.parseJSON(),B)}.bind(this)})},_updateResults:function(C,D){if(!C||!C.results){return }this._elements._summary.setContent(C.searchSummary||"");var B=["odd","even"],A=Ojay(Ojay.HTML.div());this._elements._listing.setContent(A);C.results.forEach(function(E,F){E=new this.klass.SearchResult(this,E,{className:B[F%B.length]});A.insert(E.getHTML())},this);if(D){this._elements._categories.setContent("");C.related&&C.related.forEach(function(E,F){E=new this.klass.Category(this,E);this._elements._categories.insert(E.getHTML())},this)}this._overlay.show()._(function(F){if(!C.results||C.results.length==0){return }var E=new Ojay.Paginator(A,{direction:"vertical",rows:5,columns:1});E.setup();E.addControls("after")},this);this._positionOverlay()},_positionOverlay:function(){var A=this._textField.getRegion();this._overlay.setPosition(A.left-145,A.bottom).fitToContent()},_highlightCategory:function(A){if(this._currentCategory){this._currentCategory.highlight(false)}this._currentCategory=A},extend:{TIMEOUT:0.5,SearchResult:new JS.Class({extend:{CLASS:"search-result"},initialize:function(A,C,B){this._title=C.title;this._url=C.url;this._options=B||{}},getHTML:function(){return Ojay.HTML.div({className:this.klass.CLASS+" "+this._options.className},Ojay.HTML.a({href:this._url},this._title))}}),Category:new JS.Class({extend:{CLASS:"category"},initialize:function(A,B){this._owner=A;this._title=B.name;this._params=B.params;this._elements={};if(B.original){this.highlight(true)}},getHTML:function(){if(this._elements._container){return this._elements._container}this._elements._container=Ojay(Ojay.HTML.div({className:this.klass.CLASS},this._title));this._elements._container.on("click",function(){this.highlight();this._owner.request(this._params)},this);return this.getHTML()},highlight:function(A){if(A!==false){this._owner._highlightCategory(this)}this.getHTML()[(A!==false)?"addClass":"removeClass"]("highlight")}})}});PanelOverlay=new JS.Class(Ojay.ContentOverlay,{extend:{LAYER:10000},initialize:function(B){this._panel=new Panel("drop-shadow-panel");var A=Ojay(Ojay.HTML.div({className:"close-button"},"Close"));this.callSuper();this.setLayer(this.klass.LAYER);this.getContainer().insert(A,"top");A.on("click")._(this).hide("fade");this.getContentElement().insert(this._panel.getHTML())},setContent:function(){this._panel.setContent.apply(this._panel,arguments);return this},insert:function(){this._panel.insert.apply(this._panel,arguments);return this}})