
// Requires sniffer.js for browser detection to be loaded first.

// SET DEFAULTS

var end_opacity = 50; //end opacity, 25 = 25%, 50 = 50%, 100 = 100%, etc.
var increase_opacity_by = 10; //how much to increase by each time the timeout ends
var timeout = 100; //timeout in miliseconds, 0 = instant fade-out
var cur_opacity = 0;
var posTop = null; // Set to null to use windows sizes to center float-div
var posLeft = null; // Set to null to use windows sizes to center float-div

// Get window height
var winSize = getWindowSize();
var floatSize = [];

// INITIALIZE OBJECTS
var timer = null;
var fade_div = null;
var float_div = null;

function showWindow(fade_id, float_id, eo, iob, t, pt, pl) {

	// OVERRIDE DEFAULTS
	end_opacity = (typeof eo == 'number') ? eo : end_opacity;
	increase_opacity_by = (typeof iob == 'number') ? iob : increase_opacity_by;
	timeout = (typeof t == 'number') ? t : timeout;
	posTop = (typeof pt == 'number') ? pt : posTop;
	posLeft = (typeof pl == 'number') ? pl : posLeft;

    // GET OBJECTS
	float_div = document.getElementById(float_id);
	
	// Add a div to handle the fade
	if (! (fade_div = document.getElementById(fade_id))){
		fade_div = document.createElement('div');
		fade_div.setAttribute('id', fade_id);
		document.body.appendChild(fade_div);
	}
	
    // Opera < version 9 will not support opacity properly
    // just show the div.
    
    if ((is_opera) && (! is_opera9up)){
			float_div.style.display = 'block';
			positionFloat();
    }else{
    	// Other browsers seen to ignore the opacity or support it.
    	// so just move along.
    
		if(timeout > 0) {
			cur_opacity = 0;
			fade_div.style.opacity = cur_opacity / 100;
			fade_div.style.filter = "alpha(opacity=" + cur_opacity + ")";
			fade_div.style.display = 'block';
			positionFade();
			float_div.style.display = 'none';
			timer = setTimeout("increase_opacity()",timeout);
		}else{
			fade_div.style.opacity = end_opacity / 100;
			fade_div.style.filter = "alpha(opacity=" + end_opacity + ")";
			fade_div.style.display = 'block';
			positionFade();
			float_div.style.display = 'block';
			positionFloat();
		}
	}
}

function increase_opacity() {
	cur_opacity += increase_opacity_by;

	fade_div.style.opacity = cur_opacity / 100;
	fade_div.style.filter = "alpha(opacity=" + cur_opacity + ")";
	
	if(cur_opacity < end_opacity) {
		timer = setTimeout("increase_opacity()",timeout);
	}
	else {
		float_div.style.display = 'block';
		positionFloat();
	}
}

function hideWindow() {
	fade_div.style.display = 'none';
	float_div.style.display = 'none';
}

// IE 6 function, to hide/show additional div layers
// that may contain select boxes.
// IE 6 will not honor the z-index of a select box.

function _IE6Div (ids, action){

	if ((is_ie) && (! is_ie7up)){
		var allIds = ids.split(',');
		for (var i=0; i<allIds.length; i++){
			var obj = document.getElementById(allIds[i]);
			obj.style.display = action;
	   	}
	}
}

function positionFade(){

	fade_div.style.height = document.body.offsetHeight + 'px';;

}

function positionFloat(){

	floatSize[0] = float_div.offsetHeight;
	floatSize[1] = float_div.offsetWidth;

    if (posTop == null){
		float_div.style.top = ((winSize[0] / 2) - (floatSize[0] / 2)) + 'px';
	}else{
		float_div.style.top = posTop + 'px';
	}
	
	if (posLeft == null){
		float_div.style.left = ((winSize[1] / 2) - (floatSize[1] / 2)) + 'px';
	}else{
		float_div.style.left = posLeft + 'px';
	}

}

function getWindowSize() {

	var windowsize = [];
	
	if (typeof(window.innerHeight) == 'number') {
		windowsize[0] = window.innerHeight;
		windowsize[1] = window.innerWidth;
	}else{
		if (document.documentElement && document.documentElement.clientHeight) {
			windowsize[0] = document.documentElement.clientHeight;
			windowsize[1] = document.documentElement.clientWidth;
		}else{
			if (document.body && document.body.clientHeight) {
				windowsize[0] = document.body.clientHeight;
				windowsize[1] = document.body.clientWidth;
			}
		}
	}
	return windowsize;
}

