﻿/// <reference path="jquery.js"/>
/// <reference path="jquery.cookie.js"/>
(function($) {
    $.fn.setStatus = function(options) {
        var opts = $.fn.extend({}, $.fn.setStatus.defaults, options);
        var offset = $(this).offset();
        if (opts.size == null)
            opts.size = { width: $(document).width(), height: $(document).height() };
        if ($('#jqueryplusin_loader') != null && $('#jqueryplusin_loader').length != 0) {
            $('#jqueryplusin_loader').html(opts.loadMsg).attr('class', 'jqueryplusin_loader' + opts.state).css({
                left: (opts.size.width - 200) / 2 + offset.left + 1 + document.documentElement.scrollLeft,
                top: opts.size.height / 4 + offset.top + 1 + document.documentElement.scrollTop
            });
        } else {
            return this.each(function() {
                $('<div id="jqueryplusin_loaderBG" >&nbsp;</div>').css({
                    width: opts.size.width,
                    height: opts.size.height,
                    opacity: 0.5,
                    left: offset.left,
                    top: offset.top
                }).appendTo($(this));

                $('<div id="jqueryplusin_loader" class="jqueryplusin_loader' + opts.state + '"></div>').css({
                    left: (opts.size.width - 200) / 2 + offset.left + 1 + document.documentElement.scrollLeft,
                    top: opts.size.height / 4 + offset.top + 1 + document.documentElement.scrollTop
                }).html(opts.loadMsg).appendTo($(document.body));
                $('#jqueryplusin_loaderBG').css('display', 'block');
                $('#jqueryplusin_loader').css('display', 'block');
            });
        }
    };
    $.fn.removeStatus = function() {
        if ($('#jqueryplusin_loader') != null && $('#jqueryplusin_loader').length != 0) {
            $('#jqueryplusin_loader').remove();
            $('#jqueryplusin_loaderBG').remove();
        }
    }
    $.fn.setStatus.defaults = {
        loadMsg: 'Loading...',
        state: 'load',
        size: null
    }
})(jQuery);