// JavaScript files for PCTS website - 20080523 v. 1

// --- namespace variables -------
pcts.clientHeight = 3000;
pcts.clientWidth = '';
pcts.readyState = '';
pcts.fadeTimer = '';
pcts.currentSlideOpacity = 100;

// --- namespace functions -------

pcts.getClientHeight = function() {
	return document.documentElement.clientHeight;
}
	
pcts.getClientWidth = function() {
	return document.documentElement.offsetWidth;
}

pcts.changeLocation = function(theLocation) {
	// traverse the window to a new page location, loading a page
	// appropriate to the sensed browser
	// alert(pctsFramework.browserPath + '/' + theLocation);
	window.location = pctsFramework.browserPath + '/' + theLocation + "?frameworkState=" + pctsFramework.orphanMode;
}

pcts.setBasicClientData = function() {
	// get and retain basic information about the client
	
	// first, get the height
	pcts.clientHeight = pcts.getClientHeight();

	// now get the width
	pcts.clientWidth = pcts.getClientWidth();

}

pcts.setElementHeights = function() {
	// set the heights of certain page elements
	try {
		document.getElementById('mainBody').style.height = pcts.clientHeight + 'px';

	} catch(err) {

	}
}

pcts.fadeIn = function(theId, theStart, theEnd, theTime) {
	// fade an object in from one specified opacity to another
	// set the speed of fade
	var theSpeed = Math.round(theTime / 100);
	var theTimer = 0;

	for(i = theStart; i <= theEnd; i++) {
		pcts.fadeTimer = setTimeout("pcts.setOpacity(" + i + ",'" + theId + "')",(theTimer * theSpeed));
		theTimer++;
	}
}

pcts.fadeOut = function(theId, theStart, theEnd, theTime) {
	// fade an object in from one specified opacity to another
	// set the speed of fade
	var theSpeed = Math.round(theTime / 100);
	var theTimer = 0;

	for(i = theStart; i >= theEnd; i--) {
		setTimeout("pcts.setOpacity(" + i + ",'" + theId + "')",(theTimer * theSpeed));
		theTimer++;
	}
}

pcts.setOpacity = function(theOpacity, theId) {
	// this is a cross-browser capable method for setting the opacity of an object
	try {
		var theObject = document.getElementById(theId).style; 
	
		// safari
		theObject.opacity = (theOpacity / 100);
	
		// mozilla
		theObject.MozOpacity = (theOpacity / 100);
	
		// IE
		theObject.filter = "alpha(opacity=" + theOpacity + ")";
	
	} catch(err) {
		// if we wind up here, it is likely the object was not found
		
	}
}

pcts.showSpinner = function() {
	// show the pcts spinner
	var theTop = pcts.clientHeight / 2 - 35 + 'px';
	var theLeft = pcts.clientWidth / 2 - 35 + 'px';

	document.getElementById('pctsSpinner').style.top = theTop;
	document.getElementById('pctsSpinner').style.left = theLeft;

}

pcts.hideSpinner = function() {
	// hide the pcts spinner
	document.getElementById('pctsSpinner').style.top = '-100px';
	document.getElementById('pctsSpinner').style.left = '-100px';

}

pcts.positionElements = function() {
	// position elements upon attached events

	// position the primary footer
	
	// get the window rectangle
	var theHeight = pctsFramework.getClientHeight();

	// get the scrollHeight
	var theScrollHeight = document.body.scrollHeight;

	// alert('window height is: ' + theHeight + ', content height is: ' + theScrollHeight);

	// position based either on scroll height or window height,
	// using the larger value.  This forces the footer always to the bottom
	if( theHeight > theScrollHeight ) {
		document.getElementById('primaryFooter').style.top = theHeight - 120 + 'px';

	} else {
		document.getElementById('primaryFooter').style.top = theScrollHeight - 120 + 'px';
	}
	
	// make the footer visible
	document.getElementById('primaryFooter').style.visibility = 'visible';

}

pcts.handleMenuMouse = function(theId, theAction) {
	// handle mouse actions across a main menubar item

	// first create an id for the underline of the menu item
	var theUnder = theId + '_under';

	if (theAction == 'in') {
		// this is a mouse enter event
		document.getElementById(theUnder).className = 'lsep_lbl';
	} else {
		document.getElementById(theUnder).className = '';
	}
		
}

pcts.setNoPropogate = function(theEvent) {
	// cancel an event and stop it from bubbling
	var theEvent; // the event fired
	
	try {// first figure out if this is IE and set the cancelBubble property
		if (pctsFramework.browserPath == 'ie' ) {
			theEvent.cancelBubble = true;
			
		}
		
		// if it isn't IE stopPropagation
		if (theEvent.stopPropagation) {
			//alert('this is firefox');
			theEvent.stopPropagation();
	}
	
	} catch(err) {
		// if we wind up here, there was no bubbled event to cancel
	}
}

// --- attached events -------

// we attach inside an if statement because IE handles event listeners differently from other browsers.

if (window.attachEvent) {
	// attached events for IE
	window.attachEvent("onload", pcts.setBasicClientData);
	window.attachEvent("onresize", pcts.setBasicClientData);
} else {
	// attached events for other browsers
	window.addEventListener('load', pcts.setBasicClientData, false);
	window.addEventListener('resize', pcts.setBasicClientData, false);
}