var Results=Singleton({init:function(){this.resultItems={};this.imgResized=false},preloadImgs:function(){var A=Singleton({_imgList:[],_preImgs:[],_pointer:0,init:function(){this._imgList=$$(".result-image");var B=[];forEach(this._imgList,function(C,D){B.push(C.src+"?"+Math.random())},this);this._add(B)},_add:function(C){if(typeof C=="string"){C=[C]}for(var B=0;B<C.length;B++){this._preImgs[B]=new Image;this._preImgs[B].src=C[B];this._preImgs[B].onload=bind(function(D){this._preloaded(D)},this,B);this._preImgs[B].onerror=this._preImgs[B].onabort=bind(function(D){this._notPreloaded(D)},this,B)}},_checker:function(){if(++this._pointer==this._preImgs.length){Results.imgResized=true}},_preloaded:function(H){var F=100,D=76,E=this._preImgs[H].width,B=this._preImgs[H].height;var G=F/E,C=D/B;if(E<=F&&B<=D){this._imgList[H].width=E;this._imgList[H].height=B}else{if((G*B)<D){this._imgList[H].width=F;this._imgList[H].height=Math.ceil(G*B)}else{this._imgList[H].width=Math.ceil(C*E);this._imgList[H].height=D}}var I=$("result-item-preloader-image_"+this._imgList[H].id.match(/image_(.+)/)[1]);Style.set(I,{display:"none"});Style.set(this._imgList[H],{display:"block"});this._preImgs[H]=null;this._imgList[H]=null;window.setTimeout(bind(this._checker,this,H),5)},_notPreloaded:function(B){this._imgList[B].width=57;this._imgList[B].height=57;this._imgList[B].src=BaseURL+"/img/pkg-default.gif";this._imgList[B].style.padding="0 21px";var C=$("result-item-preloader-image_"+this._imgList[B].id.match(/image_(.+)/)[1]);Style.set(C,{display:"none"});Style.set(this._imgList[B],{display:"block"});this._preImgs[B]=null;this._imgList[B]=null;window.setTimeout(bind(this._checker,this,B),5)}})},initialize:function(){this.actCurrency=app.CookieManager.readCookie("actCurrency")||this.actCurrency;var D=STemplate.parse('<option ${selected} value="${value}">${value}</option>'),C="";for(var A in this.currencies){if(A==this.actCurrency){var B="selected='selected'"}else{B=""}if(this.currencies[A].Displayed){C+=D.process({value:A,selected:B})}}Layout.setText($("curreny_wrapper_inside"),'<select id="currency">'+C+"</select>");this.setCurrencies();Layout.show("order_currency");forEach($$("#result_items>div"),function(G,H){var E,F=G.id.match(/item_(.+)/)[1],G=this.resultItems[F]={"id":G.id,"className":G.className,"review":$("result-description-text_"+F),"subtitle":$("result-details-subtitle_"+F),"price":$("price_"+F),"taxinfo":$("taxinfo_"+F),"currencies":{currency:this.itemCurrencies[F].currency,price:(1/this.getCurrency(this.itemCurrencies[F].currency).CurrencyRate)*this.itemCurrencies[F].price,exact:(1/this.getCurrency(this.itemCurrencies[F].currency).CurrencyRate==1)?true:false}};(G.className.match("reviewed"))?E=300:E=400;Layout.setText(G.review,(G.review.innerHTML.length>400)?G.review.innerHTML.slice(0,E)+"...":G.review.innerHTML);Layout.setText(G.price,Layout.formatMoney(G.currencies.price))},this);Layout.show("result_items");Layout.show("resultpager");this.setCurrencies(this.actCurrency);Event.observe($("currency"),"change",Event.bindStop(this.setCurrencies,this));Event.observe($("resultpager_select"),"change",this.setFooter);forEach($$(".order_by"),function(E){Event.observe(E,"click",this.setOrderBy)},this)},_findMaxLength:function(C,A,F,D,E){D.innerHTML=F.substring(0,C);var B=D.offsetWidth;D.innerHTML=F.substring(0,A);var G=D.offsetWidth;if(B>=E){D.innerHTML=F.substring(0,C);return }else{if((B<E&&G-B<20)){return }else{if(E<=B+(G-B)/2){this._findMaxLength(C,parseInt(C+(A-C)/2),F,D,E)}else{if(E>=B+(G-B)/2){this._findMaxLength(parseInt(C+(A-C)/2),A,F,D,E)}}}}},getCurrency:function(A){return this.currencies[A]},checkCurrency:function(A){var B=this;pattern="";forEach(A,function(C){if(C.name.match(/(([\d]+?)( - )([\d]+)( [\S]+))|(([\d]+)( [\S]+))/)){C.name=C.name.replace(/(([\d]+?)( - )([\d]+)( [\S]+))|(([\d]+)( [\S]+))/,function(){var G=0,H=0,E=[],D="";forEach(arguments,function(I,J){for(var K in B.currencies){if(I==" "+K){H=J;D=K}if(!G&&I&&!isNaN(I)){G=J}}});for(var F=G;F<H;F++){if(!isNaN(arguments[F])){E.push(Math.round((B.currencies[B.actCurrency].CurrencyRate/B.currencies[D.replace(/^\s+|\s+$/g,"")].CurrencyRate)*arguments[F]))}else{E.push(arguments[F])}}E.push(" "+B.actCurrency);return E.join("")})}})},setOrderBy:function(F){var C=Event.element(F),E=C.name,D="ASC";var B="";if(E==actualParams.sortingKey){D=actualParams.sortingMethod=="ASC"?"DESC":"ASC"}if(location.search.indexOf("sortingKey")==-1){var A=app.queryPath.indexOf("?")==-1;B=(globals.notWL?urlNoPage+"sort":app.queryPath)+(location.search==""&&A?"?":"")+location.search+(location.search==""&&A?"":"&")+"sortingKey="+E+"&sortingMethod="+D}else{B=location.href.replace(/(sortingKey=)([\w]+)(&)(sortingMethod=)([\w]+)/,function(H,L,K,J,I,G){return L+E+J+I+D})}location.href=B},setCurrencies:function(A){this.actCurrency=$("currency").options[$("currency").selectedIndex].value;app.CookieManager.createCookie("actCurrency",this.actCurrency);forEach(this.resultItems,function(B,C){Layout.setText(B.price,Layout.formatMoney(this.currencies[this.actCurrency].CurrencyRate*B.currencies.price))},this);Layout.removeFocus("currency");document.body.focus();Filter.filterManager.udSelectEventHandler()},setFooter:function(A){if(location.search.indexOf("resultperpage")==-1){location.href=app.queryPath+(location.search==""?"?":"&")+"resultperpage="+$("resultpager_select").value}else{location.href=location.href.replace(/(resultperpage=)([\w]+)/,function(B,D,C){return D+$("resultpager_select").value})}},openDetails:function(D,C,A,B){location.href=urlNoPage+"detail-"+(C?C+"-":"")+D+".html"+(A?"#all="+A:"")},openPage:function(A){location.href=A},openDeepLink:function(C,B){var A=$("jumpdlg");if(safari&&detect("Safari")&&detect("Windows")){window.open(A.action+"?skuid="+C+"&clicklocation="+B,"_blank")}else{A.innerHTML="";input1=document.createElement("input");input1.name="skuid";input1.value=C;A.appendChild(input1);input2=document.createElement("input");input2.name="clicklocation";input2.value=B;A.appendChild(input2);
A.submit();return false}},renderDescription:function(){if(!this.descCounter){this.descCounter=0}document.write(ItemDescriptions[this.descCounter++])}})
