$.fn.extend({Loader: function (Options) { return new Loader($(this), Options); }});
	
var Loader = function (Container, Options) {
	var Me = this;
	
	Me.Loader = false;
	Me.LoaderWidth = 126;
	Me.LoaderHeight = 22;
	Me.ZIndex = 100;
	Me.LoaderClass = 'loader';
	Me.AutoShow = true;
	Me.FadeIn = false;
	Me.FadeOut = true;
	
	if (typeof Options != 'undefined')
		$.each(Options, function (Key, Val) { Me[Key] = Val; });
	
	Me.Container = Container
	
	Me.GenerateLoader = function () {
	    var ContainerWidth = Container.width();
	    ContainerWidth = ContainerWidth > 0 ? ContainerWidth : Container.parent().width();
	    
	    var ContainerHeight = Container.height();
	    ContainerHeight = ContainerHeight > 0 ? ContainerHeight : Container.parent().height();
	    
        return Container.append('<div class="' + Me.LoaderClass + '"></div>').
                    find('.' + Me.LoaderClass + ':last').css({
                        position: 'absolute',
                        marginLeft: ((ContainerWidth / 2) - (Me.LoaderWidth / 2)) + 'px',
                        marginTop: ((ContainerHeight / 2) - (Me.LoaderHeight / 2)) + 'px',
                        width: Me.LoaderWidth + 'px',
                        height: Me.LoaderHeight + 'px',
                        zIndex: Me.ZIndex
                    }).hide();
    };
	
	Me.Show = function () {
        if (Me.Loader == false) Me.Loader = Me.GenerateLoader();
        
        if (Me.FadeIn) Me.Loader.fadeIn();
        else Me.Loader.show();
    };
    
    Me.Hide = function () {
        if (Me.FadeOut) Me.Loader.fadeOut();
        else Me.Loader.hide();
    };
    
    if (Me.AutoShow) Me.Show();
	
	return this;
	
};