/*
	File: LeftNavAccordian.js
	Author: Nick Barcomb
	Completed: 9-29-11
	Documented: 9-29-11
	Abstracted: 95%
	Developed for v7 Infant Toys Redesign Fisher-Price
	FUNCTIONS:
		leftNav(); Holds runtime and interactive collapsible nav actions
	Updated:
	
	NOTES:
		This requires that css hides the ul.
*/
function leftNav(){ // LEFT NAV ACCORDIAN function
var nav = '#left-nav'; // Base selector of the Nav as our starting point for jQeury
var query = 'pcat'; // The parameter in the URL to validate against
var speed = 250; // Speed of slide effect
var ease = 'swing'; // Easing of slide effect 'linier' and 'swing' are built into jQuery. For more, use jQueryUI
var active = 'active'; // The class that is toggled for the tab headers.
var queryregx = /[^A-Za-z0-9_-]/i; // Any characters that should not be in a class name
var querymatch = /=/i; // A character that should not be present when after we strip the url
var cleanQuery; // A cleaned version of the URL
var cleanQueryLi; // A cleaned version of the HREF
var getElement; // The formated version of cleanQuery to use as our jQuery selector
	cleanQuery = location.search.split(query+'=').pop().split('&').shift().replace(queryregx,''); // Gets and clean the current page's URL
	getElement = '.'+cleanQuery; // Formats cleanQuery to use as selector
	$(nav+' ul li').each(function(){ // When this is ready
		cleanQueryLi = $(this).find('a').attr('href').split(query+'=').pop().split('&').shift().replace(queryregx,''); // Gets and clean the current li tag's child's href
		$(this).addClass(cleanQueryLi); // Applies cleanQueryLi as a class the current li 
		if(!cleanQuery.match(querymatch)){ // If the formatted selector has an = sign then skip next
			$(nav+' ul '+getElement).parent().show(); // Opens ul based on the query parameter
			$(nav+' ul '+getElement).parent().parent().find('div').addClass(active); // Adds class to currently open header
		}else{
			$(nav+' ul').hide(); // Close all the query is incorrect (for non-thumbnails pages)
		}
	});
	$(nav+' div').click(function(){  // On a user click
		$(nav+' ul').not($(this).parent().find('ul')).slideUp(speed, ease); // Close all but current
		$(this).parent().find('ul').slideToggle(speed, ease); // Toggle open/close of current
		$(nav+' div').not($(this)).removeClass(active); // Remove class of all but current
		$(this).toggleClass(active); // Toggle class of current
	});
}
$(function(){ // When DOM is ready. Shorthand of $(document).ready
	leftNav(); // Calls function
});
