var accordionHeadingSelector = 'h3';
var accordionBodySelector = 'div';
var bitDebugEnabled = false;

/// A list of domain names to consider "internal". Can include regular expressions.
var InternalDomains = new Array(
	'library.ucf.edu',
	'm.library.ucf.edu',
	/lib\.ucf\.edu/,
	'cf.aleph.fcla.edu',
	'cf.catalog.fcla.edu',
	'metalib.fcla.edu',
	'fclnx5.fcla.edu',
	'sfx.fcla.edu',
	'sfx-test.fcla.edu'
);



function ResetField(obj,defaultVal) {
	if (obj) {
		if ( obj.value == '' ) {
			obj.value = defaultVal;
		}
	}
}
function ClearField(obj,defaultVal) {
	if (obj) {
		if ( obj.value == defaultVal ) {
			obj.value = '';
		}
	}
}
function goHere(me) {
	if (me.value != '0')	window.location = me.value;
}



/****************************
/
/ Toggles boolean values
/
/***************************/
function Toggle(state) {
	if (state == true || state == false) {
		if (state == true) {
			return false;
		}
		else {
			return true;
		}
	}
	return state;
}

/****************************
/
/ Toggles an ID or an object reference between block and none, to show or hide it.
/
/***************************/
function ToggleBlock(id, manualstate) {
	var obj = $(id);
	if (obj) {
		if ( manualstate != null ) {
			if (manualstate) {
				obj.setStyle('display', 'block');
				return true;
			}
			else {
				obj.setStyle('display', 'none');
				return false;
			}
		}
		else {
			var objstyle = obj.getStyle('display');
			if (objstyle == 'none') {
				obj.setStyle('display', 'block');
				return true;
			}
			else {
				obj.setStyle('display', 'none');
				return false;
			}
		}
	}
}

/****************************
/
/ AJAX Request object
/
/***************************/
function GetXmlHttpObject() {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}

/****************************
/
/ ZeroPad - Add a zero to a number less than 10
/
/***************************/
function ZeroPad(number) {
	return (number < 10) ? '0' + number : number;
}

/****************************
/
/ Plural - if the amount is 1, don't return an S, otherwise do.
/
/***************************/
function Plural(amount) {
	return amount == 1 ? '' : 's';
}

/****************************
/
/ Build a query for use with either GET or POST. Send in an object wth properties and get back the whole query string.
/
/***************************/
function BuildQuery(queryObj) {
	var QueryString = new Array();
	for (fieldname in queryObj) {
		QueryString.push(fieldname + '=' + queryObj[fieldname]);
		//window.alert(fieldname + '=' + queryObj[fieldname]);
	}
	return QueryString.join('&');
}

/****************************
/
/ Build a query string. Send in an object wth properties and get back the whole query string.
/
/***************************/
function BuildQueryString(queryObj) {
	return '?' + BuildQuery(queryObj);
}



