
/*function initMenus() {
	
	$('ul.nav ul').hide();													
		
	$('ul.nav li a').click(									
		function() {
			var checkElement = $(this).next();          					// checkElement is the next element below one of the always visible anchors 
																					(this is a ul for expansion - a flydown)
			var parent = this.parentNode.parentNode.id; 					// parent is equal to the id of the ul containing the li containing 
																					the anchor - in other words the id of the outermost ul containing this navigation:
																			       (i.e.  ul id="leftNav")

																	 if the surrounding ul has class noaccordion - expand all it's child ul's:
			if($('#' + parent).hasClass('noaccordion')) {					// equiv to: if($(#leftnav.hasClass('noaccordion'))
				$(this).next().slideToggle('normal');						// equiv to the next ul for a flydown below the current always-visible anchor
																					- slide it down
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}
$(document).ready(function() {initMenus();});
*/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


$(document).ready(function () {
							
	$('.nav li:has(ul)>a').click(function() {
		$this = $(this);
		if(!$this.parent().is('.expanded')) {
			$this.parent().parent().find('.expanded').removeClass('expanded');
			$this.parent().addClass('expanded').find(">ul").slideDown();
		} else {
			$this.parent().removeClass('expanded');
		}
		$this.parent().parent().find('li:not(.expanded) ul').slideUp();
		
		// create cookie with indexes of expanded li's:
		var expandedItems = new Array();
		var dex = 0;
		$('.nav li.expanded').each(function () {
			expandedItems[dex] = $('.nav li').index(this);
			//console.log('expandedItems[' + dex + '] is ' + expandedItems[dex]);
			dex++;
		});
	
		
		var strExpandedItems = expandedItems.join(',');
		//console.log('strExpandedItems is ' + strExpandedItems);
		//console.log('=================================================');
		createCookie('navControl',strExpandedItems);
		
		return false;
	});
	

	$('.nav ul').hide();
	
	if(readCookie('navControl')) {
		var prevExpandedItems = new Array();
		strPrevExpandedItems = readCookie('navControl');
		////console.log('strPrevExpandedItems is ' + strPrevExpandedItems);
		prevExpandedItems = strPrevExpandedItems.split(',');
		/*if(strPrevExpandedItems.indexOf(',') > 0) {
			//console.log('       strPrevExpandedItems contains multiple items... ');
			prevExpandedItems = strPrevExpandedItems.split(',');	
		}
		else
		{
			prevExpandedItems[0] = strPrevExpandedItems;
			//console.log('       strPrevExpandedItems contains 0 or 1 items... ');
		}*/
		
		////console.log('            trying loop...');
		/*$.each(prevExpandedItems, function () {							
		})*/
		
		//method 1
		/*for(i = 0; i < prevExpandedItems.length; i++) {
			var theIndex = prevExpandedItems[i];
			var navLis = $('.nav li');
			$(navLis[theIndex]).addClass('expanded').find('>ul').show();
		} // end for*/
		
		//method 2
		$.each(prevExpandedItems, function (dex) {
			
			$('.nav li:eq(' + this + ')').addClass('expanded').find('>ul').show();								
		})
	
		////console.log('            loop finished...');
		
	}; // end if(readCookie('navControl'))
}); // end $(document).ready(function ()








