/*
 * FluentZen - jquery plugin for creating DOM elements on the fly
 * Version: 0.1.1a (26/11/09)
 *
 * Author: Kristaps Karlsons <kristaps.karlsons@gmail.com>
 * Usage and info: http://code.google.com/p/fluentzen
 *
 * Base idea/code by: Sergey Chikuyonok <serge.che@gmail.com>
 * Ported code: Zen Coding for Aptana v0.5.1
 * Google Code: http://code.google.com/p/zen-coding
 * Usage and info: http://chikuyonok.ru
 */
var zen_settings={variables:{lang:"en",locale:"en-US",charset:"UTF-8",profile:"xhtml",indentation:"\t"},html:{abbreviations:{a:'<a href=""></a>',"a:link":'<a href="http://|"></a>',"a:mail":'<a href="mailto:|"></a>',abbr:'<abbr title=""></abbr>',acronym:'<acronym title=""></acronym>',base:'<base href="" />',bdo:'<bdo dir=""></bdo>',"bdo:r":'<bdo dir="rtl"></bdo>',"bdo:l":'<bdo dir="ltr"></bdo>',"link:css":'<link rel="stylesheet" type="text/css" href="|style.css" media="all" />',"link:print":'<link rel="stylesheet" type="text/css" href="|print.css" media="print" />',"link:favicon":'<link rel="shortcut icon" type="image/x-icon" href="|favicon.ico" />',"link:touch":'<link rel="apple-touch-icon" href="|favicon.png" />',"link:rss":'<link rel="alternate" type="application/rss+xml" title="RSS" href="|rss.xml" />',"link:atom":'<link rel="alternate" type="application/atom+xml" title="Atom" href="atom.xml" />',"meta:utf":'<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />',"meta:win":'<meta http-equiv="Content-Type" content="text/html;charset=windows-1251" />',"meta:compat":'<meta http-equiv="X-UA-Compatible" content="IE=7" />',style:'<style type="text/css"></style>',script:'<script type="text/javascript"><\/script>',"script:src":'<script type="text/javascript" src=""><\/script>',img:'<img src="" alt="" />',iframe:'<iframe src="" frameborder="0"></iframe>',embed:'<embed src="" type="" />',object:'<object data="" type=""></object>',param:'<param name="" value="" />',map:'<map name=""></map>',area:'<area shape="" coords="" href="" alt="" />',"area:d":'<area shape="default" href="" alt="" />',"area:c":'<area shape="circle" coords="" href="" alt="" />',"area:r":'<area shape="rect" coords="" href="" alt="" />',"area:p":'<area shape="poly" coords="" href="" alt="" />',link:'<link rel="stylesheet" href="" />',form:'<form action=""></form>',"form:get":'<form action="" method="get"></form>',"form:post":'<form action="" method="post"></form>',label:'<label for=""></label>',input:'<input type="" />',"input:hidden":'<input type="hidden" name="" />',"input:h":'<input type="hidden" name="" />',"input:text":'<input type="text" name="" id="" />',"input:t":'<input type="text" name="" id="" />',"input:search":'<input type="search" name="" id="" />',"input:email":'<input type="email" name="" id="" />',"input:url":'<input type="url" name="" id="" />',"input:password":'<input type="password" name="" id="" />',"input:p":'<input type="password" name="" id="" />',"input:datetime":'<input type="datetime" name="" id="" />',"input:date":'<input type="date" name="" id="" />',"input:datetime-local":'<input type="datetime-local" name="" id="" />',"input:month":'<input type="month" name="" id="" />',"input:week":'<input type="week" name="" id="" />',"input:time":'<input type="time" name="" id="" />',"input:number":'<input type="number" name="" id="" />',"input:color":'<input type="color" name="" id="" />',"input:checkbox":'<input type="checkbox" name="" id="" />',"input:c":'<input type="checkbox" name="" id="" />',"input:radio":'<input type="radio" name="" id="" />',"input:r":'<input type="radio" name="" id="" />',"input:range":'<input type="range" name="" id="" />',"input:file":'<input type="file" name="" id="" />',"input:f":'<input type="file" name="" id="" />',"input:submit":'<input type="submit" value="" />',"input:s":'<input type="submit" value="" />',"input:image":'<input type="image" src="" alt="" />',"input:i":'<input type="image" src="" alt="" />',"input:reset":'<input type="reset" value="" />',"input:button":'<input type="button" value="" />',"input:b":'<input type="button" value="" />',select:'<select name="" id=""></select>',option:'<option value=""></option>',textarea:'<textarea name="" id="" cols="30" rows="10"></textarea>',"menu:context":'<menu type="context"></menu>',"menu:c":'<menu type="context"></menu>',"menu:toolbar":'<menu type="toolbar"></menu>',"menu:t":'<menu type="toolbar"></menu>',video:'<video src=""></video>',audio:'<audio src=""></audio>',"html:xml":'<html xmlns="http://www.w3.org/1999/xhtml"></html>',bq:"<blockquote></blockquote>",acr:"<acronym></acronym>",fig:"<figure></figure>",ifr:"<iframe></iframe>",emb:"<embed></embed>",obj:"<object></object>",src:"<source></source>",cap:"<caption></caption>",colg:"<colgroup></colgroup>",fst:"<fieldset></fieldset>",btn:"<button></button>",optg:"<optgroup></optgroup>",opt:"<option></option>",tarea:"<textarea></textarea>",leg:"<legend></legend>",sect:"<section></section>",art:"<article></article>",hdr:"<header></header>",ftr:"<footer></footer>",adr:"<address></address>",dlg:"<dialog></dialog>",str:"<strong></strong>",prog:"<progress></progress>",fset:"<fieldset></fieldset>",datag:"<datagrid></datagrid>",datal:"<datalist></datalist>",kg:"<keygen></keygen>",out:"<output></output>",det:"<details></details>",cmd:"<command></command>","ol+":"ol>li","ul+":"ul>li","dl+":"dl>dt+dd","map+":"map>area","table+":"table>tr>td","colgroup+":"colgroup>col","colg+":"colgroup>col","tr+":"tr>td","select+":"select>option","optgroup+":"optgroup>option","optg+":"optgroup>option"},element_types:{empty:"area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,keygen,command",block_level:"address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,link,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul,h1,h2,h3,h4,h5,h6",inline_level:"a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var"}}};var zen_coding=(function(){var l=/<\/?[\w:\-]+(?:\s+[\w\-:]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*\s*(\/?)>$/;var r="zen-tag",n="zen-expando",w="zen-reference",q="{%::zen-content::%}";var v={tag_case:"lower",attr_case:"lower",attr_quotes:"double",tag_nl:"decide",place_cursor:false,indent:true,self_closing_tag:"xhtml"};var k={};function g(A){var z=A.charCodeAt(0),y="#.>+*:$-_!@";return(z>64&&z<91)||(z>96&&z<123)||(z>47&&z<58)||y.indexOf(A)!=-1}function j(){return zen_coding.getNewline()}function f(C,B){var z=j(),y=C.split(new RegExp("\\r?\\n|\\n\\r|\\r|"+z));if(B){for(var A=y.length;A>=0;A--){if(!t(y[A])){y.splice(A,1)}}}return y}function t(y){return(y||"").replace(/^\s+|\s+$/g,"")}function s(z){var y={};for(var A in v){y[A]=(A in z)?z[A]:v[A]}return y}function b(z,y){k[z.toLowerCase()]=s(y||{})}function u(B){var A={},y=B.split(",");for(var z=0;z<y.length;z++){A[y[z]]=true}return A}function x(E,z,A){var D="",G="";if(typeof(z)=="number"){for(var C=0;C<z;C++){D+=zen_settings.variables.indentation}}else{D=z}var F=f(E),y=j();G+=F[0];for(var B=1;B<F.length;B++){G+=y+D+F[B]}return G}function c(y,z){return p(z,y)?true:false}function o(y){return l.test(y)}function a(z,y){if(z&&z.element_types){return z.element_types[y]||{}}else{return{}}}function e(z,y){y=y||zen_settings.variables;return z.replace(/\$\{([\w\-]+)\}/g,function(B,A){return(A in y)?y[A]:B})}function h(A,E,D){A=A.toLowerCase();D=D||"html";var z=i(D,A);if(z&&z.type==w){z=i(D,z.value)}this.name=(z)?z.value.name:A.replace("+","");this.count=E||1;this.children=[];this.attributes=[];this._attr_hash={};this._abbr=z;this._res=zen_settings[D];this._content="";this.repeat_by_lines=false;if(this._abbr&&this._abbr.value.attributes){var C=this._abbr.value.attributes;if(C){for(var B=0;B<C.length;B++){var y=C[B];this.addAttribute(y.name,y.value)}}}}h.prototype={addChild:function(y){this.children.push(y)},addAttribute:function(z,A){var y;if(z in this._attr_hash){y=this._attr_hash[z];if(z=="class"){y.value+=((y.value)?" ":"")+A}else{y.value=A}}else{y={name:z,value:A};this._attr_hash[z]=y;this.attributes.push(y)}},isEmpty:function(){return(this._abbr&&this._abbr.value.is_empty)||(this.name in a(this._res,"empty"))},isInline:function(){return(this.name in a(this._res,"inline_level"))},isBlock:function(){return(this.name in a(this._res,"block_level"))},hasTagsInContent:function(){return this.getContent()&&l.test(this.getContent())},hasBlockChildren:function(){if(this.hasTagsInContent()&&this.isBlock()){return true}for(var y=0;y<this.children.length;y++){if(this.children[y].isBlock()){return true}}return false},setContent:function(y){this._content=y},getContent:function(){return this._content},findDeepestChild:function(){if(!this.children.length){return null}var y=this;while(true){y=y.children[y.children.length-1];if(!y.children.length){break}}return y},toString:function(D){var E=[],A=(D in k)?k[D]:k.plain,H="",J="",z="",O="",B=A.place_cursor?"|":"",G="",T=A.attr_quotes=="single"?"'":'"',I;if(A.self_closing_tag=="xhtml"){G=" /"}else{if(A.self_closing_tag===true){G="/"}}function F(U){return(A.tag_nl===true||(A.tag_nl=="decide"&&U.isBlock()))}for(var M=0;M<this.attributes.length;M++){var S=this.attributes[M];I=(A.attr_case=="upper")?S.name.toUpperCase():S.name.toLowerCase();H+=" "+I+"="+T+(S.value||B)+T}var N=this.findDeepestChild();if(!this.isEmpty()){if(N&&this.repeat_by_lines){N.setContent(q)}for(var K=0;K<this.children.length;K++){J+=this.children[K].toString(D);if((K!=this.children.length-1)&&(F(this.children[K])||F(this.children[K+1]))){J+=j()}}}if(this.name){var Q=(A.tag_case=="upper")?this.name.toUpperCase():this.name.toLowerCase();if(this.isEmpty()){z="<"+Q+H+G+">"}else{z="<"+Q+H+">";O="</"+Q+">"}}if(A.tag_nl!==false){if(this.name&&(A.tag_nl===true||this.hasBlockChildren())){if(O){z+=j()+zen_settings.variables.indentation;O=j()+O}else{}}if(this.name){if(J){J=x(J,A.indent?1:0)}else{if(!this.isEmpty()){z+=B}}}}var R="";if(this.repeat_by_lines){var y=f(t(this.getContent()),true);for(var K=0;K<y.length;K++){R=N?"":q;if(J&&!N){R+=j()}var C=z.replace(/\$/g,K+1)+R+J+O;E.push(C.replace(q,t(y[K])))}}if(!E.length){if(this.getContent()){var P=(A.tag_nl===true||(this.hasTagsInContent()&&this.isBlock()))?1:0;J=x(this.getContent(),P)+J}for(var M=0;M<this.count;M++){E.push(z.replace(/\$/g,M+1)+J+O)}}var L="";if(F(this)){L=j()}return E.join(L)}};function m(y,A,z){this.name=y;this.count=A||1;this.children=[];this._content="";this.repeat_by_lines=false;this.attributes={id:"|","class":"|"};this.value=p(z,y)}m.prototype={addChild:function(y){this.children.push(y)},addAttribute:function(y,z){this.attributes[y]=z},isBlock:function(){return true},setContent:function(y){this._content=y},getContent:function(){return this._content},findDeepestChild:function(){if(!this.children.length){return null}var y=this;while(true){y=y.children[y.children.length-1];if(!y.children.length){break}}return y},toString:function(I){var J="",B=(I in k)?k[I]:k.plain,M=[],G=this.value,z="",C="",K="",H="${child}";if(G){if(B.tag_nl!==false){var y=j();G=G.replace(/\n/g,y);var L=G.split(y),A;for(var E=0;E<L.length;E++){if(L[E].indexOf(H)!=-1){K=(A=L[E].match(/(^\s+)/))?A[1]:"";break}}}var D=G.split(H);z=D[0]||"";C=D[1]||""}for(var F=0;F<this.children.length;F++){J+=this.children[F].toString(I);if(F!=this.children.length-1&&(B.tag_nl===true||(B.tag_nl=="decide"&&this.children[F].isBlock()))){J+=j()}}if(K){J=x(J,K)}z=e(z,this.attributes);C=e(C,this.attributes);if(this.getContent()){J=x(this.getContent(),1)+J}for(var F=0;F<this.count;F++){M.push(z+J+C)}return M.join((B.tag_nl!==false)?j():"")}};function i(z,y){return d(z,y,"abbreviations")}function p(z,y){return d(z,y,"snippets")}function d(A,y,C){var B=zen_settings[A];if(B){if(C in B&&y in B[C]){return B[C][y]}else{if("extends" in B){for(var z=0;z<B["extends"].length;z++){var A=B["extends"][z];if(zen_settings[A]&&zen_settings[A][C]&&zen_settings[A][C][y]){return zen_settings[A][C][y]}}}}}return null}b("xhtml",{place_cursor:false});b("html",{self_closing_tag:false,place_cursor:false});return{expandAbbreviation:function(z,B,A){var y=this.parseIntoTree(z,B||"html");return e(y?y.toString(A):"")},extractAbbreviation:function(B){var z=B.length,y=-1;while(true){z--;if(z<0){y=0;break}var A=B.charAt(z);if(!g(A)||(A==">"&&o(B.substring(0,z+1)))){y=z+1;break}}if(y!=-1){return B.substring(y)}else{return""}},parseIntoTree:function(z,D){D=D||"html";var y=new h("",1,D),C=y,E=null,F=null,A=zen_settings[D],B=/([\+>])?([a-z@\!][a-z0-9:\-]*)(#[\w\-\$]+)?((?:\.[\w\-\$]+)*)(\*(\d*))?(\+$)?/ig;if(!z){return null}z=z.replace(/([a-z][\w\:\-]*)\+$/i,function(H){var G=i(D,H);return G?G.value:H});z=z.replace(B,function(M,J,I,G,K,O,P,H){var N=(O&&!P);P=P?parseInt(P):1;if(H){I+="+"}var L=c(I,D)?new m(I,P,D):new h(I,P,D);if(G){L.addAttribute("id",G.substr(1))}if(K){L.addAttribute("class",K.substr(1).replace(/\./g," "))}if(J==">"&&E){C=E}C.addChild(L);E=L;if(N){F=L}return""});y.last=E;y.multiply_elem=F;return(!z)?y:null},padString:x,setupProfile:b,getNewline:function(){return"\n"},wrapWithAbbreviation:function(z,D,C,B){var y=this.parseIntoTree(z,C||"html");if(y){var A=y.multiply_elem||y.last;A.setContent(D);A.repeat_by_lines=!!y.multiply_elem;return y.toString(B)}else{return null}},splitByLines:f,settings_parser:(function(){function z(F,E,G){return{type:F,key:E,value:G}}var y=/^<(\w+\:?[\w\-]*)((?:\s+[\w\:\-]+\s*=\s*(['"]).*?\3)*)\s*(\/?)>/,D=/([\w\-]+)\s*=\s*(['"])(.*?)\2/g;function A(E,F){return z(n,E,F)}function C(I,J,H,G){var F={name:J,is_empty:Boolean(G)};if(H){var E;F.attributes=[];while(E=D.exec(H)){F.attributes.push({name:E[1],value:E[3]})}}return z(r,I,F)}function B(H){for(var F in H){var G=H[F],E;F=t(F);if(F.substr(-1)=="+"){H[F]=A(F,G)}else{if(E=y.exec(G)){H[F]=C(F,E[1],E[2],E[4]=="/")}else{H[F]=z(w,F,G)}}}}return{parse:function(G){for(var H in G){if(H=="abbreviations"){B(G[H])}else{if(H=="extends"){var E=G[H].split(",");for(var F=0;F<E.length;F++){E[F]=t(E[F])}G[H]=E}else{if(typeof(G[H])=="object"){arguments.callee(G[H])}}}}},extend:function(E,G){for(var F in G){if(typeof(G[F])=="object"&&E.hasOwnProperty(F)){arguments.callee(E[F],G[F])}else{E[F]=G[F]}}},createMaps:function(G){for(var F in G){if(F=="element_types"){for(var E in G[F]){G[F][E]=u(G[F][E])}}else{if(typeof(G[F])=="object"){arguments.callee(G[F])}}}},TYPE_ABBREVIATION:r,TYPE_EXPANDO:n,TYPE_REFERENCE:w}})()}})();if("zen_settings" in this){zen_coding.settings_parser.createMaps(zen_settings);if("my_zen_settings" in this){zen_coding.settings_parser.createMaps(my_zen_settings);zen_coding.settings_parser.extend(zen_settings,my_zen_settings)}zen_coding.settings_parser.parse(zen_settings)}(function(){var k=/^<([\w\:]+)((?:\s+[\w\-:]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,c=/^<\/([\w\:]+)[^>]*>/,g=/([\w\-:]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;var f=b("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed");var a=b("address,applet,blockquote,button,center,dd,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,isindex,li,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul");var i=b("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var");var d=b("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");var j=b("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");var h=b("style");var e=this.HTMLParser=function(o,x){var r,s,p,t=[],u=o;t.last=function(){return this[this.length-1]};var n=0;while(o&&!x.stop){s=true;if(!t.last()||!h[t.last()]){if(o.indexOf("<!--")==0){r=o.indexOf("-->");if(r>=0){if(x.comment){x.comment(o.substring(4,r),n,n+r+3)}o=o.substring(r+3);n+=r+3;s=false}}else{if(o.indexOf("<!DOCTYPE")==0){r=o.indexOf(">");if(r>=0){o=o.substring(r+1);n+=r+1;s=false}}else{if(o.indexOf("</")==0){p=o.match(c);if(p){o=o.substring(p[0].length);p[0].replace(c,q);n+=p[0].length;s=false}}else{if(o.indexOf("<")==0){p=o.match(k);if(p){o=o.substring(p[0].length);p[0].replace(k,m);n+=p[0].length;s=false}}}}}if(s){r=o.indexOf("<");var v=r<0?o:o.substring(0,r);o=r<0?"":o.substring(r);if(r>-1){n+=r}if(x.chars){x.chars(v)}}}else{var l="</"+t.last()+">",w=o.indexOf(l);if(w!=-1){if(x.chars){x.chars(o.substring(0,w))}n+=w+l.length;o=o.substring(w+l.length)}q("",t.last())}if(o==u){throw"Parse Error: "+o}u=o}q();function m(y,B,C,z){if(a[B]){while(t.last()&&i[t.last()]){q("",t.last())}}if(d[B]&&t.last()==B){q("",B)}z=f[B]||!!z;if(!z){t.push(B)}if(x.start){var A=[];C.replace(g,function(E,D){var F=arguments[2]?arguments[2]:arguments[3]?arguments[3]:arguments[4]?arguments[4]:j[D]?D:"";A.push({name:D,value:F,escaped:F.replace(/(^|[^\\])"/g,'$1\\"')})});if(x.start){x.start(B,A,z,n,n+y.length)}}}function q(y,A){if(!A){var B=0}else{for(var B=t.length-1;B>=0;B--){if(t[B]==A){break}}}if(B>=0){for(var z=t.length-1;z>=B;z--){if(x.end){x.end(t[z],n,n+y.length)}}t.length=B}}};e.startTag=k;e.endTag=c;function b(o){var n={},l=o.split(",");for(var m=0;m<l.length;m++){n[l[m]]=true}return n}})();(function(a){a.fn.zen=function(b){a(this).append(zen_coding.expandAbbreviation(b,"html","xhtml"));get=b.replace(/([.[*:+][a-zA-Z0-9]*)|(#.*\$[a-zA-Z0-9]*)/g,"").replace(/>/g," ");return a(this).find(get.toString())}})(jQuery);
