var $p,pure=$p=function(f,k){var s=false;if(typeof f==="string")s=k||false;return $p.core(f,s)};
$p.core=function(f,k,s){function t(b){alert(b);if(typeof console!=="undefined"){console.log(b);debugger}throw"pure error: "+b;}function O(b){return b.outerHTML||function(a){var d=document.createElement("div");d.appendChild(a.cloneNode(true));return d.innerHTML}(b)}function E(b){return Object.prototype.toString.call(b)==="[object Array]"}function A(b,a){return function(d){return b(""+a.call(d.context,d))}}function G(b,a){a=a||document.createDocumentFragment();var d,c;for(var e in b){d=document.createElement(e);
a.appendChild(d);if(typeof b[e]==="object")c=G(b[e],d);else{c=document.createElement(b[e]);d.appendChild(c)}}return c}function P(b,a){if(typeof b==="string"){a=b;b=false}if(typeof document.querySelectorAll!=="undefined")return(b||document).querySelectorAll(a);else t("You can test PURE standalone with: iPhone, FF3.5+, Safari4+ and IE8+\n\nTo run PURE on your browser, you need a JS library/framework with a CSS selector engine")}function H(b,a){return function(d){for(var c=[b[0]],e=b.length,j,h,l,g,
m=1;m<e;m++){j=a[m](d);h=b[m];if(j===""){l=c[c.length-1];if((g=l.search(/[\w]+=\"?$/))>-1){c[c.length-1]=l.substring(0,g);h=h.substr(1)}}c[c.length]=j;c[c.length]=h}return c.join("")}}function Q(b){var a=b.match(/^(\w+)\s*<-\s*(\S+)?$/);a===null&&t('bad loop spec: "'+b+'"');a[1]==="item"&&t('"item<-..." is a reserved word for the current running iteration.\n\nPlease choose another name for your loop.');if(!a[2]||a[2]&&/context/i.test(a[2]))a[2]=function(d){return d.context};return{name:a[1],sel:a[2]}}
function y(b){if(typeof b==="function")return b;var a=b.match(/^[a-zA-Z$_][\w$]*(\.[\w$-]*[^\.])*$/);if(a===null){var d=false,c=b,e=[],j=[],h=0,l;if(/\'|\"/.test(c.charAt(0))){if(/\'|\"/.test(c.charAt(c.length-1))){l=c.substring(1,c.length-1);return function(){return l}}}else for(;(a=c.match(/#\{([^{}]+)\}/))!==null;){d=true;e[h++]=c.slice(0,a.index);j[h]=y(a[1]);c=c.slice(a.index+a[0].length,c.length)}d||t("bad data selector syntax: "+b);e[h]=c;return H(e,j)}a=b.split(".");return function(g){var m=
g.context;if(!m)return"";var n=g[a[0]];g=0;if(n&&n.item){m=n.item;g+=1}for(n=a.length;g<n;g++){if(!m)break;m=m[a[g]]}return!m&&m!==0?"":m}}function B(b,a,d){var c,e,j,h,l,g=[];if(typeof a==="string"){c=a;(l=a.match(I))||t("bad selector syntax: "+a);e=l[1];j=l[2];h=l[3];l=l[4];if(j==="."||!j&&h)g[0]=b;else g=s.find(b,j);if(!g||g.length===0)return t('The node "'+a+'" was not found in the template')}else{e=a.prepend;h=a.attr;l=a.append;g=[b]}if(e||l)if(e&&l)t("append/prepend cannot take place at the same time");
else if(d)t("no append/prepend/replace modifiers allowed for loop target");else l&&d&&t("cannot append with loop (sel: "+c+")");var m,n,u,r,p;if(h){u=/^style$/i.test(h);p=(r=/^class$/i.test(h))?"className":h;m=function(i,q){i.setAttribute(J+h,q);if(p in i&&!u)i[p]="";if(i.nodeType===1){i.removeAttribute(h);r&&i.removeAttribute(p)}};if(u||r){n=u?function(i){return i.style.cssText}:function(i){return i.className};b=function(i){return i.replace(/\"/g,"&quot;")}}else{n=function(i){return i.getAttribute(h)};
b=function(i){return i.replace(/\"/g,"&quot;").replace(/\s/g,"&nbsp;")}}e=e?function(i,q){m(i,q+n(i))}:l?function(i,q){m(i,n(i)+q)}:function(i,q){m(i,q)}}else{e=d?function(i,q){var o=i.parentNode;if(o){o.insertBefore(document.createTextNode(q),i.nextSibling);o.removeChild(i)}}:e?function(i,q){i.insertBefore(document.createTextNode(q),i.firstChild)}:l?function(i,q){i.appendChild(document.createTextNode(q))}:function(i,q){for(;i.firstChild;)i.removeChild(i.firstChild);i.appendChild(document.createTextNode(q))};
b=function(i){return i}}return{attr:h,nodes:g,set:e,sel:c,quotefn:b}}function C(b,a){for(var d=K+a+":",c=0;c<b.nodes.length;c++)b.set(b.nodes[c],d)}function L(b,a,d,c,e){return function(j){var h=a(j),l=j[b],g={items:h},m=0,n,u=[],r=function(i,q,o,x){j.pos=q.pos=i;j.item=q.item=h[i];j.items=h;typeof x!=="undefined"&&(j.length=x);if(typeof o==="function"&&!o(j))m++;else u.push(d.call(q,j))};j[b]=g;if(E(h)){n=h.length||0;typeof c==="function"&&h.sort(c);for(var p=0;p<n;p++)r(p,g,e,n-m)}else{h&&typeof c!==
"undefined"&&t("sort is only available on arrays, not objects");for(n in h)h.hasOwnProperty(n)&&r(n,g,e)}typeof l!=="undefined"?j[b]=l:delete j[b];return u.join("")}}function M(b,a,d,c){var e=false,j,h,l,g;for(g in d)if(d.hasOwnProperty(g))if(g==="sort")h=d.sort;else if(g==="filter")l=d.filter;else{e&&t("cannot have more than one loop on a target");j=g;e=true}j||t("Error in the selector: "+a+"\nA directive action must be a string, a function or a loop(<-)");e=d[j];if(typeof e==="string"||typeof e===
"function"){d={};d[j]={root:e};return M(b,a,d,c)}d=Q(j);j=y(d.sel);b=B(b,a,true);a=b.nodes;for(w=0;w<a.length;w++){g=a[w];var m=D(g,e);c[c.length]=A(b.quotefn,L(d.name,j,m,h,l));b.nodes=[g];C(b,c.length-1)}}function R(b,a){function d(i,q){var o=i.match(I);o={prepend:!!o[1],prop:o[2],attr:o[3]||S[q],append:!!o[4],sel:i};var x,F,v;for(x=j.a.length-1;x>=0;x--){F=j.a[x];v=(v=F.l[0])&&v[o.prop];if(typeof v!=="undefined"){o.prop=F.p+"."+o.prop;if(j.l[o.prop]===true)v=v[0];break}}if(typeof v==="undefined"){v=
E(a)?a[0][o.prop]:a[o.prop];if(typeof v==="undefined")return false}if(E(v)){j.a.push({l:v,p:o.prop});j.l[o.prop]=true;o.t="loop"}else o.t="str";return o}var c=b.getElementsByTagName("*"),e=[],j={a:[],l:{}},h,l,g,m,n,u,r,p;g=-1;for(m=c.length;g<m;g++){r=g>-1?c[g]:b;if(r.nodeType===1&&r.className!==""){p=r.className.split(" ");n=0;for(u=p.length;n<u;n++){h=p[n];h=d(h,r.tagName);if(h!==false){l=/nodevalue/i.test(h.attr);if(h.sel.indexOf("@")>-1||l){r.className=r.className.replace("@"+h.attr,"");if(l)h.attr=
false}e.push({n:r,cspec:h})}}}}return e}function D(b,a,d,c){var e=[];c=c||d&&R(b,d);if(d)for(var j,h,l,g,m,n,u,r;c.length>0;){l=c[0].cspec;g=c[0].n;c.splice(0,1);if(l.t==="str"){g=B(g,l,false);C(g,e.length);e[e.length]=A(g.quotefn,y(l.prop))}else{n=y(l.sel);g=B(g,l,true);m=g.nodes;j=0;for(h=m.length;j<h;j++){u=m[j];r=D(u,false,d,c);e[e.length]=A(g.quotefn,L(l.sel,n,r));g.nodes=[u];C(g,e.length-1)}}}for(var p in a)if(a.hasOwnProperty(p)){d=a[p];if(typeof d==="function"||typeof d==="string"){g=B(b,
p,false);C(g,e.length);e[e.length]=A(g.quotefn,y(d))}else M(b,p,d,e)}a=O(b);b=[];a=a.replace(/<([^>]+)\s(value\=""|selected)\s?([^>]*)>/ig,"<$1 $3>");a=a.split(J).join("");a=a.split(K);for(d=1;d<a.length;d++){p=a[d];b[d]=e[parseInt(p,10)];a[d]=p.substring(p.indexOf(":")+1)}return H(a,b)}function T(b,a,d){var c=D((d||this[0]).cloneNode(true),b,a);return function(e){return c({context:e})}}function U(b,a){for(var d=typeof a==="function"?a:s.compile(a,false,this[0]),c=0,e=this.length;c<e;c++)this[c]=
N(this[c],d(b,false));context=null;return this}function V(b,a){for(var d=s.compile(a,b,this[0]),c=0,e=this.length;c<e;c++)this[c]=N(this[c],d(b,false));context=null;return this}function N(b,a){var d=b.tagName,c,e;c=/TD|TR|TH/.test(d)?G({TR:{TABLE:"TBODY"},TD:{TABLE:{TBODY:"TR"}},TH:{TABLE:{THEAD:"TR"}}}[d]):/TBODY|THEAD|TFOOT/.test(d)?document.createElement("TABLE"):document.createElement("SPAN");e=b.parentNode;e.insertBefore(c,b);e.removeChild(b);c.style.display="none";c.innerHTML=a;d=c.firstChild;
e.insertBefore(d,c);e.removeChild(c);return b=d}s=function(){var b=$p.plugins,a=function(){};a.prototype=b;a.prototype.compile=b.compile||T;a.prototype.render=b.render||U;a.prototype.autoRender=b.autoRender||V;a.prototype.find=b.find||P;a.prototype._compiler=D;a.prototype._error=t;return new a}();var z=[];switch(typeof f){case "string":z=s.find(k||document,f);z.length===0&&t('The template "'+f+'" was not found');break;case "undefined":t("The template root is undefined, check your selector");break;
default:z=[f]}var w=0;for(f=z.length;w<f;w++)s[w]=z[w];s.length=f;var K="_s"+Math.floor(Math.random()*1E6)+"_",J="_a"+Math.floor(Math.random()*1E6)+"_",I=/^(\+)?([^\@\+]+)?\@?([^\+]+)?(\+)?$/,S={IMG:"src",INPUT:"value"};return s};$p.plugins={};
$p.libs={dojo:function(){if(typeof document.querySelector==="undefined")$p.plugins.find=function(f,k){return dojo.query(k,f)}},domassistant:function(){if(typeof document.querySelector==="undefined")$p.plugins.find=function(f,k){return $(f).cssSelect(k)};DOMAssistant.attach({publicMethods:["compile","render","autoRender"],compile:function(f,k){return $p(this).compile(f,k)},render:function(f,k){return $($p(this).render(f,k))[0]},autoRender:function(f,k){return $($p(this).autoRender(f,k))[0]}})},jquery:function(){if(typeof document.querySelector===
"undefined")$p.plugins.find=function(f,k){return $(f).find(k)};jQuery.fn.extend({compile:function(f,k){return $p(this[0]).compile(f,k)},render:function(f,k){return jQuery($p(this[0]).render(f,k))},autoRender:function(f,k){return jQuery($p(this[0]).autoRender(f,k))}})},mootools:function(){if(typeof document.querySelector==="undefined")$p.plugins.find=function(f,k){return $(f).getElements(k)};Element.implement({compile:function(f,k){return $p(this).compile(f,k)},render:function(f,k){return $p(this).render(f,
k)},autoRender:function(f,k){return $p(this).autoRender(f,k)}})},prototype:function(){if(typeof document.querySelector==="undefined")$p.plugins.find=function(f,k){f=f===document?f.body:f;return typeof f==="string"?$$(f):$(f).select(k)};Element.addMethods({compile:function(f,k,s){return $p(f).compile(k,s)},render:function(f,k,s){return $p(f).render(k,s)},autoRender:function(f,k,s){return $p(f).autoRender(k,s)}})},sizzle:function(){if(typeof document.querySelector==="undefined")$p.plugins.find=function(f,
k){return Sizzle(k,f)}},sly:function(){if(typeof document.querySelector==="undefined")$p.plugins.find=function(f,k){return Sly(k,f)}}};(function(){var f=typeof dojo!=="undefined"&&"dojo"||typeof DOMAssistant!=="undefined"&&"domassistant"||typeof jQuery!=="undefined"&&"jquery"||typeof MooTools!=="undefined"&&"mootools"||typeof Prototype!=="undefined"&&"prototype"||typeof Sizzle!=="undefined"&&"sizzle"||typeof Sly!=="undefined"&&"sly";f&&$p.libs[f]()})();

