//Copyright © [Year(s)] Nokia Corporation and/or its subsidiary(-ies).

Fp.SelectionList={elements:[],domList:Fp.byId("selectionUl"),input:Fp.byId("selectionInput"),timeoutFun:null,id:"",footer:Fp.byId("selectionInput").parentNode,content:Fp.byId("selectionUl").parentNode,init:function(){},displayList:function(a,e,j){j=j||{};if(j.filtering){this.footer.style.display="block";Fp.byId("listSelection").className+=" hasFilter";}else{this.footer.style.display="none";Fp.byId("listSelection").className="window";}this.domList.innerHTML="";this.activateOnKeyDown();var c=[],g;for(g in a){c.push({id:g,name:a[g]});}if(j.sort){if(Fp.Lang.isPinyin&&Fp.LangPinyin){c=Fp.LangPinyin.sort(c,function(i){return i.name;});}else{c.sort(function(k,i){if(k.name===i.name){return 0;}return(k.name>i.name?1:-1);});}}for(var d=0,b=c.length;d<b;d++){var h=document.createElement("li"),f=document.createElement("span");h.id=c[d].id;h.className="btnLeft";f.className="btnRight";f.innerHTML=c[d].name;h.appendChild(f);this.domList.appendChild(h);new Fp.Utils.addTapEvent({element:h,onEvent:function(i){if(!j.multipage){Fp.Pages.history.pop();}e.call(this,{id:i.target.id||i.target.parentNode.id,name:i.target.innerHTML});}});Fp.SelectionList.elements[c[d].id]=f;}this.domList.parentNode.scrollTop=0;},activateOnKeyDown:function(){Fp.SelectionList.input.onkeyup=function(a){clearTimeout(Fp.SelectionList.timeoutFun);Fp.SelectionList.timeoutFun=setTimeout(function(){Fp.SelectionList.domList.style.display="none";var e=Fp.SelectionList.input.value.toLowerCase(),d=Fp.SelectionList.elements,b=e.length;for(elementKey in d){var c=d[elementKey];if(c.innerHTML.toLowerCase().substr(0,b)!==e){c.parentNode.style.display="none";}else{c.parentNode.style.display=null;}}Fp.SelectionList.domList.style.display="block";},300);};}};