/*
 * jQuery Templating Plugin
 *   NOTE: Created for demonstration purposes.
 * Copyright 2010, John Resig
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * Ver: 11 Jun 10 - http://github.com/nje/jquery-tmpl
 */
(function(k){var j=k.fn.domManip,e="_tmplctx",g="["+e+"]",f,a,c=/^[^<]*(<[\w\W]+>)[^>]*$/,b={},d=h({key:0}),i=0;function h(n,m,o,q){var p={index:-1,data:q||null,tmpl:null,parent:m||null,nodes:[],update:r,remove:l};if(n){k.extend(p,n,{nodes:[],parent:m})}if(o){p.tmpl=o;p.content=p.tmpl(k,p);p.key=++i;b[i]=p}return p;function r(t){t=t?k.extend(this,t):this;var s=t.nodes;k(s[0]).before(t);k(s).remove();return this}function l(){k(this.nodes).remove();return this}}k.fn.extend({tmpl:function(){return k.tmpl(this[0])},domManip:function(o,q,s){var n,l,r=-1,p=k.makeArray(arguments);if(o.length>1&&o[0].nodeType){p[0]=[k.makeArray(o)]}else{if(o.length>=2&&typeof o[1]==="object"&&!o[1].nodeType){l=o[3]||d;p[0]=[k.tmpl(o[0],l,o[1],o[2],true)]}else{if(o.length===1&&typeof o[0]==="object"&&!o[0].nodeType&&!(o[0] instanceof k)){l=o[0];b[l.key]=l;p[0]=[k.tmpl(l)];p[1]=l.data}}}if(l){p[2]=m}j.apply(this,p);r=-1;n=b;b={};for(f in n){a=n[f];if(a.rendered){a.rendered(a)}}return this;function m(t){var x,v,u,w,A,y,z=k(t.nodeType===11?t.childNodes:t);r++;A="_"+r;s.call(this,t);z.find(g).add(z.filter(g)).each(function(){w=k.attr(this,e);if(!k(this.parentNode).closest("["+e+"="+w+"]").length){y=u=b[w];if(r){w=w+A;b[w]=b[w]||h(u,b[u.parent.key+A]||u.parent,true)}parentNodeCtx=k.attr(this.parentNode,e)||0;while(y&&y.key!=parentNodeCtx){y.nodes.push(this);y=y.parent}k.data(this,"tmplCtx",u)}}).removeAttr(e);delete l.content}}});k.extend({tmpl:function(q,s,o,t,l){var p,m;if(arguments.length===1){if((typeof q==="string")&&!c.test(q)){q=k(q)[0]}else{if(q instanceof k){q=q.get(0)}}if(q.nodeType){if(k.attr(q,"type")!=="text/html"){while(q&&!(tmplCtx=k.data(q,"tmplCtx"))&&(q=q.parentNode)){}return tmplCtx||d}}else{m=q;q=q.tmpl}}if(!q){return d}if(typeof q==="string"){p=k.templates[q];if(!p){p=n(k(q)[0].innerHTML)}}else{if(typeof q==="function"){p=q}else{if(q.nodeType){p=k.data(q,"tmpl")||k.data(q,"tmpl",n(q.innerHTML))}}}if(!p){return[]}if(m){m.tmpl=p;m.nodes=[];m.content=m.tmpl(k,m);return r(m)}o=o||(s?s.data:null);if(!o){return p}if(typeof o==="function"){o=o.call(s.data||{},s)}s.content=k.isArray(o)?k.map(o,function(u){return h(t,s,p,u)}):[h(t,s,p,o)];return l?r(s):s.content;function r(u,w){var x,v=k.map(u.content,function(y){return(typeof y==="string")?y.replace(/(<\w+)([^>]*)/g,"$1 "+e+'="'+u.key+'" $2'):r(y,u)});if(w){return v}v=v.join("");v.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/,function(z,A,y,B){x=k(y).get();if(!!A){x.unshift(document.createTextNode(A))}if(!!B){x.push(document.createTextNode(B))}});return x?x:document.createTextNode(v)}function n(u){return new Function("jQuery","$ctx","var $=jQuery,_=[],$data=$ctx.data;with($data){_.push('"+u.replace(/([\\'])/g,"\\$1").replace(/[\r\t\n]/g," ").replace(/\${([^}]*)}/g,"{{= $1}}").replace(/{{(\/?)(\w+|.)(?:\(((?:.(?!}}))*?)?\))?(?:\s+(.*?)?)?(\((.*?)\))?}}/g,function(E,x,C,y,A,F,B){function z(G){return G?G.replace(/\\'/g,"'").replace(/\\\\/g,"\\"):null}var w=k.tmplTags[C],v,D;if(!w){throw"Template command not found: "+C}v=w._default||[];if(A){A=z(A);B=B?(","+z(B)+")"):(F?")":"");D=B?("("+A+").call($ctx"+B):A}else{D=v["$1"]||"null"}y=z(y);return"');"+w[x?"suffix":"prefix"].split("$defined_1").join("typeof("+A+")!=='undefined'").split("$1").join(D).split("$2").join(y?y.replace(/\s*([^\(]+)\s*(\((.*?)\))?/g,function(H,G,I,J){J=J?(","+J+")"):(I?")":"");return J?("("+G+").call($ctx"+J):H}):(v["$2"]||""))+"_.push('"})+"');}return _;")}},templates:{},tmplTags:{tmpl:{_default:{$2:"null"},prefix:"if($defined_1){_=_.concat($.tmpl($1,$ctx,$2));}"},each:{_default:{$2:"$index, $value"},prefix:"if($defined_1){$.each($1,function($2){with(this){",suffix:"}});}"},"if":{prefix:"if(($defined_1) && $1){",suffix:"}"},"else":{prefix:"}else{"},html:{prefix:"if($defined_1){_.push($1);}"},"=":{_default:{$1:"$data"},prefix:"if($defined_1){_.push($.encode($1));}"}},encode:function(l){return l!=null?document.createTextNode(l.toString()).nodeValue:""}})})(jQuery);
