var msg = {
    create : function(content, callback, type)
    {
        this.wall = document.createElement('div');
        $(this.wall).attr('id', 'wall');
        $(this.wall).attr('class', 'mwall');
        $(this.wall).css({
            width  : $(document).width() +'px',
            height : $(document).height() +'px',
            display: 'block'
        }).appendTo(document.body);
        
        //msg shaddow
        this.shadow = document.createElement('div');
        $(this.shadow).attr('class', 'msgShadow');
        $(this.shadow).css({
            left: ($(window).width() - 300) / 2 + 'px',
            top: $(window).scrollTop() + 250 + 'px'
        }).appendTo(document.body);
        
        //msg box
        this.box = document.createElement('div');
        $(this.box).attr('class', 'mbox');
        if(typeof callback == 'undefined')
            $(this.box).bind('click', function() {
                msg.close();
                return false;
            });
        if(typeof type == 'undefined')
            var type = 'alert';

        $(this.box).css({
            left: ($(window).width() - 280) / 2 + 'px',
            top: $(window).scrollTop() + 260 + 'px',
            cursor: 'pointer'
        }).appendTo(document.body).html('<p>' + content + '</p>');
        
        $(this.shadow).css('height', ($(this.box).height()+62)+'px');
        
        if(typeof callback != 'undefined'){
            this.button = document.createElement('button');
            $(this.button).bind('click', function() {
                eval(callback);
                msg.close();
                return false;
            });
            if(type == 'confirm')
              $(this.button).appendTo(this.box).html(' Taip ');
            else
              $(this.button).appendTo(this.box).html(' Gerai ');

            if(type == 'confirm')
            {
                this.button = document.createElement('button');
                $(this.button).bind('click', function() {
                    msg.close();
                    return false;
                });
                $(this.button).appendTo(this.box).html(' Ne ');
            }
        }
    },
    change : function(content)
    {
         $(this.box).appendTo(document.body).html(content);
    },
    loading : function(msg)
    {
        content = '<img src ="'+BASE_URL+'/images/loading.gif" class="loading"> ' + msg;
        this.create(content);
    },
    preloading : function(el)
    {
        $('<img src ="'+BASE_URL+'/images/loading.gif" id="loader_'+el+'" class="loading">').insertAfter('#'+el);
    },
    prefinish : function(el)
    {
        $('#loader_'+el).remove();
    },
    close : function()
    {
        $(this.shadow).fadeOut();
        $(this.shadow).queue(function (){
                $(this.shadow).remove();
            }
        )
        $(this.box).fadeOut();
        $(this.box).queue(function (){
                $(this.box).remove();
                $("#wall").remove();
            }
        )
    }
}
$.getScripts = function(scripts, onComplete)
{
var i = 1;
var ii = scripts.length;
var onScriptLoaded = function(data, response) { if (i++ == ii) onComplete(); } ;
for(var s in scripts) { $.getScript(scripts[s], onScriptLoaded); } ;
};

function loadWysiwyg(id)
{
    $.getScripts([
      BASE_URL + '/plugins/openwysiwyg/scripts/wysiwyg-settings.js',
      BASE_URL + '/plugins/openwysiwyg/scripts/wysiwygCMPjquery.js'],
      function() {
          WYSIWYG.setSettings(id, small);
          WYSIWYG_Core.includeCSS(BASE_URL + '/plugins/openwysiwyg/style/wysiwyg.css');
          WYSIWYG._generate(id, small);
      }
    );
}
