var currFade   = Array();
var fadeTarget = Array();
function hud_CreateElement (type, parent) {
        var el = null;
        if (document.createElementNS) {
                el = document.createElementNS("http://www.w3.org/1999/xhtml", type);
        } else {
                el = document.createElement(type);
        }
        fadeBkg = el;
        if (typeof parent != "undefined") {
                parent.appendChild(el);
        }
        return el;
};
function showFadeBox ( id ) {
        bringDiv = document.getElementById(id);
        if ( ! bringDiv ) return 0;
        fullHeight = document.body.clientHeight;
        fullWidth  = document.body.clientWidth;
        if ( fullHeight <= 0 ) {
                fullHeight = window.innerHeight;
                fullWidth = window.innerWidth;
        }
        if ( document.body.scrollTop && document.body.scrollTop > 10 ) document.body.scrollTop = 0;
        if ( document.body.scrollHeight && document.body.scrollHeight > fullHeight ) {
                fullHeight = document.body.scrollHeight;
        }
        if ( document.documentElement.scrollHeight && document.documentElement.scrollHeight > 0 ) fullHeight = document.documentElement.scrollHeight;
        if ( document.documentElement.scrollTop && document.documentElement.scrollTop > 0 ) document.documentElement.scrollTop = 0;
        if ( fullHeight <= 0 ) {
                fullHeight = 1000;
                fullWidth  = 1000;
        }
        fadeDiv = document.getElementById('fadeDivBkg');
        if ( ! fadeDiv ) {
                fadeDiv = hud_CreateElement('div', document.body);
        }
        fadeDiv.id='fadeDivBkg';
        fadeDiv.style.position = 'absolute';
        fadeDiv.style.left = 0;
        fadeDiv.style.top = 0;
        fadeDiv.style.width=fullWidth+'px';
        fadeDiv.style.height=fullHeight+'px';
        fadeDiv.style.backgroundColor = '#000000';
        fadeDiv.style.zIndex=5;
        bringDiv.style.zIndex=10;
        bringdivin('fadeDivBkg', 80);
        centredivhorizontal(id); 
        var el = document.getElementById(id);
        if ( el ) {
                el.style.display = 'block';
                el.style.visibility='visible';
                el.style.zIndex=20;
        }
        return 0;
}
function hideFadeBox ( id ) {
        bringDiv = document.getElementById(id);
        if ( ! bringDiv ) return 0;
        document.body.removeChild(fadeBkg);
        var el = document.getElementById(id);
        if ( el ) {
                el.style.display = 'none';
                el.style.visibility='hidden';
        }
        return 0;
}
function centredivhorizontal( id ) {
   var el = document.getElementById(id);
   if ( el ) {
	w = Math.round(parseInt(el.style.width)/2); 
	var x=Math.round(parseInt(document.body.style.width)/2);
        if (window.innerWidth) {
                screenX = window.innerWidth;
        } else if (document.documentElement && document.documentElement.clientWidth) {
                screenX = document.documentElement.clientWidth;
        } else if (document.body) {
                screenX = document.body.clientWidth;
        } else {
                screenX = 800;
        }
	var z=Math.round(screenX/2)-w;
	el.style.left=z+"px";
   }
}
function bringdivin(divName, target) {
        if ( typeof target == "undefined" ) target = 100;
        var el = document.getElementById(divName);
        if ( el ) {
            var object = el.style;
            if ( target > 0 ) { 
                object.visibility = 'visible';
                object.display = 'block';
            } else {
                object.visibility = 'hidden';
                object.display = 'none';
            }
            currFadePct = target/100;
            object.opacity = currFadePct;
            object.MozOpacity = currFadePct;
            object.KhtmlOpacity = currFadePct;
            object.filter = "alpha(opacity=" + target + ")";
        }
}
function bringdivout(divName, target) {
        if ( typeof target == "undefined" ) target = 0;
        var el = document.getElementById(divName);
        if ( el ) {
            var object = el.style;
            if ( target > 0 ) {
                object.visibility = 'visible';
                object.display = 'block';
            } else {
                object.visibility = 'hidden';
                object.display = 'none';
            }
            currFadePct = target/100;
            object.opacity = currFadePct;
            object.MozOpacity = currFadePct;
            object.KhtmlOpacity = currFadePct;
            object.filter = "alpha(opacity=" + target + ")";
        } 
}

