(function(){var K=90;var R=0;var V=null;var L=null;var N=0;var T=location.hash;var D="#_";var J=[];var G=0;var X;window.iui={showPage:function(Z,Y){if(Z){if(L){L.removeAttribute("selected");L=null}if(C(Z,"dialog")){S(Z)}else{var a=V;V=Z;if(a){setTimeout(B,0,a,Z,Y)}else{P(Z,a)}}}},showPageById:function(Z){var b=I(Z);if(b){var a=J.indexOf(Z);var Y=a!=-1;if(Y){J.splice(a,J.length)}iui.showPage(b,Y)}},showPageByHref:function(Z,a,d,b,Y){var c=new XMLHttpRequest();c.onerror=function(){if(Y){Y(false)}};c.onabort=function(){if(Y){Y(false)}};c.onreadystatechange=function(){if(c.readyState==4){if(b){Q(b,c.responseText)}else{var e=document.createElement("div");e.innerHTML=c.responseText;iui.insertPages(e.childNodes)}if(Y){setTimeout(Y,1000,true)}}};if(a){c.open(d||"GET",Z,true);c.setRequestHeader("Content-Type","application/x-www-form-urlencoded");c.setRequestHeader("Content-Length",a.length);c.send(a.join("&"))}else{c.open(d||"GET",Z,true);c.send(null)}},insertPages:function(Y){var a;for(var Z=0;Z<Y.length;++Z){var c=Y[Z];if(c.nodeType==1){if(!c.id){c.id="__"+(++G)+"__"}var b=I(c.id);if(b){b.parentNode.replaceChild(c,b)}else{document.body.appendChild(c)}if(c.getAttribute("selected")=="true"||!a){a=c}--Z}}if(a){iui.showPage(a)}},getSelectedPage:function(){for(var Y=document.body.firstChild;Y;Y=Y.nextSibling){if(Y.nodeType==1&&Y.getAttribute("selected")=="true"){return Y}}}};addEventListener("load",function(Y){var Z=iui.getSelectedPage();if(Z){iui.showPage(Z)}setTimeout(M,0);setTimeout(F,0);X=setInterval(F,300)},false);addEventListener("submit",function(Y){if(Y.target.method=="ajax"){Y.preventDefault()}else{O(Y.target);Y.preventDefault()}},false);addEventListener("click",function(a){var Z=A(a.target,"a");if(Z){function Y(){Z.removeAttribute("selected")}if(Z.href&&Z.hash&&Z.hash!="#"){Z.setAttribute("selected","true");iui.showPage(I(Z.hash.substr(1)));setTimeout(Y,500)}else{if(Z==I("backButton")){history.back()}else{if(Z.getAttribute("type")=="submit"){O(A(Z,"form"))}else{if(Z.getAttribute("type")=="cancel"){E(A(Z,"form"))}else{if(Z.target=="_replace"){Z.setAttribute("selected","progress");iui.showPageByHref(Z.href,null,null,Z,Y)}else{if(Z.target=="_slide"){Z.setAttribute("selected","progress");iui.showPageByHref(Z.href,null,null,null,Y)}else{if(!Z.target){Z.setAttribute("selected","progress");setTimeout(Y,500);return }else{return }}}}}}}a.preventDefault()}},true);addEventListener("click",function(Y){var Z=A(Y.target,"div");if(Z&&C(Z,"toggle")){Z.setAttribute("toggled",Z.getAttribute("toggled")!="true");Y.preventDefault()}},true);function F(){if(window.innerWidth!=N){N=window.innerWidth;var Z=N==320?"profile":"landscape";document.body.setAttribute("orient",Z);setTimeout(scrollTo,100,0,1)}if(location.hash!=T){var Y=location.hash.substr(D.length);iui.showPageById(Y)}}function S(Y){L=Y;Y.setAttribute("selected","true");if(C(Y,"dialog")&&!Y.target){U(Y)}}function U(Y){Y.onsubmit=function(Z){Z.preventDefault();O(Y)};Y.onclick=function(Z){if(Z.target==Y&&C(Y,"dialog")){E(Y)}}}function E(Y){Y.removeAttribute("selected")}function P(b,c){if(!b.id){b.id="__"+(++G)+"__"}location.href=T=D+b.id;J.push(b.id);var a=I("pageTitle");if(b.title&&a!=null){a.innerHTML=b.title}if(b.localName.toLowerCase()=="form"&&!b.target){U(b)}var Z=I("backButton");if(Z){var Y=I(J[J.length-2]);if(Y&&!b.getAttribute("hideBackButton")){Z.style.display="inline";Z.innerHTML=Y.title?Y.title:"Back"}else{Z.style.display="none"}}}function B(d,c,Z){var a=(Z?d:c).getAttribute("axis");if(a=="y"){(Z?d:c).style.top="100%"}else{c.style.left="100%"}c.setAttribute("selected","true");scrollTo(0,1);clearInterval(X);var b=100;Y();var e=setInterval(Y,R);function Y(){b-=K;if(b<=0){b=0;if(!C(c,"dialog")){d.removeAttribute("selected")}clearInterval(e);X=setInterval(F,300);setTimeout(P,0,c,d)}if(a=="y"){Z?d.style.top=(100-b)+"%":c.style.top=b+"%"}else{d.style.left=(Z?(100-b):(b-100))+"%";c.style.left=(Z?-b:b)+"%"}}}function M(){var Y=document.createElement("div");Y.id="preloader";document.body.appendChild(Y)}function O(Y){iui.showPageByHref(Y.action||"POST",W(Y),Y.method)}function W(a){function Z(b){for(var c=0;c<b.length;++c){if(b[c].name){if(b[c].type!="radio"&&b[c].type!="checkbox"){Y.push(b[c].name+"="+escape(b[c].value))}else{if(b[c].checked!=""){Y.push(b[c].name+"="+escape(b[c].value))}}}}}var Y=[];Z(a.getElementsByTagName("input"));Z(a.getElementsByTagName("textarea"));Z(a.getElementsByTagName("select"));return Y}function A(Z,Y){while(Z&&(Z.nodeType!=1||Z.localName.toLowerCase()!=Y)){Z=Z.parentNode}return Z}function C(Y,Z){var a=new RegExp("(^|\\s)"+Z+"($|\\s)");return a.exec(Y.getAttribute("class"))!=null}function Q(Y,b){var a=Y.parentNode;var Z=Y;while(a.parentNode!=document.body){a=a.parentNode;Z=Z.parentNode}var c=document.createElement(Z.localName);c.innerHTML=b;a.removeChild(Z);while(c.firstChild){a.appendChild(c.firstChild)}}function I(Y){return document.getElementById(Y)}function H(){console.log.apply(console,arguments)}})();
