/*
ICanHaz.js version 0.7 -- by @HenrikJoreteg
More info at: http://github.com/HenrikJoreteg/ICanHaz.js
*/
(function(c){
/*
  mustache.js -- Logic-less templates in JavaScript

  by @janl (MIT Licensed, https://github.com/janl/mustache.js/blob/master/LICENSE).

  See http://mustache.github.com/ for more info.
*/
var b=function(){var d=function(){};d.prototype={otag:"{{",ctag:"}}",pragmas:{},buffer:[],pragmas_implemented:{"IMPLICIT-ITERATOR":true},context:{},render:function(h,g,f,i){if(!i){this.context=g;this.buffer=[]}if(!this.includes("",h)){if(i){return h}else{this.send(h);return}}h=this.render_pragmas(h);var e=this.render_section(h,g,f);if(i){return this.render_tags(e,g,f,i)}this.render_tags(e,g,f,i)},send:function(e){if(e!=""){this.buffer.push(e)}},render_pragmas:function(e){if(!this.includes("%",e)){return e}var g=this;var f=new RegExp(this.otag+"%([\\w-]+) ?([\\w]+=[\\w]+)?"+this.ctag);return e.replace(f,function(j,h,i){if(!g.pragmas_implemented[h]){throw ({message:"This implementation of mustache doesn't understand the '"+h+"' pragma"})}g.pragmas[h]={};if(i){var k=i.split("=");g.pragmas[h][k[0]]=k[1]}return""})},render_partial:function(e,g,f){e=this.trim(e);if(!f||f[e]===undefined){throw ({message:"unknown_partial '"+e+"'"})}if(typeof(g[e])!="object"){return this.render(f[e],g,f,true)}return this.render(f[e],g[e],f,true)},render_section:function(g,f,e){if(!this.includes("#",g)&&!this.includes("^",g)){return g}var i=this;var h=new RegExp(this.otag+"(\\^|\\#)\\s*(.+)\\s*"+this.ctag+"\n*([\\s\\S]+?)"+this.otag+"\\/\\s*\\2\\s*"+this.ctag+"\\s*","mg");return g.replace(h,function(k,l,j,m){var n=i.find(j,f);if(l=="^"){if(!n||i.is_array(n)&&n.length===0){return i.render(m,f,e,true)}else{return""}}else{if(l=="#"){if(i.is_array(n)){return i.map(n,function(o){return i.render(m,i.create_context(o),e,true)}).join("")}else{if(i.is_object(n)){return i.render(m,i.create_context(n),e,true)}else{if(typeof n==="function"){return n.call(f,m,function(o){return i.render(o,f,e,true)})}else{if(n){return i.render(m,f,e,true)}else{return""}}}}}}})},render_tags:function(n,e,g,j){var h=this;var m=function(){return new RegExp(h.otag+"(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?"+h.ctag+"+","g")};var k=m();var l=function(q,i,p){switch(i){case"!":return"";case"=":h.set_delimiters(p);k=m();return"";case">":return h.render_partial(p,e,g);case"{":return h.find(p,e);default:return h.escape(h.find(p,e))}};var o=n.split("\n");for(var f=0;f<o.length;f++){o[f]=o[f].replace(k,l,this);if(!j){this.send(o[f])}}if(j){return o.join("\n")}},set_delimiters:function(f){var e=f.split(" ");this.otag=this.escape_regex(e[0]);this.ctag=this.escape_regex(e[1])},escape_regex:function(f){if(!arguments.callee.sRE){var e=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];arguments.callee.sRE=new RegExp("(\\"+e.join("|\\")+")","g")}return f.replace(arguments.callee.sRE,"\\$1")},find:function(f,g){f=this.trim(f);function e(i){return i===false||i===0||i}var h;if(e(g[f])){h=g[f]}else{if(e(this.context[f])){h=this.context[f]}}if(typeof h==="function"){return h.apply(g)}if(h!==undefined){return h}return""},includes:function(f,e){return e.indexOf(this.otag+f)!=-1},escape:function(e){e=String(e===null?"":e);return e.replace(/&(?!\w+;)|["<>\\]/g,function(f){switch(f){case"&":return"&amp;";case"\\":return"\\\\";case'"':return'"';case"<":return"&lt;";case">":return"&gt;";default:return f}})},create_context:function(f){if(this.is_object(f)){return f}else{var g=".";if(this.pragmas["IMPLICIT-ITERATOR"]){g=this.pragmas["IMPLICIT-ITERATOR"].iterator}var e={};e[g]=f;return e}},is_object:function(e){return e&&typeof e=="object"},is_array:function(e){return Object.prototype.toString.call(e)==="[object Array]"},trim:function(e){return e.replace(/^\s*|\s*$/g,"")},map:function(j,g){if(typeof j.map=="function"){return j.map(g)}else{var h=[];var e=j.length;for(var f=0;f<e;f++){h.push(g(j[f]))}return h}}};return({name:"mustache.js",version:"0.3.0",to_html:function(g,e,f,i){var h=new d();if(i){h.send=i}h.render(g,e,f);if(!i){return h.buffer.join("\n")}}})}();
/*
  ICanHaz.js -- by @HenrikJoreteg
*/
function a(){var e=this,d={cache:{},partials:{}};this.VERSION="0.7";this.addTemplate=function(f,g){if(this[f]){throw"Can't add a template with reserved name: "+f+"."}else{if(d.cache.hasOwnProperty(f)){throw"You've already got a template by the name: \""+f+'"'}else{d.cache[f]=g;e[f]=function(j,i){j=j||{};var h=b.to_html(d.cache[f],j,d.partials);return i?h:c(h)}}}};this.addPartial=function(f,g){if(d.partials.hasOwnProperty(f)){throw'You\'ve already got a partial with the name: " + name + "'}else{d.partials[f]=g}};this.grabTemplates=function(){c('script[type="text/html"]').each(function(){var f=c(this),g=f.attr("id"),i=c.trim(f.html()),h=f.attr("class").toLowerCase()==="partial";if(h){e.addPartial(g,i)}else{e.addTemplate(g,i)}f.remove()})};this.showAll=function(){return{templates:c.extend({},d.cache),partials:c.extend({},d.partials)}};this.clearAll=function(){c.each(d.cache,function(f,g){delete e[f]});d.cache={};d.partials={}};this.refresh=function(){this.clearAll();this.grabTemplates()}}window.ich=new a();c(function(){ich.grabTemplates()})}(jQuery));
