/*
       copyright 2009 Cornerstone All Rights Reserved
       Client: Cornerstone 
       Author: Cameron Wardzala - Rosetta 
       Date: 3/2/2009 
*/

function getParam(key) {
	  var href  = href || window.location.href;
	  var params  = href.slice(href.indexOf('?') + 1).split('&');
	  var returnParam = null;
	    jQuery.each(params, function() {
	      	var param = this.split('=');
	      	if(param[0] == key){returnParam = param[1];}
		});
    return returnParam;
  };

var jq = jQuery.noConflict();
function cs_nav_asess()
{
	var curpath = document.location.pathname;
	
	// determine the max amount of items in the array
	var count = curpath.length - 1;
	var ref = jq('#sideBox').find('a').each(function(){
		// account for href values that may have query strings
		var href = jq(this).attr('href').split("?", 2);
		// run the test and apply new class if returned true.

		var curItemIsActive = false;
		if (href[0] === curpath){
			if (curpath != "/WCMContentView" ) {
				curItemIsActive = true;
			} else {
				if(href[1].indexOf(getParam('contentKey')) > 0){
					curItemIsActive = true;
				}
			}
		}
		
		if (curItemIsActive) {
			if(jq(this).parent().hasClass('.group')){
				jq(this).parent('.group').addClass('on active');
			} else {
				jq(this).parent().parent().parent('.group').addClass('on');
				jq(this).parent().addClass('on active');
			}		
		}
		// this is code to highlight the featured stories that come from WWCM
		if(href[0] == 'FeatureStoriesArticleView' ) {
			if(href[1].indexOf(getParam('contentKey')) > 0){
				jq(this).parent().addClass('on active');
			}
		}
		
	});
}

jq(document).ready(function(){
	cs_nav_asess();
});

