﻿jQuery.fn.centre = function() {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
    return this;
}
jQuery.fn.modalShow = function() {
    if ($('#divOverlay').length < 1) {
        this.parent().append('<div id="divOverlay" style="width:100%;height:100%;background:#ffffff none repeat scroll 0 0;filter:alpha(opacity=50);opacity:0.5;position:fixed;top:0px;left:0px;z-index:10"></div>').show();
    }
    else {
        $('#divOverlay').show();
    }
    this.css({ 'z-index': '20' }).show();
    
    //would be nice to have code to add a close button to the div automatically
    
    return this;
}
jQuery.fn.modalHide = function() {
    $('#divOverlay').hide();
    this.hide();
    return this;
}
jQuery.fn.loadingShow = function() {
    if( $('#divJQLoading').length < 1)
    {
        $('body').append('<div id="divJQLoading"><img src="/_Common/_Images/roller.gif" alt="Loading" /></div>');        
    }
    $('#divJQLoading').centre().modalShow().show();    
    return this;
}
jQuery.fn.loadingHide = function() {
    $('#divJQLoading').modalHide().hide();
    return this;
}
