//window.status = 'Loading [CR.Csi.js] ';

if (typeof Prototype != 'object') {
  throw new Error( 'CR.Csi.js requires prototype.js version 1.6 or greater' );
}

// Define the CR namespace 
if (CR == undefined) {
  var CR = {};
}

if (!CR.Csi) {
  CR.Csi = (function() {

    // Private attributes and methods
    VERSION = '1.0'; // no point in this ;) no wait, there's one point, or one prick involved

    return ({ //Public attributes and methods

      include: function(url, targetNode, callbackHandler) {
        new Ajax.Request(url, {
          method: 'post',
          onSuccess: function(transport) {
            var node = $(targetNode);
            var res = transport.responseText;
            if (node) {
              //window.loadFirebugConsole();
              //console.log("running eval...");
              node.innerHTML = /*new Date().getTime() + "<br />" + */res; // uncomment to check response
              var scripts = node.getElementsByTagName("script");
              for (var i = 0; i < scripts.length; i++) eval(scripts[i].innerHTML);
            }
          },
          onFailure: function(transport) {
            //alert("onFailure: " + transport);
            alert("Hei! Vi beklager, men vi oppdaterer applikasjonen.\nDen vil være tilbake om få minutter.");
          }
        });
      },

      toString: function() {
        return 'CR.Csi, version ' + VERSION;
      }

    }); //~return

  } ) (); //~anonymous function immediately invoked with ()
}
