 /*
 * jQuery Active Session 1.1
 * For use with BigCommerce hosted sites ONLY
 * Author: Ian Hallworth
 * http://www.hallworthdesign.co.uk
 * Date: 26 Oct 2010
 * Depends on: jQuery core - http://docs.jquery.com/Downloading_jQuery
 * Depends on jquery.ba-nth-last-child.min.js - http://benalman.com/projects/jquery-misc-plugins/
 */
 $(document).ready(function(){ 
	// get the url
	var $path = location.pathname; 
	// initialise variables 
	var $currentPage, $WhichList; 
	// Get the text of the last item in the first breadcrumb list
	var $breadcrumbLast = $('.Breadcrumb ul:first-child li:last').text();
	// Get the text of the penultimate item in the first breadcrumb list
	var $breadcrumbPenultimate = $('.Breadcrumb ul:first-child li:nth-last-child(2)').text();
	
	// uncomment the line below to test what you're actually getting
	// alert("Penultimate Item = " + $breadcrumbPenultimate + "Last Item=" + $breadcrumbPenultimate);
	
	// products always contain /products/ in the url string so look for it
	if ($path.match('/products/')) {
		// we have a match, get the *penultimate* list item from the first list
		// this will give you the brand or category name
		$currentPage = $breadcrumbPenultimate;
		$WhichList = '#SideCategoryList';
	}
	else if ($path.match('/categories/')){
		// if it's category page, get the last breadcrumb item 
		$currentPage = $breadcrumbLast;
		// target the category list
		$WhichList = '#SideCategoryList';
	}
	else if ($path.match('/brands/')){
		// if it's brand page, get the last breadcrumb item
		$currentPage = $breadcrumbLast
		// target the shopbybrand list
		$WhichList = '#SideShopByBrand';
	}	
	// go through every item in the chosen list
	$($WhichList+' ul li').each(function() {
		// get the text for the list item 
		text = $(this).text();
		if (text.match($currentPage)) {
			// Add a class to the list item if you find a text match and return
			return $(this).addClass('ActiveSection');
		}
	})	
});

