/* 
	global objects
*/
window.APAIT = new APAIT();


/* 
	Wrapper object
*/
function APAIT() {
	
	var that = this;
	
	this.LightboxDialog = new LightboxDialog();
	
	function LightboxDialog() { 
		
		var that = this;
		
		this.getPageWidth = function getPageWidth() {
			var pageWidth = -1;
			if( document.body.clientWidth ) { // Firefox 
				pageWidth = document.body.clientWidth;
			}
			else if( document.body.scrollWidth > document.body.scrollWidth ) { // all but Explorer Mac 
				pageWidth = document.body.scrollWidth;
			}
			else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari 
				pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
			}
			if (window.innerWidth && window.innerWidth > pageWidth) {
				pageWidth = window.innerWidth; 
			}
			return pageWidth;
		}
		
		this.getPageHeight = function getPageHeight() {
		  var pageHeight = -1;
			if( window.innerHeight && window.scrollMaxY ) { // Firefox 
				pageHeight = window.innerHeight + window.scrollMaxY;
			}
			else if( document.body.scrollHeight > document.body.offsetHeight ) { // all but Explorer Mac 
				pageHeight = document.body.scrollHeight;
			}
			else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari 
				pageHeight = document.body.offsetHeight + document.body.offsetTop; 
			}
			if (window.innerHeight && window.innerHeight > pageHeight) {
				pageHeight = window.innerHeight; 
			}
			return pageHeight;
		}
		
		this.getScrollPos = function getScrollPos() {
			var scrollPos = 0;
			if (window.pageYOffset && window.pageYOffset > 0) { // IE  
				scrollPos = window.pageYOffset;
			} else if (document.documentElement.scrollTop && document.documentElement.scrollTop > 0) { 
	 		  scrollPos = document.documentElement.scrollTop;
			} else {
				scrollPos = document.body.scrollTop;
			}
			return scrollPos;
		}
		
		this.getElemWidth = function getElemWidth(elem) {
			return elem.offsetWidth;
		}

		this.getElemHeight = function getElemHeight(elem) {
			return elem.offsetHeight;
		}
		
		this.getWindowHeight = function getWindowHeight() {
		  var myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    myHeight = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    myHeight = document.body.clientHeight;
		  }
		  return myHeight;
		}
		
		this.overlay = function overlay(dialogId, overlayId) {
			
			var overlayDiv = document.getElementById("overlay");
			
			if(overlayId != null)
				{
				overlayDiv = document.getElementById(overlayId);
				}
			
			var dialogDiv = document.getElementById(dialogId);
			
			overlayDiv.style.display = (overlayDiv.style.display == "block") ? "none" : "block";
			dialogDiv.style.display = (dialogDiv.style.display == "block") ? "none" : "block";
			
			if (overlayDiv.style.display == "block") {
				
				/* overlayDiv.setAttribute("onClick","APAIT.LightboxDialog.overlay('"+dialogId+"')"); */
				/* this works in IE6 too ! */
				overlayDiv.onclick = function () {APAIT.LightboxDialog.overlay(dialogId, overlayDiv.id);}

				overlayDiv.style.width = this.getPageWidth() + "px";
				overlayDiv.style.height = this.getPageHeight() + "px";

				var scrollPos = this.getScrollPos();	
				var topPos = (this.getWindowHeight() - this.getElemHeight(dialogDiv))/2;
				
				dialogDiv.style.top = (scrollPos + topPos) + "px";
				dialogDiv.style.left = ((this.getPageWidth()  - this.getElemWidth(dialogDiv)) / 2) + "px";
			} 
			
			// this.bugfixIE6(overlayDiv.style.visibility, "selectXY");
						
		}

		/*
		this.bugfixIE6 = function bugfixIE6(visibility, selectElemId) {
			// bugfix IE6 for drowdowns
			var selectElem = document.getElementById(selectElemId);
		
			if(document.all) {
				if (visibility == "visible") {
					// hide dropdowns
					if (selectElem != null) {
						selectElem.style.display='none';
					}
				} else {
					// show dropdowns
					if (selectElem != null) {
						selectElem.style.display='block';
					}
				}	
			}
		}

		*/


  }	// END LightboxDialog
	
	return true;
}

