﻿(function($) {
    var n = 0, cache = {};

    $.fn.jqote = function(data) {
        var dom = $([]);

        if (!$.isArray(data)) data = [data];

        $(this).each(function(i) {
            var f = (fn = cache[$.data(this, 'jqote')]) ?
                fn : cache[$.data(this, 'jqote', n++)] = new Function('i, j',
                    "var t=[]; t.push('" +
                    $(this).html()
                        .replace(/\s*<!\[CDATA\[|\]\]>\s*/g, '')
                        .replace(/[\r\n\t]/g, '\\\n')
                        .replace(/<%=(.+?)%>/g, "\t,$1,'")
                        .split("<%").join("\t)\n")
                        .split("%>").join("t.push(\t")
                        .split("\t").join("'") +
                    "'); return $(t.join(''));"
                );

            for (n = 0; n < data.length; n++)
                dom.push(f.call(data[n], i, n));
        });

        return dom;
    };
})(jQuery);