function popthing(popID, shadowID){
	// default values
	var _self = this;
	this.shadowID = shadowID;
	this.popID = popID;
	var fading = false;
	var fadingEnabled = false;	
	var fadeType = 'in';
	var popOpacity = 100;
	var shadowOpacity = 100;
	var scrollX_old = 0;
	var scrollY_old = 0;
	var popCtrlBar = false;
	var closeButton1 = "/graphics/nav/close1.jpg";
	var closeButton2 = "/graphics/nav/close2.jpg";
	var progressImg = new Image();
	progressImg.src="/graphics/loading/wait30trans.gif"	
	if (popCtrlBar) {
		var closeButtonWidth = 20;
		var closeButtonHeight = 20;
	}
	else {
		var closeButtonWidth = 0;
		var closeButtonHeight = 0;
	}
	var popOffset = [0, 0];
	var flashPlayer = "player2.swf";
	var shadowOpacityMax = 75;
	var popFadeRate = 1;
	var popFadeInc = 75;
	var hasInnerContent = false;
	var activeInnerContent = null;
	var shadowOffset = 0;
	var allowToggle = true;
	var highestZ = 0;
	var dragging = false;
	var oldmouseX = 0;
	var oldmouseY = 0;
	var keyboardMove = false;
	
	this.togglePop = togglePop;
	this.showPop_DIV = showPop_DIV;
	this.loadPop_DIV = loadPop_DIV;
	this.loadPop_IMG = loadPop_IMG;
	this.loadPop_SWF = loadPop_SWF;
	this.loadPop_QT = loadPop_QT;
	this.addPopOffset = addPopOffset;
	this.fade = fade;
	this.init = init;
	this.setOpacity = setOpacity;
	this.setupPop = setupPop;
	this.setCss = setCss;
	this.setDepth = setDepth;
	this.addHtml = addHtml;
	this.toggleEnabled = toggleEnabled;
	this.showProgress = showProgress;	
	this.center = centerPopup;
	this.clear = clearPopup;
		
	function centerPopup() {
		centerDiv(popID);
	}
		
	function movePopup (e) { 
		if((e)&&(keyboardMove)) {
			var div = document.getElementById(popID);	
			if (e.keyCode)
				e = e.keyCode;
			else 
				e = e.charCode;
			if ((e > 36) && (e < 41)) {
				var left = parseInt(div.style.left);
				var top = parseInt(div.style.top);
				switch (e) {
					case 37:
						left -= 2;
						break;
					case 38:
						top -= 2;
						break;
					case 39:
						left += 2;
						break;
					case 40:
						top += 2;
						break;
				}
				div.style.left = left +'px';
				div.style.top = top + 'px';
			}
		} 
	}
	
	function getNextHighestZindex(obj){
		var highestIndex = 0;
		var currentIndex = 0;
		var elArray = Array();
		if (obj) {
			elArray = document.getElementsByTagName(obj);
		}
		else {
			elArray = document.getElementsByTagName('*');
		}
		for (var i = 0; i < elArray.length; i++) {
			if (elArray[i].currentStyle) {
				currentIndex = parseFloat(elArray[i].currentStyle['zIndex']);
			}
			else 
				if (window.getComputedStyle) {
					currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i], null).getPropertyValue('z-index'));
				}
			if (!isNaN(currentIndex) && currentIndex > highestIndex) {
				highestIndex = currentIndex;
			}
		}
		return (highestIndex + 1);
	}
	
	function toggleEnabled(bool) {
		allowToggle = bool;
	}
	
	function addHtml(html) {
		document.getElementById(popID).innerHTML += html; 
	}
	
	function setStyle(objId, style, value) {
    	document.getElementById(objId).style[style] = value;
	}

	
	function getHeight(){
		var d = document.getElementById(popID);
		var divHeight;
		if (d.offsetHeight) {
			divHeight = d.offsetHeight;
		}
		else 
			if (d.style.pixelHeight) {
				divHeight = d.style.pixelHeight;
			}
		
		return divHeight;
	}
	
	function getWidth(){
		var d = document.getElementById(popID);
		var divWidth;
		if (d.offsetWidth) {
			divWidth = d.offsetWidth;
		}
		else 
			if (d.style.pixelWidth) {
				divWidth = d.style.pixelWidth;
			}
		
		return divWidth;
	}
	
	function getWindowHeight(){
		var windowHeight = 0;
		
		if (typeof(window.innerHeight) == 'number') {
			windowHeight = window.innerHeight;
		}
		
		else {
			if (document.documentElement && document.documentElement.clientHeight) {
				windowHeight = document.documentElement.clientHeight;
			}
			else {
				if (document.body && document.body.clientHeight) {
					windowHeight = document.body.clientHeight;
				}
			}
		}
		return windowHeight;
	}
	
	function getWindowWidth (){
		var windowWidth = 0;
		
		if (typeof(window.innerWidth) == 'number') {
			windowWidth = window.innerWidth;
		}
		
		else {
			if (document.documentElement && document.documentElement.clientWidth) {
				windowWidth = document.documentElement.clientWidth;
			}
			else {
				if (document.body && document.body.clientWidth) {
					windowWidth = document.body.clientWidth;
				}
			}
		}
		return windowWidth;
	}
	
	
	function centerDiv (id){
		var div = document.getElementById(id);
		var top = (getWindowHeight() - div.offsetHeight) / 2;
		if (id == shadowID) {
			var left = 0;
		}
		else 
			var left = (getWindowWidth() - div.offsetWidth) / 2; 
		var xy = getScrollXY();
		
		div.style.left = left + xy[0] + "px";
		div.style.top = top + xy[1] + "px";
	}	
	
	function getScrollXY (){
		var scrOfX = 0, scrOfY = 0;
		if (typeof(window.pageYOffset) == 'number') {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		}
		else 
			if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
				//DOM compliant
				scrOfY = document.body.scrollTop;
				scrOfX = document.body.scrollLeft;
			}
			else 
				if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
					//IE6 standards compliant mode
					scrOfY = document.documentElement.scrollTop;
					scrOfX = document.documentElement.scrollLeft;
				}
		return [scrOfX, scrOfY];
	}
	
	// prevents the user from scrolling while the popup is visible
	function preventScroll (){ 
	//	var h = getHeight() - getWindowHeight();
	//	if(h<0)
			window.scrollTo(scrollX_old, scrollY_old);
	}
	
	// fades in and out depending on what the global var 'fadeType' has been set to
	function fade (){
		switch (fadeType) {
			case 'in':
				if (shadowOpacity < shadowOpacityMax) {
					shadowOpacity += popFadeInc;
				}
				if (popOpacity < 100) {
					popOpacity += popFadeInc;
					setOpacity(popID)
				}
				else {
					fading = false;
				}
				break;
			case 'out':
				if (shadowOpacity > 0) {
					shadowOpacity -= popFadeInc;
				}
				if (popOpacity > 0) {
					popOpacity -= popFadeInc;
					setOpacity(popID)
				}
				else {
					fading = false;
				}
				break;
		}
		if (fading) {
			setTimeout(_self.fade, popFadeRate);
		}
		
	}
	
	//sets the opacity of the popup and shadow using the global opacity vars (popupOpacity & shadowOpacity)
	function setOpacity (){
		var div1 = document.getElementById(popID);
		var div2 = document.getElementById(shadowID);
		div1.style.opacity = popOpacity / 100;
		div1.style.filter = 'alpha(opacity=' + popOpacity + ')';
		div2.style.opacity = shadowOpacity / 100;
		div2.style.display = 'block'; // shouldn't really be here but couldn't get it to work otherwise
		div2.style.filter = 'alpha(opacity=' + shadowOpacity + ')';
		if ((div1.style.opacity == 0) || (div1.style.filter == "alpha(opacity=0)") || (div1.style.filter == "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)")) {
			div1.style.display = div2.style.display = 'none';
			div1.style.zIndex = div2.style.zIndex = 0;
			if (!hasInnerContent) {
				div1.innerHTML = "";
			}
			window.onscroll = null;
		}
		
	}
	
	// hides the popup and removes all its content
	function clearPopup() {
		var div = document.getElementById(popID);
		var shadow = document.getElementById(shadowID);	
		div.style.display = 'none';
		shadow.style.display = 'none';
		div.innerHTML = '';
	}
	
	// toggles the popup on when the link is clicked and off when the popup is clicked
	// initiates the fading
	function togglePop(){
		if(!allowToggle) return 0;			
		
		window.onscroll = preventScroll;
		
		var xy = getScrollXY();
		scrollX_old = xy[0];
		scrollY_old = xy[1];
		
		var div = document.getElementById(popID);
		var shadow = document.getElementById(shadowID);	
		if (!highestZ) {
			highestZ = getNextHighestZindex('div');
		}
		shadow.style.zIndex = highestZ;
		div.style.zIndex = highestZ + 1;
		
		
		if (div.style.display == 'block') {
			if (fadingEnabled) {
				fadeType = 'out';
				fading = true;
			}
			else {
				div.style.display = 'none';
				shadow.style.display = 'none';
				if(!hasInnerContent) div.innerHTML = '';
				window.onscroll = null;
				shadow.style.zIndex = div.style.zIndex = 0;
			}
		}
		else {
			div.style.display = 'block';
			if (fadingEnabled) {
				fadeType = 'in';
				fading = true;
			}
			else {
				shadow.style.display = 'block';
			}
		}
		
		if (hasInnerContent) {
			var e = document.getElementById(activeInnerContent);
			if (e) {
				if (e.style.display == 'block') {
					e.style.display = 'none';
					activeInnerContent = null;
				}
				else {
					e.style.display = 'block';
				}
			}
		}
		
		if (fadingEnabled) fade();
		centerDiv(popID);
		centerDiv(shadowID);
		addPopOffset();
	}
	
	// loads the content from another div into the popup
	// the div should be defined at the start of the html body and its display should be set to 'none'
	function loadPop_DIV (contentID, title){
		var div1 = document.getElementById(popID);
		var div2 = document.getElementById(contentID);
		div1.innerHTML = "";
		if (popCtrlBar) {
			div1.innerHTML = "<div id=\"popCtrlBar\"><div align=\"left\">" + title + "</div><div style=\"text-align:right; width:" + closeButtonWidth + "px\"><img style=\"cursor:pointer\" onclick=\"document.getElementById('" + popID + "').innerHTML=''; _self.togglePop()\" align=\"right\" src=\"" + closeButton1 + "\" width=\"" + closeButtonWidth + "\" height=\"" + closeButtonHeight + "\" onmouseover=\"this.src='" + closeButton2 + "'\" onmouseout=\"this.src='" + closeButton1 + "'\"></div></div>";
		}
		div1.innerHTML += "<div id=\"popInnerContent\">" + div2.innerHTML + "</div>";
		
		togglePop();
	}
	
	function showPop_DIV (contentID, title){
		hasInnerContent = true;
		activeInnerContent = contentID;
		togglePop();		
	}
	
	function loadPop_IMG (mylink, title){		
		var div1 = document.getElementById(popID);
		div1.innerHTML = "";
		if (popCtrlBar) {
			div1.innerHTML = "<div id=\"popCtrlBar\"><div style=\"float:left;\">" + title + "</div><div style=\"float:right; width:" + closeButtonWidth + "px\"><img style=\"cursor:pointer\" onclick=\"document.getElementById('" + popID + "').innerHTML=''; _self.togglePop()\" align=\"right\" src=\"" + closeButton1 + "\" width=\"" + closeButtonWidth + "\" height=\"" + closeButtonHeight + "\" onmouseover=\"this.src='" + closeButton2 + "'\" onmouseout=\"this.src='" + closeButton1 + "'\"></div></div>";
		}
		div1.innerHTML += "<div align=\"center\"><img src=\"" + mylink + "\" border=\"0\"></div>";
		
		togglePop();
	}
	
	function loadPop_SWF (width, height, mylink, title){		
		var div1 = document.getElementById(popID);
		div1.innerHTML = "";
		if(!width) width = 320;
		if(!height) height = 200;

		if (popCtrlBar) {
			div1.innerHTML = "<div id=\"popCtrlBar\"><div style=\"float:left;\">" + title + "</div><div style=\"float:right; width:" + closeButtonWidth + "px\"><img style=\"cursor:pointer\" onclick=\"document.getElementById('" + popID + "').innerHTML=''; _self.togglePop()\" align=\"right\" src=\"" + closeButton1 + "\" width=\"" + closeButtonWidth + "\" height=\"" + closeButtonHeight + "\" onmouseover=\"this.src='" + closeButton2 + "'\" onmouseout=\"this.src='" + closeButton1 + "'\"></div></div>";
		}
		div1.innerHTML += "<center><div id=\"flv_player\" style=\"margin:auto 0; margin-top:" + closeButtonHeight + "px; z-index:20; position:relative;width:"+width+"; height:"+height+";\" align=\"center\"><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" viewastext=\"\" id=\"Object1\" height=\"" + height + "\" width=\"" + width + "\"><param name=\"movie\" value=\"" + flashPlayer + "?src=" + mylink + "\"><param name=\"quality\" value=\"high\" /><embed src=\"" + flashPlayer + "?fname=" + mylink + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" height=\"" + height + "\" width=\"" + width + "\"></embed></object></div></center>";
		togglePop();
	}
	
	function loadPop_QT (width, height, mylink, title){
		var div1 = document.getElementById(popID);
		div1.innerHTML = "";
		if(!width) width = 320;
		if(!height) height = 200;
		
		if (popCtrlBar) {
			div1.innerHTML = "<div id=\"popCtrlBar\"><div style=\"float:left;\">" + title + "</div><div style=\"float:right; width:" + closeButtonWidth + "px\"><img style=\"cursor:pointer\" onclick=\"document.getElementById('" + popID + "').innerHTML=''; _self.togglePop()\" align=\"right\" src=\"" + closeButton1 + "\" width=\"" + closeButtonWidth + "\" height=\"" + closeButtonHeight + "\" onmouseover=\"this.src='" + closeButton2 + "'\" onmouseout=\"this.src='" + closeButton1 + "'\"></div></div>";
		}
		div1.innerHTML += "<center><div style=\"margin:auto 0; margin-top:" + closeButtonHeight + "px; z-index:20; position:relative;\" align=\"center\"><embed src=\"" + mylink + "\" width=\"" + width + "\" height=\"" + height + "\" align=\"absmiddle\"></embed></div></center>";
		
		togglePop();
	}
	
	// redefines the popup's width, height, background, border and padding so that it can be used with different content 
	// would be nice if the width and height could be set automatically in relation to the content dimensions
	function setupPop (w, h, bgCol, b, p){
		var div = document.getElementById(popID)
		div.style.width = w;
		div.style.height = h;
		div.style.background = bgCol;
		div.style.border = b;
		div.style.padding = p;
		div.style.overflow = 'hidden';
	}
	
	function setShadow (){
		var shadow = document.getElementById(shadowID);
		var height = '100%';
		var width = '100%';	
		shadow.onclick = togglePop;
		if (!fadingEnabled) {
			shadow.style.opacity = shadowOpacityMax/100;
			shadow.style.filter = 'alpha(opacity='+shadowOpacityMax+')';
		}
	}
	
	function init() {		
		setShadow();
		var div1 = document.getElementById(popID);
		var div2 = document.getElementById(shadowID);
		if(fadingEnabled) {
			div1.className = 'popup';
			div2.className = 'shadow';		
			div1.style.opacity = div2.style.opacity= 0;
			div1.style.filter = div2.style.filter = 'alpha(opacity=0)';
		}	
		document.onkeypress = movePopup;		
		div1.onmousedown = dragPopup;	
		div1.onmouseup = function (){
			document.getElementById(popID).onmousemove = null;
			dragging = false;
		}
	}
	
	function dragPopup(mouseEvent){
		if (!mouseEvent) var mouseEvent = window.event;
		var tg = (window.event) ? mouseEvent.srcElement : mouseEvent.target; 
		if(tg.className == 'nodrag') return false;
		if ((tg.nodeName == 'INPUT')||(tg.nodeName == 'SELECT')||(tg.nodeName == 'TEXTAREA')||(tg.nodeName == 'IMG'))	return 0;

		dragging = true;
		if (mouseEvent.offsetX || mouseEvent.offsetY) { //For Internet Explorer
			x = mouseEvent.offsetX;
			y = mouseEvent.offsetY;
		}
		else { //For FireFox
			x = mouseEvent.pageX;
			y = mouseEvent.pageY;
		}
		oldmouseX = x;
		oldmouseY = y;
		document.getElementById(popID).onmousemove = startDrag;
	}
	
	function startDrag(e) {
		 if (dragging) {
		 	if (e.offsetX || e.offsetY) { //For Internet Explorer
					x = e.offsetX;
					y = e.offsetY;
				}
				else { //For FireFox
					x = e.pageX;
					y = e.pageY;
				}						
				
				var incX = x - oldmouseX;
				var incY = y - oldmouseY;			
				
				oldmouseX = x;
				oldmouseY = y;
				
				var newY = parseInt(document.getElementById(popID).style.top) + incY;
				var newX = parseInt(document.getElementById(popID).style.left) + incX;
				
				document.getElementById(popID).style.top = newY + 'px'; //
				document.getElementById(popID).style.left = newX + 'px'; //				
			}
	}
	
	function addPopOffset(){
		var div = document.getElementById(popID)
		div.style.left = div.offsetLeft + popOffset[0] + "px";
		div.style.top = div.offsetTop + popOffset[1] + "px";
	}
	
	function setPlayer (p){
		flashPlayer = p;
	}
	
	function setCss() {
		var e = document.getElementById(popID);	
		e.style.zIndex = 100;
		e.style.backgroundColor = 'white';
		e.style.position = 'absolute';
		e.style.top = '0px';
		e.style.left = '0px';
		e.style.display = 'none';
		e.style.fontFamily = 'Arial, san-serif';
		e.style.margin = '0 auto';
		e.style.overflow = 'hidden';
		e.style.border = '5px solid #999';
		e.style.padding = '7px';
		e.style.mozBorderRadius = '15px';	
		e.style.webkitBorderRadius = '15px';	
		e.style.OperaBorderRadius = '15px';
		e.style.KhtmlBorderRadius = '15px';
		e.style.borderRadius = '15px';
		e.style.behavior = 'url(border-radius.htc)'; 
		
		var s = document.getElementById(shadowID);	
		s.style.backgroundColor = 'black';
		s.style.width = '100%';
		s.style.height = '100%';
		s.style.position = 'absolute';
		s.style.zIndex = 50;
		s.style.display = 'none';
		s.style.top = '0px';
		s.style.left = '0px';		
	}
	
	function setDepth(i) {
		/*var e = document.getElementById(popID);	
		e.style.zIndex = i*100;
		var s = document.getElementById(shadowID);	
		s.style.zIndex = parseInt(e.style.zIndex)-1;*/
	}
	
	function showProgress(i){
		if(hasInnerContent) return 0; 
		if (i) {
			var e = document.getElementById(popID);			
			e.innerHTML = '<div id="progressWheel" style="padding:10px;"><img src="/graphics/loading/wait30trans.gif" align="center"></div>';
			togglePop();
			allowToggle = false;
		}
		else {
			allowToggle = true;
			togglePop();
		}
	}
		
}