//! clog.js
//! version : 1.1
//! author : Mark Pottie (velvary pty ltd)
//! license : MIT
//! www.velvary.com.au

// switch dbug on only for selected hosts
var dbug = (document.location.host=='sandbox.wordpress'||document.location.host=='www.velvary.com.au');

function vbgetstyle(st, tc, bg) {

    tc = typeof tc == 'undefined' ? null : tc;
    bg = typeof bg == 'undefined' ? null : bg;
    bg = bg == null ? 'black' : bg;
    tc = tc == null ? 'lime' : tc;
    var h1 = 'line-height:35px;font-weight:bold;font-size:18px;color:' + tc + ';background:' + bg + ';padding:6px;border:1px solid ' + tc + ';';
    tc = tc == null ? 'yellow' : tc;
    var h2 = 'line-height:30px;font-weight:bold;font-size:16px;color:' + tc + ';background:' + bg + ';padding:4px;border:1px solid ' + tc + ';';
    tc = tc == null ? 'hotpink' : tc;
    var h3 = 'line-height:25px;font-weight:bold;font-size:14px;color:' + tc + ';background:' + bg + ';padding:2px;border:1px solid ' + tc + ';';
    tc = tc == null ? 'aqua' : tc;
    var h4 = 'line-height:25px;font-weight:bold;font-size:14px;color:' + tc + ';background:' + bg + ';padding:2px;border:1px solid ' + tc + ';';
    var b = 'font-weight:bold;';
    if (st == 'h1') {
        return h1;
    }
    if (st == 'h2') {
        return h2;
    }
    if (st == 'h3') {
        return h3;
    }
    if (st == 'h4') {
        return h4;
    }
    if (st == 'b') {
        return b;
    }
    return st;
}


// <editor-fold defaultstate="collapsed" desc="Debug console functions">




// log error
function loge(s, style, insist) {
    insist = typeof insist != 'undefined';
    if (insist || dbug) {
        if (style == 1) {
            console.info(s);
        } else {
            console.info('%c' + s, '' + style);
        }
    }
}


// for chrome only. adjust for safari or firefox
function logd(heading, s, style, textcolor, bgcolor, insist) {

    if (!dbug) {
        console.log(document.location.host);
        return;
    }

    textcolor = typeof textcolor == 'undefined' ? null : textcolor;
    bgcolor = typeof bgcolor == 'undefined' ? null : bgcolor;
    style = vbgetstyle(style, textcolor, bgcolor);
    insist = typeof insist != 'undefined';

    var toPrint = [];

    function getErrorObject() {
        try {
            throw Error('')
        } catch (err) {
            return err;
        }
    }

    var err = getErrorObject(), caller;

//    if ($.browser.mozilla) {
//        caller = err.stack.split("\n")[2];
//    } else {
    caller = err.stack.split("\n")[4];
//    }

    if (typeof caller != 'undefined') {
        var index = caller.indexOf('.js');

        var str = caller.substr(0, index + 3);
        index = str.lastIndexOf('/');
        str = str.substr(index + 1, str.length);

        var info = "" + str;

        var fn = caller.replace('    at ', '');
        fn = fn.substr(0, fn.indexOf(' '));
        //    if ($.browser.mozilla) {
        //        str = caller;
        //    } else {
        index = caller.lastIndexOf(':');
        str = caller.substr(0, index);
        //    }
        index = str.lastIndexOf(':');
        str = str.substr(index + 1, str.length);
        info += " " + str + ' ' + fn;
        toPrint.push(info);
    } else {
        info = '???';
    }


    if (insist || dbug && str != '3555') {
        console.log('%c' + info + ':\t' + heading, '' + style);
        if (s != 'nodata') {
            console.log(s);
        } else {

        }
        if (err.stack) {
            //console.log(err.stack.split("\n"));
        }
        //    console.log.apply(console, toPrint);
    }

}

// </editor-fold>

