boxOverlayArray = [];
function boxOverlay(optObj) {
	var optObj = optObj || {}
	var boxWidth = optObj.width || '500px'
	var boxHeight = optObj.height || '500px'
	var format = optObj.format || '<a href="javascript://" onclick="removeOverlay();>Close</a>'	
	var boxStyle = optObj.style || false
	var d = new Date();
	var overlayID = 'overlay'+Math.floor(Math.random()*d.getTime()*999);
	var boxID = 'box'+Math.floor(Math.random()*d.getTime()*999);
	var content = optObj.content || false;
	
	this.init = function() {
		if (boxOverlayArray.length >= 1) {
			var zindex = boxOverlayArray[boxOverlayArray.length-1].zi + 3;
		} else {
			var zindex = 76;
		}
		
		var myWidth = 0, myHeight = 0;

		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}				
		var olay = $(document.createElement('div'));
		olay.setAttribute('id',overlayID);
		olay.setStyle({opacity:0.3,position:'absolute',zIndex:zindex,width:myWidth+'px',height:myHeight+'px',backgroundColor:'black',top:'0px',left:'0px'});
		document.body.appendChild(olay);
		
		var box = $(document.createElement('div'));
		box.setAttribute('id',boxID);
		box.setStyle({position:'absolute',zIndex:zindex+1,width:boxWidth,height:boxHeight,backgroundColor:'white',top:'0px',left:'0px'});
		document.body.appendChild(box);
		boxOverlayArray.push({box:boxID,overlay:overlayID,zi:zindex})
		
		if (boxStyle) {
			box.setStyle(boxStyle);
		}
		if (content) {
			box.innerHTML = content;
		} else {
			box.innerHTML = format;
		}
		
		test2 = function() {var position = this.maintPos();this.boxCenter();}.bind(this);
		Event.observe(window, 'scroll', test2);
		
		this.boxCenter();
		this.maintPos();
	}
	this.boxCenter = function() {
		var elem;
		var emSize = 0;
		var elm_x,elm_y = 0;
		var scrollPos = getScrollPos();
		var	pageSize = getPageSize();
		for(var x = 0; x < boxOverlayArray.length;x++){
			elem = $(boxOverlayArray[x].box);
			//if (!elem) {Event.stopObserving(window,'scroll',test2);alert('doesnt exist');}
			emSize = getElementSize(elem);
			elm_x = eval(Math.round(pageSize.width/2) - (emSize.width /2) + scrollPos.scroll_x);
			elm_y = eval(Math.round(pageSize.height/2) - (emSize.height /2) + scrollPos.scroll_y);
			elem.style.left = elm_x+'px';
			elem.style.top = elm_y+'px';
		}
	}
	this.maintPos = function() {
		for(var x = 0; x < boxOverlayArray.length;x++){
			var scrollYoffset = getScrollHeight();
			var scrollXoffset = getScrollWidth();
			var w = screenSize('width')+scrollXoffset-getScrollerWidth();
			var h = screenSize('height')+scrollYoffset;
			$(boxOverlayArray[x].overlay).style.width = w+"px";
			$(boxOverlayArray[x].overlay).style.height = h+"px";
		}
	}
}

function getScrollerWidth() {
	var scr = null;
	var inn = null;
	var wNoScroll = 0;
	var wScroll = 0;

	// Outer scrolling div
	scr = document.createElement('div');
	scr.style.position = 'absolute';
	scr.style.top = '-1000px';
	scr.style.left = '-1000px';
	scr.style.width = '100px';
	scr.style.height = '50px';
	// Start with no scrollbar
	scr.style.overflow = 'hidden';

	// Inner content div
	inn = document.createElement('div');
	inn.style.width = '100%';
	inn.style.height = '200px';

	// Put the inner div in the scrolling div
	scr.appendChild(inn);
	// Append the scrolling div to the doc
	document.body.appendChild(scr);

	// Width of the inner div sans scrollbar
	wNoScroll = inn.offsetWidth;
	// Add the scrollbar
	scr.style.overflow = 'auto';
	// Width of the inner div width scrollbar
	wScroll = inn.offsetWidth;

	// Remove the scrolling div from the doc
	document.body.removeChild(
		document.body.lastChild);

	// Pixel width of the scroller
	return (wNoScroll - wScroll);
}
removeOverlay = function() {
	document.body.removeChild($(boxOverlayArray[boxOverlayArray.length-1].box));
	document.body.removeChild($(boxOverlayArray[boxOverlayArray.length-1].overlay));
	boxOverlayArray.pop();
			
}
getScrollHeight = function() {
   var h = window.pageYOffset ||
		   document.body.scrollTop ||
		   document.documentElement.scrollTop;
		   
   return h ? h : 0;
}
getScrollWidth = function() {
   var w = window.pageXOffset ||
		   document.body.scrollLeft ||
		   document.documentElement.scrollLeft;
		   
   return w ? w : 0;
} 
getElementSize = function(elem) {
	var w = elem.offsetWidth ||  elem.style.pixelWidth;
	var h = elem.offsetHeight || elem.style.pixelHeight;
	return {'width':w,'height':h}
}
getScrollPos = function() {
	var docElem = document.documentElement;
	var scrollX = self.pageXOffset || (docElem&&docElem.scrollLeft) || document.body.scrollLeft;
	var scrollY = self.pageYOffset || (docElem&&docElem.scrollTop) || document.body.scrollTop;
	return {scroll_x:scrollX,scroll_y:scrollY}
}

getPageSize = function() {
	var docElem = document.documentElement
	var width = self.innerWidth || (docElem&&docElem.clientWidth) || document.body.clientWidth;
	var height = self.innerHeight || (docElem&&docElem.clientHeight) || document.body.clientHeight;
	return {'width':width,'height':height}
}
function screenSize(what) {
	var myWidth = 0, myHeight = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	if (what == "width") {
		return myWidth;
	} else {
		return myHeight;
	}
}
welcomeVideo = function() {
	var createBox = new boxOverlay({
		width:'612px',
		height:'235px',
		content:'<img src="images/2010brochure_msg.jpg" style="cursor:pointer;" onclick="removeOverlay();">'
		//content:'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="436" id="welcome" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="welcome.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="welcome.swf" quality="high" bgcolor="#ffffff" width="600" height="436" name="welcome" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>',
		//style:{border:'4px solid #999',backgroundColor:'white'}
	});
	createBox.init();
}
function closeWelcomeVideo() {
	removeOverlay();
}
