
;(function(){
    
    DRHorton = DRHorton || {};
    
    // private 
    var included = [],
        read = [],
        fileIncluded = function(url){
            for(var i = 0; i < included.length; i++)
                if(included[i] == url)
                    return true;
            return false;
        },
        fileRead = function(url){
            for(var i = 0; i < read.length; i++)
                if(read[i] == url)
                    return true;
            return false;
        },
        absoluteUrl = function(url){
            if(document.location.protocol.indexOf('file') == 0){
                var lh = "http://localhost";
            }
            else {
                var lh = document.location.protocol + "//" + document.location.host;
            }
            if(url.indexOf('http') != 0){
                if(url.indexOf('/') != 0)
                    url = lh  + document.location.pathname.replace(/\/\w*\.\w*/img, '') + "/" + url;
                else url = lh + url;
            }     
            return url;
        },
        
        
        makeXMLHttpRequest = function(){
            var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] 
            if (window.ActiveXObject){ 
                for (var i=0; i<activexmodes.length; i++){
                    try{
                        return new ActiveXObject(activexmodes[i])
                    }
                    catch(e){}
                }
            }
            else if (window.XMLHttpRequest) // if Mozilla, Safari etc
                return new XMLHttpRequest()
            else
                return false
            return false;
        }        
    ;
    
    if(typeof DRHorton.core == 'undefined')
        DRHorton.core = {};
    
    // public     
    DRHorton.core.include = function(url){
        url = absoluteUrl(url);
        if(fileIncluded(url)) return;
        var xmlhttp =  makeXMLHttpRequest();
        
        /* The callback function */
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200){}
                    //alert(xmlhttp.responseText);
                else {
                    //alert("eh")
                }
            }
        }
        
        xmlhttp.open("GET", url+"?r=" + Math.random(), false)
        xmlhttp.send(null)
        eval(xmlhttp.responseText);
        
    };
    
    
}())


var log = log || function(str){
    if(typeof console != "undefined")
	console.log(str);
};



// credit: Douglas Crockford, www.crockford.com
// source: http://www.crockford.com/javascript/inheritance.html
Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
};

Function.method('inherits', function (parent) {
    var d = {}, p = (this.prototype = new parent());
    this.method('uber', function uber(name) {
	if (!(name in d)) {
	    d[name] = 0;
	}        
	var f, r, t = d[name], v = parent.prototype;
	if (t) {
	    while (t) {
		v = v.constructor.prototype;
		t -= 1;
	    }
	    f = v[name];
	} else {
	    f = p[name];
	    if (f == this[name]) {
		f = v[name];
	    }
	}
	d[name] += 1;
	r = f.apply(this, Array.prototype.slice.apply(arguments, [1]));
	d[name] -= 1;
	return r;
    });
    return this;
});

Function.method('swiss', function (parent) {
    for (var i = 1; i < arguments.length; i += 1) {
	var name = arguments[i];
	this.prototype[name] = parent.prototype[name];
    }
    return this;
});

Function.prototype.methods = function (defs) {
    for(var j in defs)
        this.method(j, defs[j]);
};

