﻿(function() {
   var global = this;
   global.El = global.El || {};
   global.Templates = global.Templates || {};
   global.El.EjsLoader = function(path, fullPath, callback) {
      global.Templates = global.Templates || {};
      fullPath = fullPath || path;
      $.ajax({
         async: false,
         cache: true,
         dataType: 'text',
         type: 'get',
         url: fullPath,
         error: function() {
            throw ("Error getting template");
         },
         success: function(data) {
            var compiler = new EjsCompiler(data)
            compiler.compile();
            global.Templates[path.toLowerCase()] = compiler.process;
            if (callback) {
               callback();
            }
         }
      });
   };

   global.El.CompiledEjsLoader = function(path, fullPath, callback) {
      global.Templates = global.Templates || {};
      fullPath = fullPath || path;
      include(path.replace(path,path+"-compiled.js"));
      if (callback) {
        callback();
      }
   };
})();
