;(function(){
    
    DRHorton = DRHorton || {};
        
    DRHorton.utils = DRHorton.utils || {};
    
    DRHorton.utils.testConditionOverTime = function(p){
        p.start = p.start == undefined ? p.start = (new Date()).getTime() : p.start;
        p.interval = p.interval == undefined ? 100 : p.interval;
        p.failure = p.failure == undefined ? function(){} : p.failure;
        if(!eval(p.expression)){
            if(((new Date()).getTime() - p.start) < p.timeLimit)
                setTimeout(function(){DRHorton.utils.testConditionOverTime(p)}, p.interval);
            else p.failure();
        }
        else p.success();
    };
    
    DRHorton.utils.log = function(str){
        if(typeof console != 'undefined')
            console.log(str);
    }
    
    DRHorton.utils.parseTemplate = function(template, vars){
        var re, delimiter;
        delimiter = arguments[2] || "#";
        for(var j in vars){
            re = new RegExp(delimiter + j + delimiter, 'gi');
            template = template.replace(re, vars[j]);
        }
        return template;
    }
    
    DRHorton.utils.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;
    }
    
}());
