﻿/// <reference path="jquery-1.6.2.js" />

/*
*	Code Dependencies:
*	- "jquery-1.6.2.js"
*	- "dc.global.js"
*/

$(document).ready(function () {
	dc.site.pageNavigation();
});

// This is a Self-Executing Anonymous Function
// "dc" is the namespace for all of our code
// There should be no global "window" variables,
// they should all be created under the "dc" namespace. 
(function (dc, $, undefined) {
	// Hook jQuery Selector Caching Function to "$$"
	var $$ = dc.$$;

	// Create the "dc.site" namespace if it does not exist
	dc.site = (function (site) {
		
		/* Used on all pages with section navigation */
		/* Note: is replaced on some specialized pages like the location page */
		site.pageNavigation = function () {
			var $contentLoading = $$('#ContentLoading');
			$$('div.FeatureBoxesColumn, div.SectionContent').css('visibility', 'visible');
			var LogGoogleAnalytics = true;
			var $SectonContents = $$('div.SectionContent', '#MainContent div.ContentColumn');
			var $FeatureBoxContents = $$('div.FeatureBoxContent:not(.Sticky)', '#MainContent div.FeatureBoxesColumn');
			var $SectionNavLinks = $$('div.NavColumn ul li', '#MainContent');
			$SectonContents.hide();
			$FeatureBoxContents.hide();
			$SectionNavLinks.each(function (index, element) {
				var $NavLink = $(this);
				if ($NavLink.hasClass('Current') == true) {
					$SectonContents.eq(index).show();
					if ($FeatureBoxContents.eq(index).hasClass('SectionPlaceHolder') == false) {
						$FeatureBoxContents.eq(index).show();
					}
				}
				$('a', $NavLink).click(function (event) {
					event.preventDefault();
					if ($NavLink.hasClass('Current') == false) {
						$SectionNavLinks.removeClass('Current').eq(index).addClass('Current');
						$SectonContents.hide().eq(index).fadeIn();
						/* BEGIN - Google Analytics */
						if (LogGoogleAnalytics) {
							_gaq.push(['_trackPageview', $(this).attr('rel')]);
						} else {
							LogGoogleAnalytics = true; // Reset flag to log all section clicks to Google Analytics
						}
						/* END - Google Analytics */
						$FeatureBoxContents.hide();
						if ($FeatureBoxContents.eq(index).hasClass('SectionPlaceHolder') == false) {
							$FeatureBoxContents.eq(index).fadeIn();
						}
						this.blur();
					}
				});
			});
			$contentLoading.hide();
			/* Must include jquery.getQueryParam.1.0.0.min.js */
			/* Check query string for sid, if found show the corresponding section */
			var QuerySectionId = $.getQueryParam('sid');
			if (QuerySectionId != undefined) {
				LogGoogleAnalytics = false; // Set flag so as to not log this first programmatic section click to Google Analytics
				$('a', $SectionNavLinks).eq(QuerySectionId).click();
			}
		}

		// Return this instance of site
		return site;
	})(window.dc.site = window.dc.site || {});

})(window.dc = window.dc || {}, jQuery);
