// ===================================================================
// Author: Kyle Hoker <javascript@hoker.com>
// WWW: http://hoker.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, so long as the author and site address above are kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download.
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================
document.write("<style type='text/css'>.modalshade-shim { display: none; overflow : hidden; position: absolute; width: 0px; height: 0px; top: 0px; left: 0px; z-index: 10000;} </style>");

modalShade = function(elemID, color, opacity, args)
{
    this.ie = (document.all) ? 1 : 0;
    this.color = color || 'black';
    this.opacity = opacity || 50;
    this.elemID = elemID;
    this.args = args || {};
    this.init(elemID);
};
modalShade.prototype.init = function(elemID) {
    this.divEl = document.getElementById(elemID);
    this.divEl.style.left = '50%';
    this.divEl.style.zIndex = '10001';
};
modalShade.prototype.show = function() {
    this.scrollTop = document.body.scrollTop;
    this.divEl.style.visibility = 'visible';
    if (this.args.modal !== false)
        document.body.style.overflow = 'hidden';
    this.center();
    if (typeof this.shimEl == 'undefined')
        shimID = this.make(this.elemID);
    this.shimEl.style.top = document.body.scrollTop;
    this.shimEl.style.display = 'block';
};
modalShade.prototype.hide = function() {
    if (typeof this.shimEl == 'undefined')
        return false;
    this.divEl.style.visibility = 'hidden';
    this.shimEl.style.display = 'none';
    if (this.args.modal !== false)
        document.body.style.overflow = 'auto';
    document.body.scrollTop = this.scrollTop;
};
modalShade.prototype.center = function() {
    var ih = (this.ie) ? (window.document.body.clientHeight) : (window.innerHeight);
    var h = ((ih/2) - (this.divEl.offsetHeight/2));
    h += document.body.scrollTop;
    this.divEl.style.top = h + "px";
    this.divEl.style.marginLeft = "-" + (this.divEl.offsetWidth/2) + "px";
};
modalShade.prototype.setstyle = function() {
    this.shimEl.style.backgroundColor = this.color;
    this.shimEl.style.opacity = this.opacity/100;
    this.shimEl.style.height = screen.height;
    this.shimEl.style.width = screen.width;
    var p = (this.ie) ? "filter" : "opacity";
    var v = (this.ie) ? "alpha(opacity="+this.opacity+")" : this.opacity/100;
    this.shimEl.style[p] = v;
};
modalShade.prototype.make = function(winID) {
    var shimID = winID + "_shim";
    var ifrm = document.createElement("IFRAME");
    ifrm.setAttribute("id", shimID);
    ifrm.className = "modalshade-shim";
    document.body.appendChild(ifrm);
    this.shimEl = document.getElementById(shimID);
    this.setstyle(this.shimEl);
    if (this.ie)   //IE doesn't honor background style on an iframe
    {              //so you have to put color into the body iframe html
        var idoc = this.shimEl.contentWindow || this.shimEl.contentDocument;
        if (idoc.document)
            idoc = idoc.document;
        idoc.open();
        idoc.write("<html><body style='background-color: "+this.color+";'></body></style></html>");
        idoc.close();
    }
};