<!--
/*
 * b1gMail7 client library
 * (c) 2002-2008 B1G Software
 * 
 * Redistribution of this code without explicit permission
 * is forbidden!
 *
 * $Id: overlay.js,v 1.9 2008/05/20 22:24:08 patrick Exp $
 *
 */

var olCounter = 0, olOverlays = new Object;

function __hideOverlay(id)
{
	olOverlays[id].hide();
}

function __getLastOLID()
{
	var lastOLID = -1;
	for(var olID in olOverlays)
		if(olOverlays[olID] != null)
			lastOLID = olID;
	return(lastOLID);
}

function __getPLastOLID()
{
	var lastOLID = -1, pLastOLID = -1;
	for(var olID in olOverlays)
		if(olOverlays[olID] != null)
		{
			pLastOLID = lastOLID;
			lastOLID = olID;
		}
	return(pLastOLID);
}

function __getOLCount()
{
	var i = 0;
	for(var olID in olOverlays)
		if(olOverlays[olID] != null)
			i++;
	return(i);
}

function hideOverlay()
{
	var lastOLID = __getLastOLID();
	if(lastOLID >= 0)
		__hideOverlay(lastOLID);
}

function overlayDocument()
{
	if(olOverlays.length <= 1)
		return(window);
	else
	{
		return(frames['__olFrame_'+__getPLastOLID()]);
	}
}

function openOverlay(url, name, w, h, clean)
{
	if(top != window)
	{
		// new OL on parent page
		return top.openOverlay(url, name, w, h, clean);
	}
	
	var overlay = new Overlay();
	overlay.setSize(w, h);
	overlay.setCaption(name);
	overlay.setPage(url, clean);
	overlay.show();
	return(overlay);
}

function Overlay()
{
	this.id = olCounter++;//olOverlays.length;
	this.visible = false;
	this.hide = function()
	{
		olOverlays[this.id] = null;
		
		if(__getOLCount() == 0)
		{
			this.olBackground.style.display = 'none';
			this.olBody.removeChild(this.olBackground);
		}
		else
		{
			this.olContainer.style.display = 'none';
			this.olShadow.style.display = 'none';
			this.olBackground.removeChild(this.olContainer);
			this.olBackground.removeChild(this.olShadow);
		}
		this.visible = false;
	}
	this.show = function()
	{
		this.olBackground.style.display = 'block';
		this.olContainer.style.display = 'block';
		this.visible = true;
	}
	this.init = function()
	{
		this.olBody = document.getElementsByTagName('body').item(0);
		
		// background
		if(__getOLCount() == 1)
		{
			this.olBackground = document.createElement('div');
			this.olBackground.style.position = 'absolute';
			this.olBackground.style.display = 'none';
			this.olBackground.style.top = '0px';
			this.olBackground.style.left = '0px';
			this.olBackground.style.zIndex = 100+this.id;
			this.olBackground.style.width = '100%';
			this.olBackground.style.height = getDocumentMetrics('pageH') + 'px';
			this.olBackground.id = '__olBackground';
			this.olBackground.onclick = function() { hideOverlay(); return(false); }
			this.olBody.insertBefore(this.olBackground, this.olBody.firstChild);
		}
		else
		{
			this.olBackground = EBID('__olBackground');
		}
		
		// container
		this.olContainer = document.createElement('div');
		this.olContainer.style.display = 'none';
		this.olContainer.style.position = 'absolute';
		this.olContainer.setAttribute('id', '__olContainer_'+this.id);
		this.olContainer.className = '__olContainer';
		this.olContainer.style.zIndex = 102+this.id;
		this.olBackground.insertBefore(this.olContainer, this.olBackground.firstChild);
		
		// shadow
		this.olShadow = document.createElement('div');
		this.olShadow.style.position = 'absolute';
		this.olShadow.setAttribute('id', '__olShadow_'+this.id);
		this.olShadow.className = '__olShadow';
		this.olShadow.style.zIndex = 101+this.id;
		this.olBackground.insertBefore(this.olShadow, this.olBackground.firstChild);
		
		// content
		this.olContent = document.createElement('div');
		this.olContent.style.width = '100%';
		this.olContent.style.height = '100%';
		this.olContent.setAttribute('id', '__olContent_'+this.id);
		this.olContent.className = '__olContent';
		this.olContainer.insertBefore(this.olContent, this.olContainer.firstChild); 
		
		// caption
		this.olCaption = document.createElement('div');
		this.olCaption.style.width = '100%';
		this.olCaption.setAttribute('id', '__olCaption_'+this.id);
		this.olCaption.className = '__olCaption';
		this.olContainer.insertBefore(this.olCaption, this.olContainer.firstChild);
	}
	this.setSize = function(w, h)
	{
		h += (document.all ? 15 : 0);
		
		this.w = w;
		this.h = h;
		
		this.olContainer.style.left = (getDocumentMetrics('windowW')/2 - w/2) + 'px';
		this.olContainer.style.top = (getDocumentMetrics('rScrollY') + getDocumentMetrics('windowH')/2 - h/2) + 'px';
		this.olContainer.style.width = w + 'px';
		this.olContainer.style.height = (h+26) + 'px';
		
		this.olShadow.style.left = (parseInt(this.olContainer.style.left) + 7) + 'px';
		this.olShadow.style.top = (parseInt(this.olContainer.style.top) + 7) + 'px';
		this.olShadow.style.width = this.olContainer.style.width;
		this.olShadow.style.height = this.olContainer.style.height;
	}
	this.setCaption = function(caption)
	{
		this.olCaption.innerHTML = caption;
	}
	this.setPage = function(url, clean)
	{
		this.olFrame = document.createElement('iframe');
		this.olFrame.setAttribute('name', '__olFrame_' + this.id);
		this.olFrame.setAttribute('id', '__olFrame_' + this.id);
		this.olFrame.setAttribute('scrolling', clean ? 'no' : 'auto');
		this.olFrame.setAttribute('width', '100%');
		this.olFrame.setAttribute('height', this.h);
		this.olFrame.setAttribute('src', url);
		this.olFrame.setAttribute('frameBorder', 0);
		this.olFrame.setAttribute('border', 0);
		this.olContent.insertBefore(this.olFrame, this.olContent.firstChild);
	}
	
	olOverlays[this.id] = this;
	this.init();
}

//-->
