﻿/*
        Author  :   Anand Kumar Sharma
        Date    :   21-10-2009
        Purpose :   To create overlay on modal windows.
*/



$.fn.extend(
{
    showoverlay:function(options)
    {
        var defaults = 
        {
            imgPath : 'JSOS/elapsor.gif',
            topX    : 0,
            topY    : 0,
            bgColor : '#ccffff',
            myOpacity:   .85,
            textStyle   :   ''
        };
        
        var opts = $.extend(defaults, options);
        var w = [this.innerWidth(),this.innerHeight()];
        var s = [this.scrollLeft(),this.scrollTop()];
       // var a = [$(this)[0].offsetLeft,$(this)[0].offsetTop];
        var offset = $(this).position();
        var topX = offset.top;
        var leftY = offset.left;
        //if(opts.topX == 0 && opts.topY == 0)
            //$(this).append('<div class="myoverlay" style="background-color:' + opts.bgColor + ';opacity:' + opts.myOpacity + '; z-index:9999; height:' + w[1] + 'px; width:' + w[0] + 'px; position:absolute;"><div style="z-index:99999; width:' + w[0] + 'px; top:' + ((w[1]/2)) + 'px; left:' + ((w[0]/2)) + 'px; position:absolute;"><img src="' + defaults.imgPath + '" /><br /><span class=\"' + opts.textStyle + '\">Loading...</span></div></div>');
        //else
            //$(this).append('<div class="myoverlay" style="opacity:' + opts.myOpacity + '; z-index:9999; height:' + w[1] + 'px; width:' + w[0] + 'px; top:' + (opts.topX) + 'px; left:' + (opts.topY) + 'px; position:absolute;"><div style="z-index:99999; width:' + w[0] + 'px; top:' + ((w[1]/2)-90) + 'px; left:' + ((w[0]/2)-90) + 'px; position:absolute;"><img src="' + defaults.imgPath + '" /></div></div>');
            //$(this).append('<div class="myoverlay" style="opacity:' + opts.myOpacity + '; z-index:9999; height:' + w[1] + 'px; width:' + w[0] + 'px; top:' + (opts.topX) + 'px; left:' + (opts.topY) + 'px; position:absolute; background: black url(' + opts.imgPath + ') no-repeat center;"><div style="z-index:99999; width:' + w[0] + 'px; top:' + ((w[1]/2)-90) + 'px; left:' + ((w[0]/2)-90) + 'px; position:absolute; "></div></div>');
            if($(this).parent().is('body') || $(this).parent().is('form'))
                $(this).append('<div class="myoverlay" style="opacity:' + opts.myOpacity + '; z-index:9999; height:' + w[1] + 'px; width:' + w[0] + 'px; top:' + 0 + 'px; left:' + 0 + 'px; position:absolute; background: #f0f0f0 url(' + opts.imgPath + ') no-repeat center;"></div>');
            else
                $(this).append('<div class="myoverlay" style="opacity:' + opts.myOpacity + '; z-index:9999; height:' + w[1] + 'px; width:' + w[0] + 'px; top:' + (topX) + 'px; left:' + (leftY) + 'px; position:absolute; background: #f0f0f0 url(' + opts.imgPath + ') no-repeat center;"></div>');
    },
    hideoverlay:function()
    {
        $(this).find('.myoverlay').remove();
    }
});
