<!--
// ==============================
// SET VARIABLES
// ==============================


// ==============================
// RUN ALL ONLOAD JQUERY COMMANDS
// ==============================
$(document).ready(function() {
	//var urlParts = parseURL();
	// ==============================
	// NAVIGATION
	// ==============================
	if (jQuery.browser.msie) {
		if (jQuery.browser.version == '7.0') {
			// Fixes a positioning bug related to the breadcrumbs
			var breadcrumbsHeight = $('#breadcrumbs').outerHeight();
			if (breadcrumbsHeight) {
				$('#docBody').css('margin-top', breadcrumbsHeight + 'px');
			}
		}
	}
	//	=============
	//	FONT SIZER
	//	=============
	$('#utility3 .plus').click(function() {
		var fontSize = $('body').css('font-size');
		fontSize = parseInt(fontSize.substr(0,fontSize.indexOf('p')));
		if (fontSize < 16) {
			fontSize += 1;
			$('body').css('font-size',fontSize);
		}
	});
	$('#utility3 .minus').click(function() {
		var fontSize = $('body').css('font-size');
		fontSize = parseInt(fontSize.substr(0,fontSize.indexOf('p')));
		if (fontSize > 11) {
			fontSize -= 1;
			$('body').css('font-size',fontSize);
		}
	});
	
	//	=================
	//	RIGHT SIDEBAR NAV
	//	=================
	//	Compute the background image for the on state.
	//	This enables the right nav on states to accomandate 2 and 3 line menu items.
	//	It's assumed that there will never be a 4 line menu item.
	//	Grab the on state menu item and store its vertical dimension
	var $sidebarOnLink = $('div#sidebarNav > ul > li > ul > li ul li.on a');
	var sidebarOnLinkHeight = $sidebarOnLink.outerHeight(true);
	/*	Test it's height and set the background image as necessary.
		We don't strive for pixel perfect accuracy here because the vertical dimensions
		vary from browser to browser, but these numbers should accomodate most everything. */
	if (sidebarOnLinkHeight > 40 && sidebarOnLinkHeight < 60) {
		$sidebarOnLink.css('background-image','url("/images/nav/sidebarNavOn-2.png")');
	} else if (sidebarOnLinkHeight > 60) {
		$sidebarOnLink.css('background-image','url("/images/nav/sidebarNavOn-3.png")');
	}
	
	//	===================
	//	MISC
	//	===================
	//	Section index blocks
	$('.section_index #mainContent .block:odd').after('<br clear="left" />');
	
	//	PUSH COMMENTS BELOW RIGHT SIDEBAR IF NECESSARY
	//	Calculate some needed data
	var rightSidebarPos = $('#mainContent #rightSidebar').position();
	if (rightSidebarPos) {
		var commentsPos = $('#mainContent #comments').position();
		var rightSidebarBottom = rightSidebarPos.top + $('#rightSidebar').outerHeight(true);
		//	If the right sidebar extends farther then the top of the comments section. Push it below the sidebar.
		if (commentsPos.top < rightSidebarBottom) {
			$('#mainContent #comments').css('margin-top', (rightSidebarBottom - commentsPos.top) + 'px');
		}
	}
	
	
	//	===================
	//	HOME PAGE SLIDESHOW
	//	===================
	// Initialize some variables and DOM states
	var currentHomePageSlide = 0;
	var totalHomePageSlides = $('.home #slideshow .slideImage').length;
	$('.home #slideshow .slideImage').hide();
	$('.home #slideshow .slideCaption').hide();
	$('.home #slideshow .slideImage:eq(0)').show();
	$('.home #slideshow .slideCaption:eq(0)').show();
	
	// Generate and initialize the control buttons
	for (i=0; i< totalHomePageSlides; i++) {
		$('.home #slideshow .controls').append('<div class="controlDot" ref="' + i + '"></div>');
	}
	$('.home #slideshow .controls .controlDot:eq(0)').addClass('on');
	
	// Respond to clicks on the control buttons. Only respond to buttons in an "off" state.
	$('.home #slideshow .controls .controlDot').click(function() {
		if (!$(this).hasClass('on')) {
			$(document).stopTime('homeSlideshow');
			_selectSlide($(this).attr('ref'));
		}
	});
	
	function _selectSlide(s) {
		// Passing an arg of -1 is for running the slideshow in an autoloop.
		if (s == -1) {
			if (currentHomePageSlide == totalHomePageSlides - 1) {
				slide = 0;
			} else {
				slide = currentHomePageSlide + 1;
			}
		} else {
			slide = s;
		}
		// Fade the images.
		$('.home #slideshow .slideImage:eq(' + currentHomePageSlide + ')').fadeOut(1000);
		$('.home #slideshow .slideImage:eq(' + slide + ')').fadeIn(1000, function () {
			// Cut to a new caption
        	$('.home #slideshow .slideCaption').hide();
			$('.home #slideshow .slideCaption:eq(' + slide + ')').show();
      	});
		// Change to a new button "on" state
		$('.home #slideshow .controls .controlDot').removeClass('on');
		$('.home #slideshow .controls .controlDot:eq(' + slide + ')').addClass('on');
		currentHomePageSlide = slide;
	}
	//	================
	//	ACCORDIAN ON HOME PAGE
	//	================
	$("#accordian").accordion();




	// Set the autoloop for the slideshow. This is canceled once a button is clicked.
	// The jquery.timers plugin throws a non-supported method error, it doesn't appear to break the functionality.
	// But it will break any jQuery that follows, so this must be the last set of code.
	$(document).everyTime(7000, 'homeSlideshow', function(i) {
		// Passing -1 invokes the loop.
 		 _selectSlide(-1);
	}, 0);
});
//-->  

