// JavaScript Document
// sliding panel class

function PanelObj(params) {

	// string takes the form of param:value;param:value;...
	this.params = params.replace(/\s/g,'');
	var tmpPairArray = params.split(";");
	this.paramsArray = new Array();
	for (var i=0; i<(tmpPairArray.length); i++) {
		var pair = tmpPairArray[i].split(":");
		this.paramsArray[pair[0]] = pair[1];
	}

	this.createCookie = function (name,value,hours) {
		if (hours!='') {
			var date = new Date();
			date.setTime(date.getTime()+(hours*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		} else { var expires = ""; }
		document.cookie = name+"="+value+expires+"; path=/";
	}

	this.readCookie =  function (name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') { c = c.substring(1,c.length); }
			if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length,c.length); }
		}
		return null;
	}

	this.eraseCookie = function (name) { createCookie(name,"",-1); }

	// CLASS INITS of behaviors and the like
	this.className = this.paramsArray['className'];
	this.panelName = this.paramsArray['panelName'];
	this.stepDivider = 50; // more divisions, the smoother the action. fewer is faster.
	this.stepIncrements = 1; // the absolute size (px) of each step in the transition
	this.transMethod = this.paramsArray['transMethod']; // 'divider' or 'increment'
	this.steppingMethod = this.paramsArray['steppingMethod'];
	this.distToMove;
	this.stopAt = 0;
	this.panelSizeX = this.paramsArray['panelX'];
	this.panelX;
	this.panelX_orig;
	this.panelSizeY = this.paramsArray['panelY'];
	this.panelY;
	this.panelY_orig;
	this.paneWidth = this.panelX;
	this.displayBlocks = Array();
	this.panelIndex = 1; // there are 2 sliding panels
	this.panelIndexPrior = -1;
	this.displayBlockIndex = 0;
	this.panelTimer;
	this.panelState = 'init';
	this.firstPassToday = true;
	this.lookingForFirstPanel = true;  // on reloads, no-repeat panels are skipped!
	this.showDebug = false;

	// see if we have a panel cookie setup
	var panelCookie = this.readCookie('nldzPanelState');
	this.firstPassToday = (panelCookie!='no-intro');

	// FINAL INITS of a few things we'll need later
	this.canStopNow = false;
	this.panelPane = document.getElementById(this.panelName+'_pane');
	this.panelPane.style.width = this.panelSizeX+'px';
	this.panelPane.style.height = this.panelSizeY+'px';

	// setup REVEAL panel 1
	this.panelObj  = document.getElementById(this.panelName+'_reveal1');
	this.panelObj.style.width = this.panelSizeX+'px';
	this.panelObj.style.height = this.panelSizeY+'px';
	this.panelObj.style.left = this.panelSizeX+'px';
	this.panelObj.style.top = (-this.panelSizeX)+'px';

	// setup SLIDE panel 1
	this.panelObj  = document.getElementById(this.panelName+'_1');
	this.panelObj.style.width = this.panelSizeX+'px';
	this.panelObj.style.height = this.panelSizeY+'px';

	// setup FILTER panel 1
	/*this.panelObj  = document.getElementById(this.panelName+'_filter1');
	this.panelObj.style.width = this.panelSizeX+'px';
	this.panelObj.style.height = this.panelSizeY+'px';
	this.panelObj.style.top = (-this.panelSizeY)+'px';*/

	// setup REVEAL panel 2
	this.panelObj  = document.getElementById(this.panelName+'_reveal2');
	this.panelObj.style.width = this.panelSizeX+'px';
	this.panelObj.style.height = this.panelSizeY+'px';
	this.panelObj.style.top = (-this.panelSizeY)+'px';
	this.panelObj.style.left = this.panelSizeX+'px';

	// setup SLIDE panel 2
	this.panelObj  = document.getElementById(this.panelName+'_2');
	this.panelObj.style.width = this.panelSizeX+'px';
	this.panelObj.style.height = this.panelSizeY+'px';

	// setup FILTER panel 2
	/*this.panelObj  = document.getElementById(this.panelName+'_filter2');
	this.panelObj.style.width = this.panelSizeX+'px';
	this.panelObj.style.height = this.panelSizeY+'px';
	this.panelObj.style.top = (-this.panelSizeY)+'px';*/

	// the REVEAL transitions require a slightly different initial setup
	switch (this.transMethod) {
		case 'reveal-left':
			// setup REVEAL panel 1
			this.panelObj  = document.getElementById(this.panelName+'_reveal1');
			this.panelObj.style.left = '0px';
			this.panelObj.style.top = '0px';
			break;
	}


	d=document;
	this.agt=navigator.userAgent.toLowerCase();
	this.major=parseInt(navigator.appVersion);
	this.dom=(d.getElementById);
	this.ns=(d.layers);
	this.ns4up=(this.ns && this.major>=4);
	this.ns6=(this.dom&&navigator.appName=="Netscape");
	this.op=(window.opera);
	if(d.all)this.ie=1;else this.ie=0;
	this.ie4=(d.all&&!this.dom);
	this.ie4up=(this.ie&&this.major>=4);
	this.ie5=(d.all&&this.dom);
	this.ie6=(d.nodeType);
	this.sf=(this.agt.indexOf("safari")!=-1);
	this.win=((this.agt.indexOf("win")!=-1)||(this.agt.indexOf("16bit")!=-1));
	this.winme=(this.agt.indexOf("win 9x 4.90")!=-1);
	this.xpsp2=(this.agt.indexOf("sv1")!=-1);
	this.mac=(this.agt.indexOf("mac")!=-1);

	this.getHorzMoveByMethod = function(dir) {
		this.softLanding = 2; // higher values make a harder/faster landing. zero is softest
		if (this.steppingMethod=='divider') {
			return Math.ceil( Math.abs(this.panelX) / this.stepDivider ) + this.softLanding;
		} else {
			return this.stepIncrements;
		}
	}

	this.getVertMoveByMethod = function(dir) {
		if (this.steppingMethod=='divider') {
			var softLanding = 0; // higher values make a harder/faster landing. zero is softest
			return Math.ceil( this.panelY / this.stepDivider ) + softLanding;
		} else {
			return this.stepIncrements;
		}
	}

	this.adjustFilter = function(objRef,alpha) {
		// scale is always a float between 0 and 1...
		if (typeof(objRef)=='object') { var filterDiv = objRef; } else { var filterDiv = document.getElementById(objRef); }
		filterDiv.style['-moz-opacity']=alpha;
		filterDiv.style.opacity=alpha;
		if (this.ie5) {
			//alert('filtAlpha: '+filterDiv.style.filter);
			filterDiv.style.filter='alpha(opacity='+Math.floor(alpha*100)+')';
			//alert('filtAlpha: '+filterDiv.style.filter);
		}
	}

	this.addDisplayBlock = function (panelSource,duration,repeat){
		var OKtoAdd = (repeat=='ok-repeat' || (repeat=='no-repeat' && this.firstPassToday) );
		if (OKtoAdd) {
			var count = this.displayBlocks.length;
			this.displayBlocks[count] =  new Array;
			this.displayBlocks[count]['src'] = panelSource;
			this.displayBlocks[count]['duration'] = duration;
			this.displayBlocks[count]['repeat'] = repeat;
			if (this.lookingForFirstPanel) {
				// setup first panelthis.revealObj  = document.getElementById(this.panelName+'_reveal'+this.panelIndex);
				this.revealObj  = document.getElementById(this.panelName+'_reveal1');
				//this.filterObj  = document.getElementById(this.panelName+'_filter1');
				this.panelObj  = document.getElementById(this.panelName+'_1');
				this.panelObj.innerHTML = this.displayBlocks[count]['src'];
				this.panelObj.duration = this.displayBlocks[count]['duration'];
				this.panelObj.style.visibility = 'visible';
				//this.filterObj.style.visibility = 'hidden';
				this.revealObj.style.zIndex = 10;  // background this now
				this.panelObj.style.zIndex = 15;
				//this.filterObj.style.zIndex = 20;
				this.panelObj.style.left = '0px';
				this.panelObj.style.top = '0px';
				this.revealObj.style.top = '0px';
				this.revealObj.style.left = '0px';

				this.panelIndex++; // ready for next pane
				this.displayBlockIndex++; // ready for next panel
				this.lookingForFirstPanel = false;
			}
		}
	}

	this.setPanelStatus = function(theStatus) {
		this.panelState = theStatus;
		switch (theStatus) {
		case 'paused':
			document.getElementById(this.panelName+'_status').innerHTML = '<img src="http://70.85.21.116/~nativela/images/slides/toolbar_paused.gif" width="50" height="14" border="0">';
			break;
		default:
			document.getElementById(this.panelName+'_status').innerHTML = '';
		}
	}

	this.run =  function(initDelay,pauseDelay) {
		// start cycle
		this.pauseDelay = pauseDelay;
		if (!this.testingMode) { this.pauseTimer = setTimeout(this.className+'.pullPanel()',initDelay*1000); }
		this.setPanelStatus('ready')

		if (this.showDebug) { this.debug(); }

	}

	this.nextPanel = function() {
		if (this.panelState=='transitioning') {
			this.setPanelStatus('goNextAfter');
		} else {
			clearTimeout(this.pauseTimer);
			this.pullPanel();
		}

		if (this.showDebug) { this.debug(); }
	}

	this.pausePanel = function() {
		clearTimeout(this.pauseTimer);
		if (this.panelState=='transitioning') {
			this.setPanelStatus('pauseAfter');
		} else { this.setPanelStatus('paused'); }

		if (this.showDebug) { this.debug(); }
	}

	this.resumePanel = function() {
		//clearTimeout(this.pauseTimer);
		if (!this.testingMode) { this.pauseTimer = setTimeout(this.className+'.pullPanel()',1*1000); } // pull another in 1 sec
		this.setPanelStatus('ready')


		if (this.showDebug) { this.debug(); }
	}

	this.prevPanel = function() {
		if (this.panelState=='transitioning') {
			this.setPanelStatus('goPrevAfter');
		} else {
			clearTimeout(this.pauseTimer);
			// have to decrement-and-test TWICE because the index was previously set to point AHEAD
			this.displayBlockIndex--;
			if (this.displayBlockIndex < 0) {
				this.displayBlockIndex = this.displayBlocks.length - 1;
			}
			this.displayBlockIndex--;
			if (this.displayBlockIndex < 0) {
				this.displayBlockIndex = this.displayBlocks.length - 1;
			}
			this.pullPanel();
		}
	}

	this.pullPanel = function () {
		this.setPanelStatus('transitioning')
		// we use this obj definition through the entire current sequence
		this.revealObj  = document.getElementById(this.panelName+'_reveal'+this.panelIndex);
		//this.filterObj  = document.getElementById(this.panelName+'_filter'+this.panelIndex);
		this.panelObj  = document.getElementById(this.panelName+'_'+this.panelIndex);
		if (!this.firstPassToday) {
			while (this.displayBlocks[this.displayBlockIndex]['repeat']=='no-repeat' ) {
				this.displayBlockIndex++;
				if (this.displayBlockIndex >= this.displayBlocks.length) { this.displayBlockIndex = 0; }
			}
		}
		this.panelObj.innerHTML = this.displayBlocks[this.displayBlockIndex]['src'];
		this.panelObj.duration = this.displayBlocks[this.displayBlockIndex]['duration'];
		this.panelObj.style.visibility = 'visible';
		//this.filterObj.style.visibility = 'hidden';
		this.revealObj.style.zIndex = 100;
		this.panelObj.style.zIndex = 150;
		//this.filterObj.style.zIndex = 200;
		this.canStopNow = false;

		switch (this.transMethod) {
		case 'x-fade':
			if (this.panelIndex==1) { var tmp = '0px'; } else { var tmp = (-this.panelSizeY)+'px'; }
			this.revealObj.style.top = tmp;
			this.revealObj.style.left = '0px';
			//this.filterObj.style.visibility = 'visible';
			this.panelObj.style.left = '0px';
			this.startFade = 0;
			this.stopFade = 1;
			this.alphaAdj = Math.floor(((this.stopFade - this.startFade) / 10) * 100) / 100; // optimally 10
			this.panelObj.style.opacity = this.startFade;
			this.crossFade();
			break;
		case 'reveal-up':
			this.revealObj.style.left = '0px';
			this.panelObj.style.left = '0px';
			this.revealObj.style.top = this.panelSizeY +'px';
			this.panelY = this.panelSizeY;
			this.vertRevealUp();
			break;
		case 'reveal-left':
			if (this.panelIndex==1) { var tmp = '0px'; } else { var tmp = (-this.panelSizeY)+'px'; }
			this.revealObj.style.top = tmp;
			this.revealObj.style.left = this.panelSizeX+'px';
			this.panelX = this.panelSizeX;
			this.horzRevealLeft();
			break;
		case 'reveal-right':
			if (this.panelIndex==1) { var tmp = '0px'; } else { var tmp = (-this.panelSizeY)+'px'; }
			this.revealObj.style.top = tmp;
			this.revealObj.style.left = -(this.panelSizeX)+'px';
			this.panelX = -(this.panelSizeX);
			this.horzRevealRight();
			break;
		case 'scroll-left':
			if (this.panelIndex==1) { var tmp = '0px'; } else { var tmp = (-this.panelSizeY)+'px'; }
			this.revealObj.style.top = tmp;
			this.revealObj.style.left = this.panelSizeX+'px';
			this.panelX = this.panelSizeX;
			this.horzScrollLeft();
			break;
		case 'wipe-left':
			if (this.panelIndex==1) { var tmp = '0px'; } else { var tmp = (-this.panelSizeY)+'px'; }
			this.revealObj.style.top = tmp;
			this.revealObj.style.left = this.panelSizeX+'px';
			this.panelX = this.panelSizeX;
			this.horzWipeLeft();
			break;
		case 'wipe-up':
			this.panelX = 0;
			this.revealObj.style.left = '0px';
			this.revealObj.style.top = (this.panelSizeY * 2)+'px'; // safe place to start
			this.panelY = this.panelSizeY; // we adjust for panel2 offset later
			this.vertWipeUp();
			break;
		case 'scroll-up':
			this.panelX = 0;
			this.revealObj.style.left = '0px';
			this.revealObj.style.top = (this.panelSizeY * 2)+'px'; // safe place to start
			this.panelY = this.panelSizeY; // we adjust for panel2 offset later
			this.vertScrollUp();
			break;
		}

		if (this.showDebug) { this.debug(); }
	}

	this.crossFade = function () {
		var oldAlpha = this.panelObj.style.opacity * 1;
		var newAlpha =  oldAlpha + this.alphaAdj;

		if (newAlpha>this.stopFade) { newAlpha = this.stopFade; this.canStopNow = true; }
		this.panelObj.style['-moz-opacity']=newAlpha;
		this.panelObj.style.opacity=newAlpha;
		if (this.ie5) {
			this.panelObj.style.filter='alpha(opacity='+Math.floor(newAlpha*100)+')';
		}

		if (this.showDebug) { this.debug(); }

		if (this.canStopNow) { this.resetPanel();
		} else { this.panelTimer = setTimeout(this.className+'.crossFade()',50); } // optimally 50
	}

	this.vertRevealUp = function () {
		this.distToMove = this.getVertMoveByMethod();
		this.newY = this.panelY - this.distToMove;

		if (this.newY >= 0) {
			if (this.panelIndex==1) {
				this.revealObj.style.top = this.newY+'px';
				this.panelObj.style.top = -(this.newY) +'px';
			} else {
				this.revealObj.style.top = (this.newY - this.panelSizeY) +'px';
				this.panelObj.style.top = (-(this.newY) - this.panelSizeY) +'px';
			}
			this.panelY = this.newY;
		} else {
			// oops overshot
			if (this.panelIndex==1) {
				this.revealObj.style.top = '0px';
			} else {
				this.revealObj.style.top = (-this.panelSizeY) +'px';
			}
			this.panelObj.style.top = '0px';
			this.canStopNow = true;
		}

		if (this.showDebug) { this.debug(); }

		if (this.canStopNow) {
			this.resetPanel();
		} else { this.panelTimer = setTimeout(this.className+'.vertRevealUp()',30); }
	}

	this.horzRevealLeft = function () {
		this.distToMove = this.getHorzMoveByMethod('left');
		this.newX = this.panelX - this.distToMove;


		if (this.newX >= 0) {
			this.revealObj.style.left = this.newX+'px';
			this.panelObj.style.left = -(this.panelX) + this.distToMove + 'px';
			this.panelX = this.newX;
		} else {
			// oops overshot
			this.revealObj.style.left = '0px';
			this.panelObj.style.left = '0px';
			//this.panelX = (this.panelSizeX);
			this.canStopNow = true;
		}

		if (this.showDebug) { this.debug(); }

		if (this.canStopNow) {
			this.resetPanel();
		} else { this.panelTimer = setTimeout(this.className+'.horzRevealLeft()',30); }
	}

	this.horzRevealRight = function () {
		this.distToMove = this.getHorzMoveByMethod('right');
		this.newX = this.panelX + this.distToMove;


		if (this.newX <= 0) {
			this.revealObj.style.left = this.newX+'px';
			this.panelObj.style.left = -(this.panelX) - this.distToMove + 'px';
			this.panelX = this.newX;
		} else {
			// oops overshot
			this.revealObj.style.left = '0px';
			this.panelObj.style.left = '0px';
			//this.panelX = (this.panelSizeX);
			this.canStopNow = true;
		}

		if (this.showDebug) { this.debug(); }

		if (this.canStopNow) {
			this.resetPanel();
		} else { this.panelTimer = setTimeout(this.className+'.horzRevealRight()',30); }
	}

	this.horzScrollLeft = function () {
		this.distToMove = this.getHorzMoveByMethod('left');
		this.newX = this.panelX - this.distToMove;
		if (this.panelIndex==1) {
			var otherPanelObj = document.getElementById(this.panelName+'_reveal2');
		} else {
			var otherPanelObj = document.getElementById(this.panelName+'_reveal1');
		}

		if (this.newX >= 0) {
			this.revealObj.style.left = this.newX+'px';
			otherPanelObj.style.left = (this.newX - this.panelSizeX) +'px';
			this.panelX = this.newX;
		} else {
			// oops overshot
			this.revealObj.style.left = '0px';
			otherPanelObj.style.left = (-this.panelSizeX)+'px';
			//this.panelX = (this.panelSizeX);
			this.canStopNow = true;
		}

		if (this.showDebug) { this.debug(); }

		if (this.canStopNow) {
			this.resetPanel();
		} else { this.panelTimer = setTimeout(this.className+'.horzScrollLeft()',50); }
	}

	this.vertScrollUp = function () {
		this.distToMove = this.getVertMoveByMethod('up');
		this.newY = this.panelY - this.distToMove;
		if (this.panelIndex==1) {
			var otherPanelObj = document.getElementById(this.panelName+'_reveal2');
		} else {
			var otherPanelObj = document.getElementById(this.panelName+'_reveal1');
		}

		if (this.newY >= 0) {
			if (this.panelIndex==1) {
				this.revealObj.style.top = this.newY+'px';
				otherPanelObj.style.top = (this.newY - this.panelSizeY - this.panelSizeY) +'px';
			} else {
				this.revealObj.style.top = (this.newY - this.panelSizeY) +'px';
				otherPanelObj.style.top = (this.newY - this.panelSizeY)+'px';
			}

			this.panelY = this.newY;
		} else {
			// oops overshot
			if (this.panelIndex==1) {
				this.revealObj.style.top = '0px';
			} else {
				this.revealObj.style.top = (-this.panelSizeY) +'px';
			}
			otherPanelObj.style.top = (-this.panelSizeY)+'px';
			this.panelY = (-this.panelSizeY);
			this.canStopNow = true;
		}

		if (this.showDebug) { this.debug(); }

		if (this.canStopNow) {
			this.resetPanel();
		} else { this.panelTimer = setTimeout(this.className+'.vertScrollUp()',100); }
	}

	this.vertWipeUp = function () {
		this.distToMove = this.getVertMoveByMethod('up');
		this.newY = this.panelY - this.distToMove;
		//alert(this.panelY+' | '+this.distToMove); return;

		if (this.newY >= 0) {
			if (this.panelIndex==1) { this.revealObj.style.top = this.newY+'px'; } else { this.revealObj.style.top = (this.newY - this.panelSizeY) +'px'; }
			this.panelY = this.newY;
		} else {
			// oops overshot
			if (this.panelIndex==1) { this.revealObj.style.top = '0px'; } else { this.revealObj.style.top = (-this.panelSizeY) +'px'; }
			this.panelY = (-this.panelSizeY);
			this.canStopNow = true;
		}

		if (this.showDebug) { this.debug(); }

		if (this.canStopNow) {
			this.resetPanel();
		} else { this.panelTimer = setTimeout(this.className+'.vertWipeUp()',50); }
	}

	this.horzWipeLeft = function () {
		this.distToMove = this.getHorzMoveByMethod(this.transMethod);
		this.newX = this.panelX - this.distToMove;

		if (this.newX >= 0) {
			this.revealObj.style.left = this.newX+'px';
			this.panelX = this.newX;
		} else {
			// oops overshot
			this.revealObj.style.left = '0px';
			this.panelX = 0;
			this.canStopNow = true;
		}

		if (this.showDebug) { this.debug(); }

		if (this.canStopNow) {
			this.resetPanel();
		} else { this.panelTimer = setTimeout(this.className+'.horzWipeLeft()',50); }
	}

	this.resetPanel = function() {
		clearTimeout(this.panelTimer);

		if (this.firstPassToday) {
			var today = new Date();
			var expire = new Date();
			var hoursTilMidnight = 24 - today.getHours();
			// set cookie
			this.createCookie('nldzPanelState','no-intro',hoursTilMidnight);
			this.firstPassToday = false;
		}

		//this.filterObj.style.visibility = 'hidden';
		this.panelObj.style.left = '0px';
		this.panelObj.style.top = '0px';

		if (this.panelIndex==1) { var tmp = '0px'; } else { var tmp = (-this.panelSizeY)+'px'; }
		this.revealObj.style.top = tmp;
		this.revealObj.style.left = '0px';

		if (this.showDebug) { this.debug(); }

		// once our trasition is done we execute based on the last requested action, if any
		switch (this.panelState) {
		case 'pauseAfter':
			// just PAUSE and then skip the automated panel pull routines below
			this.setPanelStatus('paused');
			break;
		case 'goPrevAfter':
			// have to decrement-and-test TWICE because the index was previously set to point AHEAD
			this.displayBlockIndex--;
			if (this.displayBlockIndex < 0) {
				this.displayBlockIndex = this.displayBlocks.length - 1;
			}
			this.displayBlockIndex--;
			if (this.displayBlockIndex < 0) {
				this.displayBlockIndex = this.displayBlocks.length - 1;
			}
			this.pullPanel();
			break;
		case 'goNextAfter':
			// GO NEXT during a transition is handled a just like a regular panel pull; we assume this is what they meant anyway
		default:
			this.setPanelStatus('ready');
			if (this.panelIndexPrior>=0 && this.panelState!='paused') {
				this.oldRevealObj  = document.getElementById(this.panelName+'_reveal'+this.panelIndexPrior);
				this.oldPanelObj  = document.getElementById(this.panelName+'_'+this.panelIndexPrior);
				this.oldRevealObj.style.left = this.panelSizeX+'px';
				this.oldRevealObj.style.top = this.panelSizeY+'px';
				//this.oldPanelObj.style.visibility =  'hidden';
				//this.oldPanelObj.innerHTML = ''; // empty it out, just to be sure
			}

			this.panelIndexPrior = this.panelIndex;
			this.revealObj.style.zIndex = 10;  // background this now
			this.panelObj.style.zIndex = 15;
			//this.filterObj.style.zIndex = 20;

			this.panelIndex++; // ready for next panel
			if (this.panelIndex > 2) { this.panelIndex = 1; } // we don't replay the base panel 0

			this.displayBlockIndex++; // ready for next display block
			if (this.displayBlockIndex >= this.displayBlocks.length) {
				this.displayBlockIndex = 0;
			}

			if (!this.testingMode) { this.pauseTimer = setTimeout(this.className+'.pullPanel()',this.panelObj.duration*1000); }

		}
	}

	this.roundDec = function (dec,places) { return Math.floor( dec * 10^places ) / 10^places; }

	this.debug = function () {
		var msg = '';
		msg += 'panelIndex :'+ this.panelIndex +"<br>\n";
		msg += 'displayIndex :'+ this.displayBlockIndex +"<br>\n";
		//msg += 'paneObj: '+this.panelPane+"<br>\n";
		//msg += 'panelObj: '+this.panelObj+"<br>\n";
		msg += 'panelState: '+this.panelState+"<br>\n";
		//msg += 'newX :'+ this.newX +"<br>\n";
		//msg += 'newY :'+ this.newY +"<br>\n";
		msg += 'alpha :'+ this.panelObj.style.opacity +"<br>\n";
		msg += 'alphaAdj :'+ this.alphaAdj +"<br>\n";
		//msg += 'distToMove :'+ this.distToMove +"<br>\n";
		//msg += 'stopAt :'+ this.stopAt +"<br>\n";
		msg += 'canStopNow :'+ this.canStopNow +"<br>\n";
		document.getElementById('debug').innerHTML = msg;
	}

	this.findPosX = function (obj)
	{
		// tricky bit to account for nested objects
		var curleft = 0;
		if (obj.offsetParent){
			while (obj.offsetParent){
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		} else if (obj.x) { curleft += obj.x; }
		//alert('findPosX: '+curleft);
		return curleft;
	}

	this.findPosY = function (obj)
	{
		// tricky bit to account for nested objects
		var curtop = 0;
		//var printstring = '';
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				//printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
				curtop += obj.offsetTop;
				obj = obj.offsetParent;
			}
		} else if (obj.y) { curtop += obj.y; }
		//window.status = printstring;
		//alert('findPosY: '+curtop);
		return curtop;
	}

	this.getObj = function (name) {
		// get an object reference in accordance with the rules of engagement
		if (document.getElementById){
			this.obj = document.getElementById(name);
			this.style = document.getElementById(name).style;
		} else if (document.all) {
			this.obj = document.all[name];
			this.style = document.all[name].style;
		} else if (document.layers) {
			if (document.layers[name]) {
				this.obj = document.layers[name];
				this.style = document.layers[name];
			}
		}
	}
}

/* Client-side access to querystring name=value pairs
	Version 1.2.3
	22 Jun 2005
	Adam Vandenberg
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get

	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &

// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name

		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;

	var value=this.params[key]
	if (value==null) value=default_;

	return value
}

			