/**
 * royTemplate jQuery plugin
 * require jQuery v1.2 or later
 * 
 * Copyright (c) 2009 顏宏育 Roy Yan 
 * 
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * Website : http://blog.colorbase.tw
 * 
 * varsion 1.0
 */
(function($){$.fn.royTemplate=function(k){function replaceVars(c,d){reg=/%([a-zA-Z0-9_])*%/g;c=c.replace(reg,function(a,b){varName=a.substring(1,a.length-1);if(d[varName]!=undefined){return d[varName]}else{return''}});return c}function applyVars(h,i){var j=$(h).find('> *');$(h).contents().each(function(){var a=this.nodeName.toUpperCase();var c=false;if(a=='TBODY'||a=='THEAD'||a=='TFOOT'){applyVars(this,i)}if($(this).parent().get(0)==$(h).get(0)&&this.nodeType==1)c=true;if(c){var d=$(this).attr('blk');if(d!=undefined){if(i[d]!=undefined){var e=this;if(isNaN(i[d].length)){var f=$(this).clone();f.removeAttr('blk');$(e).after(f);applyVars(f,i[d])}else{var g=i[d].length;var b=0;for(b=0;b<g;b++){var f=$(this).clone();f.removeAttr('blk');$(e).after(f);e=f;applyVars(f,i[d][b])}}}$(this).remove()}}});$(h).html(replaceVars($(h).html(),i))}var l=$(this).clone();applyVars(l,k);return l}})(jQuery);