// COMMENT: Variable Declarations
/* COMMENT:
	Includes zero, so if you say 10 images 
	you need article00.jpg to article09.jpg
*/
var intArticleCount = 12;
var intCurrent = 0;
var objTimer;
var gstrID;


/* Function fGetObject
 * This function returns the requested object.
 *	Input: ID of object
 *	Output: Object itself	
 */
function fGetObject(objectId) {
	if(document.getElementById && document.getElementById(objectId))
		return document.getElementById(objectId);
	else if (document.all && document.all(objectId))
		return document.all(objectId);
	else if (document.layers && document.layers[objectId])
		return document.layers[objectId];
	else
		return false;
}


/* Function fToggle
 * This function toggles the visibility of the specified object
 *	Input: ID of object
 *	Output: Visual
 */
function fToggle(strID)
{
	var strVisibility = '';
	var cstrHidden = "hidden";
	var cstrVisible = "visible";
	var objDiv = fGetObject(strID);

	if (objDiv == null) { return false; }

	strVisibility = objDiv.className;

	if (strVisibility == cstrVisible || strVisibility == '') { strVisibility = cstrHidden; }
	else if (strVisibility == cstrHidden) { strVisibility = cstrVisible; }

	objDiv.className = strVisibility;
	return false;
}


/* Function fHideLoadingScrapbook
 * This function hides the "Loading Scrapbook" image
 *	Input: None
 *	Output: Visual
 */
function fHideLoadingScrapbook()
{ 
	//Effect.toggle('loadingScrapbook', 'appear'); 
	$('#loadingScrapbook').toggle();
}
	
	
/* Function fShowImage
 * This function updates the global variable, then adds the 
 * fProcessImage function to the body onload event
 *	Input: ID of the image
 *	Output: None	
 */
function fShowImage(strID)
{
	$(document).ready(function(){$('#' + strID).trigger('click');});
}



	
/* Function fArticleStart
 * This function starts the timer to cycle the article background
 *	Input: None
 *	Output: Updates global objTimer
 */
function fArticleStart()
{ objTimer = setTimeout('fArticleNext()', 10000); }


/* Function fArticlePrev
 * This function stops the timer then cycles the background back one
 *	Input: None
 *	Output: None
 */
function fArticlePrev()
{
	clearTimeout(objTimer);
	fArticleCycle(-1);
}


/* Function fArticleNext
 * This function stops the timer then cycles the background forward one
 *	Input: None
 *	Output: None
 */
function fArticleNext()
{
	clearTimeout(objTimer)
	fArticleCycle(1);
}


/* Function fArticleCycle
 * This function cycles the article background
 *	Input: Direction to Cycle
 *	Output: Visual
 */
function fArticleCycle(intDirection)
{
	// COMMENT: Variable Declaration
	var strArticle = '';
	var strCurrent = intCurrent.toString();
	
	// COMMENT: At the Beginning, Go To End
	if (intCurrent + intDirection < 0)
	{ intCurrent = intArticleCount - 1; }

	// COMMENT: At the End, Go To Beginning
	else if (intCurrent + intDirection >= intArticleCount)
	{ intCurrent = 0; }
	
	// COMMENT: Increment Default	
	else
	{ intCurrent = intCurrent + intDirection; }
	
	// COMMENT: Move Background	
	//fGetObject('article').style.backgroundPosition = '0px ' + arrArticles[intCurrent] + 'px';
	strArticle = strCurrent.length == 1 ? '0' + strCurrent : strCurrent;
	//alert(strArticle);
	fGetObject('article').style.backgroundImage = "url('/img/article" + strArticle + ".jpg')";
	
	/*
	// COMMENT: Display Current Article
	strArticle = intCurrent.length == 1 ? '0' + intCurrent : intCurrent;
	fGetObject('article' + strArticle).className = 'visible';
	
	// COMMENT: Hide All Articles
	for (intI = 0; intI < intArticleCount; intI++)
	{
		strArticle = intI.length == 1 ? '0' + intI : intI;
		fGetObject('article' + strArticle).className = 'hidden';
	}
	*/
	
	// COMMENT: Start Timer
	objTimer = setTimeout('fArticleNext()', 10000);
}


/* Function sfHover
 * This function adds hover capabilities to non-A elements in IE
 *	Input: 
 *	Output: 
 */
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}


/* Function addEventToOjbect
 * This function adds events to the specific object.
 *	Input: Object, Events, Function
 *	Output: None
 */
function addEventToObject(obj,evt,func) {
	var oldhandler = obj[evt];
	obj[evt] = (typeof obj[evt] != 'function') ? func : function(){oldhandler();func();};
}


/* Class Searchbox
 * This class represents the searchbox object.
 *	Input: 
 *	Output: 
 */
var Searchbox = {
	init : function()
		{
		var sBox = fGetObject('search-text');
		if (sBox)
			{
			addEventToObject(sBox,'onclick',Searchbox.click);
			addEventToObject(sBox,'onblur',Searchbox.blur);
			}	
		},
	click : function()
		{
		var sBox = fGetObject('search-text');
		if (sBox.value == 'Enter Search Criteria')
			{
			sBox.value = '';
			}
	  	},
	blur : function()
		{
		var sBox = fGetObject('search-text');
		if (sBox.value == '' || sBox.value == ' ') {sBox.value = 'Enter Search Criteria';}
		}
};


/* Class Logo
 * This class represents the logo object.
 *	Input: 
 *	Output: 
 */
var Logo = {
	init : function()
	{
		var sLogo = fGetObject('logo');
		if (sLogo) { addEventToObject(sLogo,'onmouseover',Logo.over); addEventToObject(sLogo,'onmouseout',Logo.out); }	
	},
	over : function()
	{
		var sLogo = fGetObject('logo');
		var sLogoTip = fGetObject('logoTip');
		if (sLogo && sLogoTip) { sLogoTip.className = 'visible'; }
  	},
	out : function()
	{
		var sLogo = fGetObject('logo');
		var sLogoTip = fGetObject('logoTip');
		if (sLogo && sLogoTip) { sLogoTip.className = 'hidden'; }
	}
};

// COMMENT: Attach Events
addEventToObject(window, 'onload', Searchbox.init);
addEventToObject(window, 'onload', Logo.init);
addEventToObject(window, 'onload', fArticleStart);
if (window.attachEvent) window.attachEvent("onload", sfHover);




