﻿<!--
var Macallan = (function(){
  function _initialize() {
    document.head=document.getElementsByTagName("head")[0];
    if(!("scripts" in document)){document.scripts=document.getElementsByTagName("script");}
    document.location.path=document.location.protocol+"//"+document.location.host;
    }

  function _load(path, includes) {
    var list="";

    if(typeof(Prototype)!="undefined") {
      Macallan.insertScript(path + "/macallan.wrapper.prototype.js");
      Macallan.insertScript(path + "/macallan.core.js");
      Macallan.insertScript(path + "/macallan.system.js");
      Macallan.insertScript(path + "/macallan.data.js");
      Macallan.insertScript(path + "/macallan.interface.js");

      _loadLibraries((includes ? includes[1] : list).split(","), path);

      Macallan.test(
        function() {
          var firstNode=document.childNodes[0];
          Macallan.doctype=(firstNode.nodeType==Macallan.NODE_DOCUMENT_TYPE)||(Prototype.Browser.IE && firstNode.nodeType==Macallan.NODE_COMMENT && ((firstNode.nodeValue||"").toUpperCase().startsWith("DOCTYPE ")||(firstNode.nodeValue||"").toUpperCase().startsWith("CTYPE ")));
          Macallan.loaded=true;
          document.fire("macallan:loaded");
          },
        function() {
          return Macallan.isFunction($In) &&
                 Macallan.isFunction($HTTP) &&
                 Macallan.isFunction($Validate) &&
                 Macallan.isFunction($XML) &&
                 Macallan.isFunction($Pop);
          });  
      }
    else {
      setTimeout(function() {_load(path, includes);}, 10);
      }
    }

  function _loadLibraries(options, basePath) {
    if(options) {
      basePath=basePath||"";
      if(basePath!=""){basePath+="/";}
      for(var i=0; i<options.length; i++){if(options[i]) {Macallan.insertScript(basePath+options[i]+".js")};}
      }
    }  

  return {
    version: "1.4.1",
    doctype: false,
    loaded: false,
    startLoad: new Date(),
    stopped: true,
    emptyFunction: function() { },
    
    NODE_ALL:                    0,
    NODE_ELEMENT:                1,
    NODE_ATTRIBUTE:              2,
    NODE_TEXT:                   3,
    NODE_CDATA_SECTION:          4,
    NODE_ENTITY_REFERENCE:       5,
    NODE_ENTITY:                 6,
    NODE_PROCESSING_INSTRUCTION: 7,
    NODE_COMMENT:                8,
    NODE_DOCUMENT:               9,
    NODE_DOCUMENT_TYPE:         10,
    NODE_DOCUMENT_FRAGMENT:     11,
    NODE_NOTATION:              12,    
  
    containsScript: function(match) {
      var matching=[];
      
      if(match) {
        for(var i=0; i<document.scripts.length; i++) {
          if(document.scripts[i].src && document.scripts[i].src.match(match)) {matching.push(document.scripts[i]);}
          }
        }
      return matching;
      },

    execute: function(handler) {
      if(Macallan.loaded && typeof(Prototype)!="undefined" && document.body) {
        if(document.loaded||!Macallan.doctype) {
          document.stopObserving("macallan:loaded", function() {Macallan.execute(handler);});
          document.stopObserving("dom:loaded", function() {Macallan.execute(handler);});
          (handler||Macallan.emptyFunction)();
          }
        else {
          setTimeout(function() {Macallan.execute(handler);}, 10);
          }
        }
      else {
        setTimeout(function() {Macallan.execute(handler);}, 10);
        }
      },
  
    insertScript: function(src, relative, handler, predicate) {
      if(Macallan.containsScript((relative ? document.location.path+"/" : "")+src).length==0) {
        if(typeof(Prototype)!="undefined") {
          document.head.appendChild(new Element("script", {
            type: "text/javascript", 
            src: (relative ? document.location.path+"/" : "")+src
            }));
          }
        else {
          var script=document.createElement("script");
          script.setAttribute("type", "text/javascript");
          script.setAttribute("src", (relative ? document.location.path+"/" : "")+src);
          document.head.appendChild(script);
          delete script;
          }
        }
      
      Macallan.test(handler, predicate);
      },

    isFunction: function(object) {
      return typeof object === "function";
      },

    load: function() {
      if(!Macallan.loaded) {
        _initialize();
      
        var items=Macallan.containsScript(/_macallan\.js(\?.*)?$/);
    
        for(var i=items.length-1; i>=0; i--) {
          var path=items[i].src.substring(0, items[i].src.lastIndexOf("/"));
          
          if(!document.location.host){document.location.path=path.substring(0, path.lastIndexOf("/", path.lastIndexOf("/")-1));}
          Macallan.insertScript(path.substring(0, path.lastIndexOf("/")) + "/prototype/prototype.js");
          _load(path, items[i].src.replace(/ /g, "").match(/\?.*load=([\w,]*)/));
          break;
          }
        }
      },

    test: function(handler, predicate, index) {
      index=index||0;
      if(Macallan.isFunction(handler)) {
        if(Macallan.isFunction(predicate) && index<20) {
          try {
            if(predicate()===true) {
              handler();
              }
            else {
              setTimeout(function(){Macallan.test(handler, predicate, index+1);}, 100);
              }
            }
          catch(error) {
            setTimeout(function(){Macallan.test(handler, predicate, index+1);}, 100);
            }
          }
        else {
          try {
            handler();
            }
          catch(error) {
            }
          }
        }
      },

    toString: function() {
      return "[object Macallan]";
      }
    }
})();

Macallan.load();
//-->
