/* A wrapper for the show/hide functions of the third-party jQuery (1.2.1)
 *
 * @version: $Id: mnb_jquery.ext.js 46448 2009-09-16 18:23:52Z jasonbar $
 *
 * This script coordinates: div to div navigation, using show/hide jQuery
 * functions; calls to Google Analytics when those functions are used to
 * navigate between divs; random selection of testimonials.
 * 
 * .jsContent is a class assigned to each <div> that you want to function 
 *     as if it is a separate navigable destination (a separate web page).
 *     Each div in this class must have a unique id.
 *
 * .jsContent2 is a class assigned to each <li> that holds a breadcrumb. 
 *     Each div in this class must have a unique id. Although there is no 
 *     technical restriction, I've used the convention is that this id 
 *     should begin with the related .jsContent id +'_breadcrumb'.
 *
 *     For the home page, the navigation is in a separate div id="icons".
 *     For other pages, this div "icons" caps .jsContent divs, which may 
 *     or may not contain the navigation between divs / related pages.
 *
 *     For simplified (html-coded) state tracking, the navigation may be 
 *     replicated in each div, with the current visible div indicated.
 */



/* This $(document).ready() function 
 *
 *		If the url query string contains "d=" or "solution=" with the id of a valid element,
 *			shows this element, which now may be initially hidden,
 *			shows a matching element with the same name + "_breadcrumb", which now may be initially hidden,
 *			hides any other .jsContent element such as <div class="jsContent"> and
 *			hides any other .jsContent2 breadcrumbs such as <li class="jsContent2">,
 *		or, if no valid element in the query string,
 *			the first .jsContent element on the page must not be hidden,
 *			the first .jsContent2 element on the page must not be hidden,
 *			hides all but the first instance of <div class="jsContent">,
 *			hides all but the first instance of <li class="jsContent2"> and
 *			hides all instances of <div class="faqContent">.
 *
 *		Do not hide (style="display:none;") any items you want shown by default (no query string).
 */

$(document).ready(function(){
	var id = GetQueryVals('d');
	var nav_group = '';

	if (!id)
		id = GetQueryVals('solution');

	if (id && $('#' + id))
	{
		nav_group = $('#' + id).attr('class').replace(/\s.*/, '');

		if ($('#' + id + '_breadcrumbs'))
		{
			$('.navContentBc:not(#' + id + '_breadcrumbs)').hide();
			$('#' + id + '_breadcrumbs').show();
		}

		$('.' + nav_group + ':not(#' + id + ')').hide();
		$('#' + id).show();
	}
	
	if (nav_group != 'navContent')
	{
		$('.navContentBc:not(:first)').hide();
		$('.navContentBc:first').show();
		$('.navContent:not(:first)').hide();
		$('.navContent:first').show();
	}
	
	$('#breadcrumbs').css('visibility', 'visible');
});

/**
 * On page block level navigation (+ breadcrumb trail)
 * @param string id to show
 * @param [boolean Track via Google Analytics :: true]
 * @return true if nav change, false otherwise
 * @todo this needs to be moved.
 */
function PageNav(id, gat_track)
{
	if (typeof gat_track != 'boolean')
		gat_track = true;

	if (id && $('#' + id))
	{
		$('#' + id);
		var nav_group = $('#' + id).attr('class').replace(/\s.*/, '');

		if ($('#' + id + ':hidden'))
		{
			$('.' + nav_group).hide();
			$('#' + id).show();
			
			if ($('#' + id + '_breadcrumbs'))
			{
				$('.navContentBc:not(#' + id + '_breadcrumbs)').hide();
				$('#' + id + '_breadcrumbs').show();
			}
			
			if (gat_track == true)
				OnPageGat(window.document.location.pathname + '/mnb_jquery/' + id + '.div');

			return true;
		}
		else
		{
			if ( nav_group != "navContent" )
			{
				$elem.hide();
			}
			return true;
		}
	}
	
	return false;
}