//create a ParcelPark namespace
var ParcelPark = new function() {
};

ParcelPark.util = function() {
    var msgDiv;

    function createBox(t, s) {
        return ['<div class="msg">',
            '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
            '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3>', s, '</div></div></div>',
            '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
            '</div>'].join('');
    }

    return {
        msg : function(title, format, link) {
            if (!msgDiv) {
                msgDiv = Ext.DomHelper.insertFirst(document.body, {id:'parcelpark-msg-div'}, true);
            }
            msgDiv.alignTo(Ext.get('header'), 'tr-tr');
            if (link) {
                msgDiv.setStyle("cursor","pointer");
                msgDiv.on('click', function () {
                    window.location = link;
                });
            } else {
                msgDiv.setStyle("cursor","auto");
                msgDiv.on('click', function () {});
            }
            var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
            var m = Ext.DomHelper.append(msgDiv, {html:createBox(title, s)}, true);
            m.slideIn('t').pause(8).ghost("t", {remove:true});
        }
    };
}();

