	// Height required if iframe:true
	var Box = {		// Pop-up box class
		ie: ( navigator.appVersion.indexOf('MSIE') > 0 ),
		delta_x: 25,
		delta_y: 25,
		title_height: 35,
		content: '',

		derivePosition: function (event) {
			var e = event ? event : window.event;// Capture this mouse movment for IE
			this.x = this.pointerX(e);
			this.y = this.pointerY(e);
		},

		fill: function(content) {
			document.getElementById('boxContent').innerHTML = content;
		},
	
		init: function() {
			if (!this.div) {	// Create div if needed
				var div = document.createElement('div');
				div.id = 'box';
				div.className = 'box';
				div.style.display = 'none';
				document.body.appendChild(div);
				this.div = div;
			}
			this.div.style.height = '';	// reset for previous instances
		},

		open: function(options) {
			if (!this.x) {	// if coordinates not set, decide where to get x/y coordinates
				if (options.center) {	// center of the screen
					this.x = 100;
					this.y = 100;
					this.center = true;
				} else if (options.x) {	// explicitly set
					this.x = options.x;
					this.y = options.y;
				} else // derive from passed event
					this.derivePosition(options.e);
			}

			this.init();
			this.content = options.content;
			this.title = options.title ? options.title : '&nbsp;';
			this.width = options.width ? options.width : 400; // default 400 width
			this.height = options.height;
			this.iframe = options.iframe ? true : false;
			this.url = options.url;
	
			if (this.lock){
				this.div.style.display = 'none';
				Box.open_complete();
			}
			else
				this.open_complete();
		},
	
		open_complete: function() {
			this.lock = true;
			var div = this.div;
			// Fill div
			div.innerHTML = '<table class="boxTable"><tr><th>'
				+ '<div style="cursor:pointer;background:#A5BBDB;float:right;" onclick="Box.close();">'
				+ '&nbsp;Close&nbsp;</div>' + this.title + '</th></tr><tr><td>';

			if (this.iframe)
				div.innerHTML += '<iframe width="100%" height="' + (this.height - this.title_height) + '" frameborder="0" src="' + this.url + '"></iframe>';
			else {
				div.innerHTML += '<div style="height:' + (this.height - this.title_height) + 'px;" id="boxContent">' + this.content + '</div>';
				this.boxContent = document.getElementById('boxContent');
			}
			div.innerHTML += '</td></tr></table>';

			div.style.width = this.width + 'px';	// Set width
			if (this.height) div.style.height = this.height + 'px';
			var dimensions = this.getDimensions(div);	// Compute box dimension

			if (this.center){
				div.style.left = ( this.getWindowWidth() - dimensions.width ) / 2 + 'px';	// position box X
				div.style.top = ( this.getWindowHeight() - dimensions.height ) / 2 + 'px';	// position box X
			} else {
				div.style.left = this.positionX(dimensions.width) + 'px';	// position box X
				div.style.top = this.positionY(dimensions.height) + 'px';	// position box Y		
			}	

			this.div.style.display = 'block';
		},
	
		close: function() {
			this.lock = false;
			this.div.style.display = 'none';
			this.div.innerHTML = '';
		},
	
		getWindowHeight: function() {
			var innerHeight;
			if (this.ie)
				innerHeight = document.body.clientHeight;
			else
				innerHeight = window.innerHeight;
	
			return innerHeight - this.delta_y;
		},
	 
		getWindowWidth: function() {
		 	var innerWidth;
			if (this.ie)
				innerWidth = document.body.clientWidth;
		 	else
				innerWidth = window.innerWidth;
	
			return innerWidth - this.delta_x;
		},
	
		positionX: function(element_width) {
			mouse_x = this.x;
	
			if ( (element_width + mouse_x) >= ( this.getWindowWidth() - this.delta_x) ){ // too big for X
				mouse_x = mouse_x - element_width;	// apply delta so box is not on link
				mouse_x = mouse_x - 10;
			} else
				mouse_x = mouse_x + 10;
	
			if (self.pageXOffset) // all except Explorer
				xScroll = self.pageXOffset;
			else // all other Explorers
				xScroll = document.body.scrollLeft;
	
			if (mouse_x < 0) mouse_x = 0;
			return mouse_x + xScroll;
		},
	
		positionY: function(element_height) {
			mouse_y = this.y;
	
			if ( (element_height + mouse_y) >= ( this.getWindowHeight() - this.delta_y) ){ // too big for Y
				mouse_y = mouse_y - element_height;	// apply delta so box is not on link
				mouse_y = mouse_y - 10;
			} else
				mouse_y = mouse_y + 10;
	
			if (self.pageYOffset){ // all except Explorer
				yScroll = self.pageYOffset;
			} else if (document.documentElement && document.documentElement.scrollTop){
				yScroll = document.documentElement.scrollTop;
			} else // all other Explorers
				yScroll = document.body.scrollTop;

			if (mouse_y < (yScroll + this.delta_y)) mouse_y = yScroll;
			return mouse_y;
		},

		pointerX: function(event) {
			return event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
		},
	
		pointerY: function(event) {
			return event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
		},

		getDimensions: function(element) {
	      return {width: element.offsetWidth, height: element.offsetHeight};
		}
	}
