/*======================================================================
PRODUCT:     HUMANIZED MESSAGES 1.0
WEBSITE:     http://humanmsg.googlecode.com
AUTEUR:      ?
======================================================================*/
var humanMsg = {
    setup: function (appendTo, logName, msgOpacity) {
        humanMsg.msgID = 'humanMsg';
        humanMsg.logID = 'humanMsgLog';

        // appendTo is the element the msg is appended to
        if (appendTo == undefined)
            appendTo = 'body';

        // The text on the Log tab
        if (logName == undefined)
            logName = 'Message Log';

        // Opacity of the message
        humanMsg.msgOpacity = .8;

        if (msgOpacity != undefined)
            humanMsg.msgOpacity = parseFloat(msgOpacity);

        // Inject the message structure
        $(appendTo).append('<div id="' + humanMsg.msgID + '" class="humanMsg"><div class="round"></div><p></p><div class="round"></div></div>')

    },

    displayMsg: function (msg) {
        if (msg == '')
            return;

        clearTimeout(humanMsg.t2);

        // Inject message
        $('#' + humanMsg.msgID + ' p').html(msg)

        // Show message
        $('#' + humanMsg.msgID + '').show() //.animate({ opacity: humanMsg.msgOpacity}, 200)

        // Watch for mouse & keyboard in .5s
        humanMsg.t1 = setTimeout("humanMsg.bindEvents()", 700)
        // Remove message after 5s
        //humanMsg.t2 = setTimeout("humanMsg.removeMsg()", 5000)
    },

    bindEvents: function () {
        // Remove message if mouse is moved or key is pressed
        $(window)
        //			.mousemove(humanMsg.removeMsg)
        //			.click(humanMsg.removeMsg)
        //			.keypress(humanMsg.removeMsg)
    },

    removeMsg: function () {
        // Unbind mouse & keyboard
        $(window)
        //.unbind('mousemove', humanMsg.removeMsg)
        //.unbind('click', humanMsg.removeMsg)
        //.unbind('keypress', humanMsg.removeMsg)

        // If message is fully transparent, fade it out
        if ($('#' + humanMsg.msgID).css('opacity') == humanMsg.msgOpacity)
            $('#' + humanMsg.msgID).animate({ opacity: 0 }, 400, function () { $(this).hide() })
    }
};

$(document).ready(function () {
    humanMsg.setup();
})
