/* <?php 

	// Inspired by
	
		// http://jquery.com/demo/thickbox/
		// http://www.huddletogether.com/projects/lightbox/
	
?> */
				
// $Id: class.popup.js,v 1.5 2006-09-18 18:53:35 pheckel Exp $
var Popup = Class.create();
Object.extend(Popup.prototype, {
	
	/**
	 * var pu = new Popup('foregroundId','backgroundId');
	 * var pu2 = new Popup('fgId','bgId','containerId');
	 *
	 * Note: The foreground- and background-object need not be existant.
	 * If the script can't find them, it'll create the divs.
	 */
	initialize: function(fgId,bgId) {
		// Move elements to a global context if they aren't
		// already a child of the document element.
		if (arguments[2]) {
			var container = document.getElementById(arguments[2]);
			
			if (container) {
				var html = container.innerHTML;
				Element.remove(container);
		
				new Insertion.Top(document.body,html);
			}				
		}
		
		this.content = document.getElementById(fgId);
		if (!this.content) { 
			new Insertion.Top(document.body,'<div id="'+fgId+'"></div>');
			this.content = $(fgId);
		}
			
		this.background = document.getElementById(bgId);
		if (!this.background) { 
			new Insertion.Top(document.body,'<div id="'+bgId+'"></div>');
			this.background = $(bgId);
		}
	},

	show: function() { 
		this.showBg();
		this.content.style.display = 'block';
		
		return false;
	},
	
	showBg: function() {
		this.background.style.display = 'block';		
		this._setInt();
		
		return false;
	},
	
	hide: function() { 
		this.hideBg();
		this.content.style.display = 'none';

		return false;
	},
	
	hideBg: function() {
		this.background.style.display = 'none';
		this._clearInt();

		return false;
	},

	_setInt: function() {
		this.intObj = setInterval(
			function() { 				
				var yScroll, windowHeight;
				
				if (window.innerHeight && window.scrollMaxY) yScroll = window.innerHeight + window.scrollMaxY;
				else if (document.body.scrollHeight > document.body.offsetHeight) yScroll = document.body.scrollHeight;
				else yScroll = document.body.offsetHeight;
		
				if (self.innerHeight) windowHeight = self.innerHeight;
				else if (document.documentElement && document.documentElement.clientHeight) windowHeight = document.documentElement.clientHeight;
				else if (document.body) windowHeight = document.body.clientHeight;
				
				if(yScroll < windowHeight) pageHeight = windowHeight;
				else pageHeight = yScroll;

				this.background.style.height = pageHeight+'px';
			}.bind(this),
			20
		);
	},

	_clearInt: function() {
		clearInterval(this.intObj);		
	},
	
	_pageSize: function() {
		var xScroll, yScroll;
		var windowWidth, windowHeight;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		if (self.innerHeight) {
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		if(yScroll < windowHeight) pageHeight = windowHeight;
		else pageHeight = yScroll;
	
		if(xScroll < windowWidth) pageWidth = windowWidth;
		else pageWidth = xScroll;
	
		return {pageWidth: pageWidth, pageHeight: pageHeight, windowWidth: windowWidth, windowHeight: windowHeight, xScroll: xScroll, yScroll: yScroll};
	}	
});