/****************************
/
/ Internal Website Domains. External ones will return false;
/
/***************************/
function isInternalDomain(url) {
	//console.log('Recieved: ' + url + ';');
	url = url.toLowerCase();
	if (url == '' || url.match(/^[\/\.]/)) {
		//console.log('BOOYA!! Found it! ' + url + ' is internal alright. And we get to stop early.');
		return true;
	}
	url = url.replace(/^[hf]tt?ps?:\/\//, '');
	url = url.replace(/\/.*$/, '');
	
	/*
	var InternalDomains = new Array(
		'library.ucf.edu',
		'm.library.ucf.edu',
		/lib\.ucf\.edu/,
		'cf.aleph.fcla.edu',
		'cf.catalog.fcla.edu',
		'metalib.fcla.edu',
		'sfx.fcla.edu'
	);
	*/
	
	//for (var domain in InternalDomains) {
	for (var i = 0; i < InternalDomains.length; i++) {
		var domain = InternalDomains[i];
		//console.log('Testing: ' + url + '; against ' + domain);
		if ( url.match(domain) ) {
			//console.log('BOOYA!! Found it! ' + url + ' is internal alright.');
			return true;
		}
	}
	
	//console.log('Well, I guess ' + url + ' must be external.');
	return false;
}

/****************************
/
/ Save Cookie
/
/***************************/
function SaveCookie(cookie,value,reload,expiretime) {
	expiretime = expiretime || (60 * 60 * 24 * 365 * 10); // 10 years from now.
	var expiration = new Date();
	expiration.setSeconds(expiration.getSeconds() + expiretime);
	document.cookie = cookie + "=" + value
	+ "; expires=" + expiration.toUTCString() + ";path=/";
	// Fri, 31-Dec-2000 00:00:00 GMT
	if (reload) {
		window.location.href = window.location.href;
	}
}

/****************************
/
/ Get A Cookie Value By Name
/
/***************************/
//Get cookie routine by Shelley Powers (get_cookie) Thanks Shelly
function GetCookie(name) {
	var search = name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		// if cookie exists
		if (offset != -1) { 
			offset += search.length
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

/****************************
/
/ Add a shadow to any element with a Shadow class
/
/***************************/
function AddShadow(item) {
	item = $(item);
	
	//var debug = '';
	//for (var prop in Aside ) {
	//	var value = Aside[prop];
	//	if (value != null && (typeof value == 'string')) {
	//		debug+= prop + ': ' + value + '\n';
	//	}
	//}
	//window.alert(debug);
	//var Aside = item.clone(true, true).cloneEvents(item);
	//Aside.className = item.className;
	//var Container = new Element('div');
	//Container.grab(Aside);
	
	//if (Browser.Engine.webkit || Browser.Engine.gecko) {
		// Browsers that support the box-shadow property
		item.addClass('Shadow');
	//}
	//else {
		// Other browsers
	//	var Shadow = new Element('div', {'class': 'ShadowFaux'});
	//	Container.grab(Shadow);
	//}
	//Container.replaces(item);
	//return Container;
	return item;
}

/****************************
/
/ Double flash an element's background
/
/***************************/
function HighlightThis(element, origbgcolor ) {
	if (element) {
		var origbgcolor = origbgcolor || element.getStyle('background-color');
		//window.alert(origbgcolor);
		if (origbgcolor == 'transparent') {
			origbgcolor = '#ddd';
		}
		
		//var myFx = new Fx.Tween(element, {property: 'opacity', duration: 150});
		//myFx.start(0.3).chain(
			//Notice that "this" refers to the calling object (in this case, the myFx object).
		//	function(){ this.start(1); },
		//	function(){ this.start(0.3); },
		//	function(){ this.start(1); }
		//);
		var myFx = new Fx.Tween(element, {property: 'background-color', duration: 150});
		myFx.start('#fff').chain(
			//Notice that "this" refers to the calling object (in this case, the myFx object).
			function(){ this.start(origbgcolor); },
			function(){ this.start('#fff'); },
			function(){ this.start(origbgcolor); }
		);
	}
}

function ActivateAccordionHeading(hash) {
	hash = hash.replace(/^#/, '');
	if (hash) {
		//window.alert(hash);
		var accheadinganchor = $$('a[name='+hash+']');
		if (accheadinganchor) {
			accheadinganchor = accheadinganchor[0];
			if (accheadinganchor) {
				var accparent = accheadinganchor.getParent('.Accordion');
				if (accparent) {
					var accheading = accheadinganchor.getParent(accordionHeadingSelector);
					//console.log(accheadinganchor, accparent, accparent.retrieve('accordion'));
					var myAccordion = accparent.retrieve('accordion');
					if (myAccordion) {
						myAccordion.display(accheading.retrieve('index'));
					}
				}
			}
		}
	}
}

/****************************
/
/ Photo Fade object. Cycles a set of LIs inside a UL.
/
/***************************/
function PhotoFade() {
	this.intCurrentIndex = 0;
	this.intNextIndex = 0;
	this.intLastIndex = 0;
	this.eleULBlock = null;
	this.arrLIs = null;
	this.intTimeTransition = 2000;
	this.intTimeHold = 4000;
	this.currentCookie = new Hash.Cookie('libPhotoFade', {duration: 7});
	
	this.Cycle = function() {
		//console.log('Rotating Ad', this);
		if (this.arrLIs) {
			var strBlockId = this.eleULBlock.get('id');
			if (this.intCurrentIndex > this.intLastIndex) {
				this.intCurrentIndex = 0;
			}
			
			this.intNextIndex = this.intCurrentIndex + 1;
			
			if (this.intNextIndex > this.intLastIndex) {
				this.intNextIndex = 0;
			}
			//console.log('Current Index:', this.intCurrentIndex, 'Next Index:', this.intNextIndex);
			var eleCurrentAd = $(this.arrLIs[this.intCurrentIndex]);
			var eleNextAd = $(this.arrLIs[this.intNextIndex]);
			eleCurrentAd.setStyle('z-index', '0');
			eleNextAd.setStyle('z-index', '1');
			eleNextAd.set('tween', {duration: this.intTimeTransition});
			eleNextAd.fade('in');
			eleCurrentAd.fade.delay(this.intTimeTransition, eleCurrentAd, 'out');
			//console.log(this.intCurrentIndex, this.arrLIs[this.intCurrentIndex]);
			this.intCurrentIndex++;
			this.currentCookie.set(strBlockId,this.intCurrentIndex);
			//console.log('Rotating Ad Complete', this.intCurrentIndex);
		}
	}
	
	this.Apply = function(eleULBlock) {
		//if (eleULBlock) {
			this.eleULBlock = $(eleULBlock);
			if (this.eleULBlock && !this.eleULBlock.hasClass('AppliedPhotoFade')) {
				//console.log(this.eleULBlock, this.intCurrentIndex);
				this.eleULBlock.addClass('AppliedPhotoFade');
				this.arrLIs = eleULBlock.getElements('li');
				this.intLastIndex = this.arrLIs.length - 1;
				
				var strBlockId = this.eleULBlock.get('id');
				var intCookieVal = this.currentCookie.get(strBlockId);
				//console.log(this);
				if(intCookieVal){
					this.intCurrentIndex = intCookieVal;
				}
				if (this.intCurrentIndex > this.intLastIndex) {
					this.intCurrentIndex = 0;
				}
				var intCurrentIndex = this.intCurrentIndex;
				
				//console.log(this);
				//var intFirstLISize = null;
				this.arrLIs.each( function(eleLI, intLIIndex) {
					//console.log('LI Loop:', intLIIndex ,' ',intCurrentIndex, (intLIIndex != this.intCurrentIndex));
					if (intLIIndex == 0) {
						var intFirstLISize = eleLI.getSize();
						eleULBlock.setStyle('height', intFirstLISize.y);
					}
					if (intLIIndex != intCurrentIndex) {
						eleLI.fade('hide');
						//eleLI.setStyle('height', intFirstLISize.y);
						//eleLI.setStyle('overflow', 'hidden');
					}
					else {
						eleLI.fade('show');
					}
					eleLI.setStyle('position', 'absolute');
					eleLI.setStyle('z-index', '0');
				});
				
				this.Cycle.periodical(this.intTimeHold, this);
			}
		//}
	}
}


/***********************************************/
/*** Initializers ******************************/
/***********************************************/

function InitializeAside(item) {
	if (item.hasClass('GuideSections')) {
		item.removeClass('GuideSections');
		item.addClass('Aside');
	}
	//if (Browser.Engine.webkit || Browser.Engine.gecko) {
		// Do whatever. i don't care. you browsers already know what to do.
	//}
	//else {
	//if (item) {
	//	$(item.parentNode).addClass('AsideContainer');
	//}
	return item;
}

function InitializeSearchFields() {
	function FocusField(obj) {
		obj = $(obj);
		if ( obj.value == obj.get('placeholder') ) {
			obj.value = '';
			obj.removeClass('Blank');
		}
	}
	function BlurField(obj) {
		obj = $(obj);
		if ( obj.value == '' ) {
			obj.value = obj.get('placeholder');
			obj.addClass('Blank');
		}
	}
	
	var SearchFields = $$('input[placeholder]');
	SearchFields.each( function(item, index, array) {
		FocusField(item);
		BlurField(item);
		
		item.addEvent('focus', function() {
			FocusField(item);
		});
		item.addEvent('blur', function() {
			BlurField(item);
		});
		
		var parentFormObj = item.getParent('form');
		if (parentFormObj) {
			parentFormObj.addEvent('submit', function() {
				FocusField(item);
			});
		}
	});
}

var initializeattentiongettersdone = false;
function InitializeAttentionGetters() {
	
	function Blink() {
		$(this).highlight('#fff');
	}
	function Pulse() {
		element = $(this);
		var origbgcolor = element.getStyle('background-color');
		//window.alert(origbgcolor);
		if (origbgcolor == 'transparent') {
			origbgcolor = '#ddd';
		}
		var myFx = new Fx.Tween(element, {property: 'background-color', duration: 1000});
		//element.set('tween', {property: 'background-color', duration: 1000})
		myFx.start('#fff').chain(
			function(){ this.start(origbgcolor); }
		);
	}
	
	if (initializeattentiongettersdone == false) {
		var BlinkSlows = $$('.BlinkSlow');
		BlinkSlows.each( function(item) {
			Blink.periodical(2000, item);
		});
		
		var Blinks = $$('.Blink');
		Blinks.each( function(item) {
			Blink.periodical(750, item);
		});
		
		var Pulses = $$('.Pulse');
		Pulses.each( function(item) {
			//item.Pulse();
			Pulse.periodical(2000, item);
		});
		
		initializeattentiongettersdone = true;
	}
}

/* Remove duplicate references to CSS files so that only one reference exists per document. */
function InitializeCSSLinkTagLocations() {
	
	function ExtractPathFromURL(url) {
		url = url.replace(/\?.*$/, '');
		url = url.replace(/^[hf]tt?ps?\:\/\/.*?\//, '');
		url = url.replace(/\.\./g, '');
		url = url.replace(/\/+/g, '/');
		return url;
	}
	
	var LinkURLs = new Array();
	var AllLinks = $(document).getElements('link').reverse();
	AllLinks.each( function(item, index) {
		item.id = 'CSSLink' + index;
		//window.alert(item.href)
		var itemhref = ExtractPathFromURL(item.href);
		//itemhref = itemhref.replace(/^[hf]tt?ps?\:\/\/.*?\//, '');
		//itemhref = itemhref.replace(/\.\./g, '');
		//itemhref = itemhref.replace(/\/+/g, '/');
		var hrefexists = LinkURLs.some( function(href, hindex) {
			return href == itemhref;
		});
		/* Kill off the duplicates, and if it's not a duplicate add it to the pile */
		if (hrefexists) {
			item.dispose();
		}
		else {
			LinkURLs.push(itemhref);
		}
		//window.alert(itemhref);
		//console.log(item);
	});
	/* Get the HEAD tag of the document */
	var HeadObj = document.head;
	/* If one doesn't exist, create one and set our obj to the new obj */
	if (!HeadObj) {
		var newHeadObj = new Element('head');
		document.appendChild(newHeadObj);
		HeadObj = document.head;
	}
	/* Go through all the links in the body and move them to the new head section */
	var BodyLinks = $(document.body).getElements('link');
	BodyLinks.each( function(item) {
		$(document.head).grab(item);
	});
	/* Now, put all the stule tags underneath the link tags in head section so they can take precidence */
	var StyleTags = $(document).getElements('style');
	StyleTags.each( function(item) {
		$(document.head).grab(item);
	});
	//var AllLinks = $(document).getElements('link');
	//AllLinks.each( function(item, index) {
	//	window.alert(item.href);
	//});
}

function InitializeAccordions() {
	var Accordions = $$('.Accordion');
	Accordions.each( function(item) {
		var Headers = item.getElements(accordionHeadingSelector);
		Headers.each( function(header, hindex) {
			header.store('index', hindex);
		});
		var myAccordion = new Accordion(Headers, item.getChildren(accordionBodySelector), {
			onActive: function(toggler, block) {
				toggler.addClass('Active');
				//this.ActiveBlock = block;
			},
			onBackground: function(toggler, block) {
				toggler.removeClass('Active');
			}
		});
		item.store('accordion', myAccordion);
	});
	
	var AnchorRefs = $$('a[href^=#]');
	AnchorRefs.each( function(atag) {
		var hash = atag.hash;
		atag.addEvent('click', function() {
			ActivateAccordionHeading(hash);
		});
	});
}

function InitializeAlternatingRows() {
	//var AllElements = document.getElementsByTagName("*");
	//if (AllElements) {
	//	var AlternatingRowObjects = new Array();
	//	for (var i = 0; i < AllElements.length; i++) {
	//		if ( AllElements[i] && AllElements[i].className && AllElements[i].className.search(/AlternateRows/i) >= 0 ) {
	var AlternateRows = $$('.AlternateRows');
	AlternateRows.each( function(row, rindex) {
	
		//AlternatingRowObjects.push(AllElements[i]);
		//window.status+= ' ' + AllElements[i].className + ' at '+i+'! ';
		var RowNodes = row.childNodes;
		var RowNodesInsideTBODY = RowNodes;
		for(var j = 0; j < RowNodesInsideTBODY.length; j++) {
			if (RowNodesInsideTBODY[j].nodeName.toLowerCase() == 'tbody') {
				// We are inside a table with a tbody tag. so get *it's* children and then continue;
				RowNodes = RowNodesInsideTBODY[j].childNodes;
				// Exit the loop by forging completion
				j = RowNodesInsideTBODY.length;
			}
		}
		var rowindex = 0;
		for(var j = 0; j < RowNodes.length; j++) {
			if (RowNodes[j].nodeType == 1) {
				$(RowNodes[j]).addClass( (rowindex % 2) ? 'RowOdd' : 'RowEven');
				rowindex++;
			}
		}
	});
	//		}
	//	}
		/*if (AlternatingRowObjects.length > 0) {
			for (var i = 0; i < AlternatingRowObjects()
				var RowNodes = AllElements[i].childNodes;
				for(var j = 1; i < RowNodes.length; i++) {
					RowNodes[i].className = (i % 2) ? 'RowOdd' : 'RowEven';
				}*/
	//}
}

function InitializeHeadings() {
	/// 2 possible approaches here:
	/// Select exactly only what we need... Lots of selectors and garbage that takes time to look through
	/// OR
	/// Select everything and weed out the ones we don't want.
	//var Headings = $$('#LibArticle>h3, #LibArticle>h4, #LibArticle>h5, #LibArticle>section>h3, #LibArticle>section>h4, #LibArticle>section>h5, #LibArticle>div.ThinBlock>h3, #LibArticle>div.ThinBlock>h4, #LibArticle>div.ThinBlock>h5');
	var Headings = $$('#LibArticle h3, #LibArticle h4, #LibArticle h5');
	Headings.each( function(item) {
		//var parentnode = item.getParent();
		if (item.getParent('#IndexFrame') || item.getParent('.Aside') || item.getParent('.Accordion') || item.getParent('.HeadingContainer')) {
			return false;
		}
		var heading = new Element('div', {'class': 'HeadingContainer'});
		heading.wraps(item);
	});
}

function InitializeHRs() {
	/// 2 possible approaches here:
	/// Select exactly only what we need... Lots of selectors and garbage that takes time to look through
	/// OR
	/// Select everything and weed out the ones we don't want.
	//var Headings = $$('#LibArticle>h3, #LibArticle>h4, #LibArticle>h5, #LibArticle>section>h3, #LibArticle>section>h4, #LibArticle>section>h5, #LibArticle>div.ThinBlock>h3, #LibArticle>div.ThinBlock>h4, #LibArticle>div.ThinBlock>h5');
	var Headings = $$('hr');
	Headings.each( function(item) {
		//var parentnode = item.getParent();
		var heading = new Element('div', {'class': 'hr'});
		heading.wraps(item);
	});
}

function InitializePhotoFade() {
	var arrMiniAds = $$('ul.MiniAds');
	arrMiniAds.each( function(eleULBlock) {
		var objMiniAd = new PhotoFade();
		objMiniAd.intTimeTransition = 1000;
		objMiniAd.intTimeHold = 6000;
		objMiniAd.Apply(eleULBlock);
	});
	
	var arrPhotoFades = $$('ul.PhotoFade');
	arrPhotoFades.each( function(eleULBlock) {
		var objPhotoFade = new PhotoFade();
		objPhotoFade.intTimeTransition = 1500;
		objPhotoFade.intTimeHold = 5000;
		objPhotoFade.Apply(eleULBlock);
	});
}

function InitializeWarnings() {
	var arrWarnings = $$('.Warning');
	arrWarnings.each( function(eleItem) {
		var eleNewDiv1 = new Element('div', {'class': 'WarningOuter'});
		var eleNewDiv2 = new Element('div', {'class': 'DontWrapSideBar'});
		eleNewDiv1.wraps(eleItem);
		eleNewDiv2.wraps(eleNewDiv1);
	});
}

function InitializeDebug() {
	var eleDebugDiv = new Element('div', {'id': 'LibDebug', 'style': 'display: ' + (bitDebugEnabled == true ? 'block' : 'none') + ';' });
	var eleDebugHeading = new Element('h3', {'text': 'Debugging Code'});
	eleDebugDiv.grab(eleDebugHeading);
	eleDebugDiv.inject($('LibPage'));
}

function Debug(strDebug) {
	var eleDebugDiv = $('LibDebug');
	if (eleDebugDiv) {
		var elePre = new Element('pre', {'text': strDebug});
		eleDebugDiv.grab(elePre);
	}
}

/***********************************************/
/*** Events ************************************/
/***********************************************/

window.addEvent('domready', function(event) {
	InitializeDebug();
	/// Do this function if we are in IE and the shift key is down.
	//window.alert(event);
	//if ( Browser.Engine.trident && window.event.shift ) {
	//	InitializeCSSLinkTagLocations();
	//}
	//else if ( !Browser.Engine.trident ) { //if (window.event == null || window.event.shift == null) {
		/// If we aren't in IE, just run it anyway, because this is correct.
		//console.log('Looks like this isn\'t IE.');
		InitializeCSSLinkTagLocations();
	//}
	//console.log('Looks like this isn\'t IE.');
	//console.log(window.event);
	//window.alert('test');
	//var Shadows = $$('.Aside, aside, .GuideSections, .HasShadow');
	var Shadows = $$('.HasShadow');
	Shadows.each( AddShadow );
	
	//var Asides = $$('.Aside, aside, .GuideSections');
	//Asides.each( InitializeAside );
	
	InitializeSearchFields();
	//InitializeHeadings();
	InitializeHRs();
	
	InitializeAccordions();
	var hash = window.location.hash;
	ActivateAccordionHeading(hash);
	
	InitializeAlternatingRows();
	InitializeAttentionGetters();
	//InitializeSideBarOptions();
	
	InitializePhotoFade();
	InitializeWarnings();
	
	//HoursSelector();
	if (document.compatMode == 'CSS1Compat') {
		window.status = "Site loaded in Standards mode.";
	}
	else {
		window.status = "Site loaded in Quirks mode. Please add <!DOCTYPE html> to the top of the document.";
	}
	
	//var testurl = document.domain;
	//window.alert(testurl + ' = "' + isInternalDomain(testurl) + '"' );
	//isInternalDomain(testurl);
	var AllLinks = $$('a[href]');
	AllLinks.each( function(link) {
		if (link.target == '') {
			//console.log(link);
			//var isinternal = ;
			if ( !isInternalDomain(link.host) ) {
				link.set('target', '_blank');
				//link.setStyle('background-color', 'Highlight');
				//console.log(link);
			}
			//console.log(link, isinternal);
		}
	});
});

if (typeof(hljs) !== 'undefined') {
	hljs.tabReplace = '   ';
	hljs.initHighlightingOnLoad();
	//window.alert('Syntax colorizing the page...');
}
//window.alert(typeof(hljs) + ' ' + (typeof(hljs) !== 'undefined'));

/// Enable automatic syntax highlighting if it's been included in the scripts.


/*** OLD SECTION - UNDER REVIEW ****************/

/****************************
/
/ Hide the first vertical line in a navigation list
/
/***************************/
function StyleNavigation() {
	var allULs = document.getElementsByTagName("ul");
	for (var i=0; i<allULs.length; i++) {
		if (allULs[i].className == "Navigation") {
			var allLIs = allULs[i].getElementsByTagName("li");
			if (allLIs[0]) {
				allLIs[0].style.borderLeftWidth = "0";
			}
		}
	}
	//setClassStyle("Navigation","color","red","LI");
	//setClassStyle("Navigation","borderLeftWidth","0","li");
}

function StyleNavigationSectionHeadings() {
	//var Boxes = $$('.BasicBox');
	var Boxes = $$('.GuideSections');
	Boxes = Boxes.concat( $$('.BasicBox') );
	for (var i = 0; i < Boxes.length; i++) {
		var Headings = Boxes[i].getElementsByTagName('h4');
		for (var j = 0; j < Headings.length; j++) {
			var heading = $(Headings[j]);
			if (j == 0 && heading.addClass) {
				heading.addClass('first');
				//window.status = 'fount one';
			}
		}
	}
}

function SetupAlternatingTableRows() {
	var AllElements = document.getElementsByTagName("*");
	if (AllElements) {
		var AlternatingRowObjects = new Array();
		for (var i = 0; i < AllElements.length; i++) {
			if ( AllElements[i] && AllElements[i].className && AllElements[i].className.search(/AlternateRows/i) >= 0 ) {
				AlternatingRowObjects.push(AllElements[i]);
				//window.status+= ' ' + AllElements[i].className + ' at '+i+'! ';
				var RowNodes = AllElements[i].childNodes;
				var RowNodesInsideTBODY = RowNodes;
				for(var j = 0; j < RowNodesInsideTBODY.length; j++) {
					if (RowNodesInsideTBODY[j].nodeName.toLowerCase() == 'tbody') {
						// We are inside a table with a tbody tag. so get *it's* children and then continue;
						RowNodes = RowNodesInsideTBODY[j].childNodes;
						// Exit the loop by forging completion
						j = RowNodesInsideTBODY.length;
					}
				}
				var rowindex = 0;
				for(var j = 0; j < RowNodes.length; j++) {
					if (RowNodes[j].nodeType == 1) {
						RowNodes[j].className = (rowindex % 2) ? 'RowOdd' : 'RowEven';
						rowindex++;
					}
				}
			}
		}
		/*if (AlternatingRowObjects.length > 0) {
			for (var i = 0; i < AlternatingRowObjects()
				var RowNodes = AllElements[i].childNodes;
				for(var j = 1; i < RowNodes.length; i++) {
					RowNodes[i].className = (i % 2) ? 'RowOdd' : 'RowEven';
				}*/
	}
}


/**
*
*  Javascript sprintf
*  http://www.webtoolkit.info/
*
*
**/

sprintfWrapper = {

    init : function () {

        if (typeof arguments == 'undefined') { return null; }
        if (arguments.length < 1) { return null; }
        if (typeof arguments[0] != 'string') { return null; }
        if (typeof RegExp == 'undefined') { return null; }

        var string = arguments[0];
        var exp = new RegExp(/(%([%]|(\-)?(\+|\x20)?(0)?(\d+)?(\.(\d)?)?([bcdfosxX])))/g);
        var matches = new Array();
        var strings = new Array();
        var convCount = 0;
        var stringPosStart = 0;
        var stringPosEnd = 0;
        var matchPosEnd = 0;
        var newString = '';
        var match = null;

        while (match = exp.exec(string)) {
            if (match[9]) { convCount += 1; }

            stringPosStart = matchPosEnd;
            stringPosEnd = exp.lastIndex - match[0].length;
            strings[strings.length] = string.substring(stringPosStart, stringPosEnd);

            matchPosEnd = exp.lastIndex;
            matches[matches.length] = {
                match: match[0],
                left: match[3] ? true : false,
                sign: match[4] || '',
                pad: match[5] || ' ',
                min: match[6] || 0,
                precision: match[8],
                code: match[9] || '%',
                negative: (parseInt(arguments[convCount]) < 0) ? true : false,
                argument: String(arguments[convCount])
            };
        }
        strings[strings.length] = string.substring(matchPosEnd);

        if (matches.length == 0) { return string; }
        if ((arguments.length - 1) < convCount) { return null; }

        var code = null;
        var match = null;
        var i = null;

        for (i=0; i<matches.length; i++) {

            if (matches[i].code == '%') { substitution = '%' }
            else if (matches[i].code == 'b') {
                matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(2));
                substitution = sprintfWrapper.convert(matches[i], true);
            }
            else if (matches[i].code == 'c') {
                matches[i].argument = String(String.fromCharCode(parseInt(Math.abs(parseInt(matches[i].argument)))));
                substitution = sprintfWrapper.convert(matches[i], true);
            }
            else if (matches[i].code == 'd') {
                matches[i].argument = String(Math.abs(parseInt(matches[i].argument)));
                substitution = sprintfWrapper.convert(matches[i]);
            }
            else if (matches[i].code == 'f') {
                matches[i].argument = String(Math.abs(parseFloat(matches[i].argument)).toFixed(matches[i].precision ? matches[i].precision : 6));
                substitution = sprintfWrapper.convert(matches[i]);
            }
            else if (matches[i].code == 'o') {
                matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(8));
                substitution = sprintfWrapper.convert(matches[i]);
            }
            else if (matches[i].code == 's') {
                matches[i].argument = matches[i].argument.substring(0, matches[i].precision ? matches[i].precision : matches[i].argument.length)
                substitution = sprintfWrapper.convert(matches[i], true);
            }
            else if (matches[i].code == 'x') {
                matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
                substitution = sprintfWrapper.convert(matches[i]);
            }
            else if (matches[i].code == 'X') {
                matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
                substitution = sprintfWrapper.convert(matches[i]).toUpperCase();
            }
            else {
                substitution = matches[i].match;
            }

            newString += strings[i];
            newString += substitution;

        }
        newString += strings[i];

        return newString;

    },

    convert : function(match, nosign){
        if (nosign) {
            match.sign = '';
        } else {
            match.sign = match.negative ? '-' : match.sign;
        }
        var l = match.min - match.argument.length + 1 - match.sign.length;
        var pad = new Array(l < 0 ? 0 : l).join(match.pad);
        if (!match.left) {
            if (match.pad == '0' || nosign) {
                return match.sign + pad + match.argument;
            } else {
                return pad + match.sign + match.argument;
            }
        } else {
            if (match.pad == '0' || nosign) {
                return match.sign + match.argument + pad.replace(/0/g, ' ');
            } else {
                return match.sign + match.argument + pad;
            }
        }
    }
}

sprintf = sprintfWrapper.init;