/**
 * Define a new console if it does not exist
 */
$(function(){
    try{
        if(console.log){}
    }catch(e){
        //  Create a dom console
        var div=$('<div style="filter:alpha(opacity=90);-moz-opacity:0.9;-khtml-opacity: 0.9;opacity: 0.9;z-index:998;position:absolute;top:0;right:0;width:600px;color:#fff;"><div class="__console" style="background:#fff;height:500px;padding:10px;display:block;color:#fff;overflow:auto;color:#000;padding-top:30px;border:solid 1px #333;"></div><a style="position:absolute;top:0px;left:0px;background:#333;color:#fff;padding:5px;" href="#" id="console">console</a></div>');

        var inner=$('.__console',div);

        
        inner.slideUp(0);
        $('a#console',div).slideUp(0);
//
        div.hide();
        $('body').append(div);

        $('a#console',div).bind('click',function(){
            inner.slideToggle(function(){
                $('a#console',div).fadeOut(250);
            });
        });

        $('a#console',div).bind('dblclick',function(){
            inner.html("");
            return false;
        });

        var timer=null;
        var timer_expired=false;

        $('body').bind('mousemove',function(e){
            function on_timer(){
                $('a#console',div).fadeIn(250);
                clearInterval(timer);
                timer=null;
                timer_expired=true;
            };

            if(e.pageY<20 && timer==null && timer_expired==false){
                timer=setInterval(on_timer,250);
            }

            if(e.pageY>20){
                clearInterval(timer);
                timer=null;
                timer_expired=false;
            }
        });

        div.fadeIn(1000);

        function render_text(e){
            if(typeof(o) != 'object'){
                e=$.toJSON(e);
            }
            return e+"<hr/>";
        };

        console={

          //  $()
            log:function(e){
                var dd=$("<div>"+render_text(e)+"</div>");
                inner.append(dd);
            }
            ,warn:function(e){
                var dd=$("<div style='color:red;'>"+render_text(e)+"</div>");
                inner.append(dd);
            }
            ,info:function(e){
                var dd=$("<div style='color:#66d;'>"+render_text(e)+"</div>");
                inner.append(dd);
            }
        };
    }
    console.log("Testing console.log");
    console.warn("Some consolo.warn");
    console.info("Some console.info");
});