_debug = {};

_debug._window = null;

_debug.window = function(){
    // output to separate window - better for debugging while the page is being built
    if (!_debug._window || !_debug._window.document){
        _debug._window = window.open("about:blank", "debug", "width=1000,height=350,status=yes,resizable=yes, scrollbars=yes");
        _debug._window.document.body.style.fontSize="14px";
        _debug._window.focus();
        //_debug._window.document.write('Debug window <br>');
    }
    return _debug._window;
}

debug = function(){
    var dd = _debug.window().document; //window().document.body;
    for (var i=0; i<arguments.length; i++){
        dd.write('<pre style="font-size: 14px;">' + arguments[i] + '</pre>\n');
    }
    dd.write('<hr>\n');
}

debug.focus = function(){
    _debug.window().focus();
}

debug.timer = function(blurb, showFunc){
    this.showFunc = showFunc ? showFunc : function(x){alert(x)};
    this.before = new Date().getTime();
    this.blurb = blurb;
    this.tell = function(){
        var time = new Date().getTime() - this.before;
        this.showFunc(this.blurb + ': time = ' + time);
    }
}
//debug('');
