define(['handlebars'], function (Handlebars) {

    function _init() {
        Handlebars.registerHelper('list', function (items, options) {
            var out = "<ul>";
            for (var i = 0, l = items.length; i < l; i++) {
                out = out + "<li>" + options.fn(items[i]) + "</li>";
            }
            return out + "</ul>";
        });
    }

    function _getTemplate(name) {
        var that = this;
        if (!that.cached) {
            that.cached = {};
        }
        var template = that.cached[name];
        if (!template) {
            var raw = $.ajax({
                    'url': 'media/js/templates/' + name + '.hbs',
                    'async': false
                }).done(function (raw) {
					template = Handlebars.compile(raw);
					that.cached[name] = template;
                })
        }
        return template;
    }

    return {
        init: _init,
        getTemplate: _getTemplate
    }
});