
///////////////////
// dom is loaded //
///////////////////

var init = function() {
	// preload some images
	preloadImages(SiteConfig.ImagesFolderPath + 'images/leftcol/nav_highlight.gif', SiteConfig.ImagesFolderPath + 'images/rightcol/more_bg.gif');
	
	// if this is a new session set a cookie appropriately
	if (Cookie.get("newSession") == false) {
		Cookie.set("newSession", "yes", { duration: false });
	} else {
		Cookie.set("newSession", "no", { duration: false });
	}
	
	// if the user has javascript enabled then disable the style_nojs.css stylesheet
	$('noJsStyles').disabled = true;
	
	<!-- primary navigation -->

	// initialize fx.accordion
	var togglers = $$("img.navToggler"); 
	var stretchers = $$("div.stretcher");
	myAccordion = new Fx.Accordion(togglers, stretchers ,{
		duration:350,
		alwaysHide: true,
		start: true,
		onActive: function(toggler) { toggler.setProperty("src", SiteConfig.ImagesFolderPath + "images/leftcol/nav_minus.gif"); },
		onBackground: function(toggler) { toggler.setProperty("src", SiteConfig.ImagesFolderPath + "images/leftcol/nav_plus.gif"); },		
		transition:Fx.Transitions.sineInOut
	});
		
	// all nav stretchers start out hidden, now that the accordion is initialized make them visible
	stretchers.each(function(el){el.setStyle('display', 'block')});	

	// highlight active nav element
	var activeNav = (SiteConfig.current_page === undefined) ? "Home" : SiteConfig.current_page;
	$(activeNav).setStyle('background', 'url(' + SiteConfig.ImagesFolderPath + 'images/leftcol/nav_highlight_active.gif) no-repeat top left');
	
	// open the correct nav stretcher
	myAccordion.showThisHideOpen(SiteConfig.nav_opener);

	// set mouseover actions for the nav element highlights
	$$('.navHighlight').each(function(el){
		el.addEvent('mouseover', function() {	el.addClass('navHighlightOver'); });
		el.addEvent('mouseout', function() { el.removeClass('navHighlightOver'); });
	});	
	
	<!-- featured solution -->

	// initialize slideshow class
	var featuredSolution = new slideShow({
		slides: $$("div.featuredSolution"),
		prevButton: $$("img.featuredPrev"),
		nextButton: $$("img.featuredNext"),
		initialSlide: "random"
	});
	
	// capture enter button press to submit search form
	$E('html').addEvent('keydown', function(event) {
		event = new Event(event);
		if (event.key == 'enter') {
			SiteConfig.validate_search(SiteConfig.searchBoxID);
			return false;
		}
	});
};

window.addEvent('domready', init);

////////////////////
// page is loaded //
////////////////////

var init_extended = function() {	

	<!-- related content -->
	if ($('relatedContent')) {
		// fix related content height (must be an odd number for the bg image to display correctly)
		var n = $('relatedContent').offsetHeight.toInt();
		if (n%2 == 0) {	n++; $('relatedContent').setStyle('margin-bottom','-1px'); }
		// swap the true related content div for the proxy div and unhide it
		$('relatedProxy').replaceWith($('related'));
		$('related').setStyle('visibility','visible');
	}
	
	<!-- quote content -->
	if ($('quoteContent')) {
		// fix related content height (must be an odd number for the bg image to display correctly)
		var n = $('quoteContent').offsetHeight.toInt();
		if (n%2 == 0) {	n++; $('quoteContent').setStyle('margin-bottom','-1px'); }
		// swap the true related content div for the proxy div and unhide it
		$('quoteProxy').replaceWith($('quote'));
		$('quote').setStyle('visibility','visible');
	}

	<!-- more bar -->
	// make sure more bar element is present
	if ($(SiteConfig.moreBarID)) {
		// initialize fx.slide and hide the more bar initially
		var moreSlide = new Fx.Slide(SiteConfig.moreBarID, { duration:350 });
		moreSlide.hide();
	
		// if this is a new session then make sure the more bar is not hidden, after a short delay open it
		if (Cookie.get("newSession") == "yes") {	
			$(SiteConfig.moreBarID).setStyle('display', 'block');
			var openMoreBar = (function() {moreSlide.toggle('vertical');}).delay(250);
			// set more bar status to show
			Cookie.set("moreBarStatus", "show", { duration: false });
		}	else {
			toggleMoreBar();
		}
	
		// function to toggle the more bar
		function toggleMoreBar() {
			if ($E('a', SiteConfig.moreButtonID)) {
				// make sure more bar is visible
				$(SiteConfig.moreBarID).setStyle('display', 'block');
				// store a copy of our cookie
				action = Cookie.get("moreBarStatus");
				// remove button class so it can be changed conditionally
				$E('a', SiteConfig.moreButtonID).removeClass('moreButtonUp');  
				$E('a', SiteConfig.moreButtonID).removeClass('moreButtonDown');
				// hide or show the more bar
				if (action == "hide") {
					$E('a', SiteConfig.moreButtonID).addClass('moreButtonUp');
					moreSlide.hide();
				} else {
					$E('a', SiteConfig.moreButtonID).addClass('moreButtonDown');
					moreSlide.show();
				}
			}
		}

		// function to toggle the more button
		function toggleMoreButton() {
			if ($E('a', SiteConfig.moreButtonID)) {
				if ($E('a', SiteConfig.moreButtonID).hasClass('moreButtonDown')) {
					$E('a', SiteConfig.moreButtonID).removeClass('moreButtonDown');
					$E('a', SiteConfig.moreButtonID).addClass('moreButtonUp');
					// more bar should be hidden on next page load
					Cookie.set("moreBarStatus", "hide", { duration: false });
				} else {
					$E('a', SiteConfig.moreButtonID).removeClass('moreButtonUp');
					$E('a', SiteConfig.moreButtonID).addClass('moreButtonDown');
					// more bar should be shown on next page load
					Cookie.set("moreBarStatus", "show", { duration: false });
				}
			}
		}

		// set the more bar button actions
		$(SiteConfig.moreButtonID).addEvent('click', function() { 
			// make sure more bar is visible
			$(SiteConfig.moreBarID).setStyle('display', 'block');
			// toggle slide animation and more button
			moreSlide.toggle('vertical').chain(function(){ toggleMoreButton() });
		});
	}

}

window.addEvent('domready', init_extended);