function init()
	{
		var leftnav = document.getElementById('left');
		var items = leftnav.getElementsByTagName('li');
		// break the cookie string into an array items separated by a pipe
		var open = adultmenu.split("|");
		// loop over all of the list items found in leftnav
		for (var i=0; i<items.length; i++)
		{
			// check to see if a list item contains its own list
			if (items[i].getElementsByTagName('ul').length > 0) {
				// if a list item contains its own list, attach the toggle_menu function to the list item
				items[i].getElementsByTagName('a')[0].onclick = toggle_menu;
				// if a list item contains its own list, check the cookie to see if the sublist should be open, otherwise collapse it.
				// loop through the cookie items to see if the current list item is listed in the cookie - listed items should be open
				var collapse=true;
				for (j=0;j<open.length;j=j+1)
				{
					if(items[i].id == open[j])
						collapse = false;
				}
				if (collapse)
				{
					items[i].getElementsByTagName('ul')[0].style.display = "none";
				}
			}
		}
		//alert("Initial menu state...  expand " + adultmenu);
		setRandomBackground();
	}

function setRandomBackground()
{ return true;
}

function toggle_menu()
	{
		//alert("prior to the update, the cookie contains: " + adultmenu);
		var submenu = this.parentNode.getElementsByTagName('ul')[0];
		var listname = this.parentNode.id;
		if (submenu.style.display == "none") {
			//alert("show");
			submenu.style.display = ""
			adultmenu =  adultmenu + "|" + listname
		} else {
			//alert("hide");
			submenu.style.display = "none";
			var search = new RegExp("\\|" + listname, "gi");
			adultmenu = adultmenu.replace(search,'');
		}
		var listname = this.parentNode.id;
		//alert("after to the update, the cookie contains: " + adultmenu);
		setcookie("adultmenu",adultmenu,1);
	}

function getcookie(cookiename)
	{
		var cookiestring=""+document.cookie;
		var index1=cookiestring.indexOf(cookiename);
		if (index1==-1 || cookiename=="") return "";
		var index2=cookiestring.indexOf(';',index1);
		if (index2==-1) index2=cookiestring.length;
		return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
	}

function setcookie(name,value,duration)
	{
		cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration)+";PATH=/adult/;";
		document.cookie=cookiestring;
		if(!getcookie(name)){
		return false;
		}
		else{
		return true;
		}
	}

function getexpirydate(nodays)
	{
		var UTCstring;
		Today = new Date();
		nomilli=Date.parse(Today);
		Today.setTime(nomilli+nodays*24*60*60*1000);
		UTCstring = Today.toUTCString();
		return UTCstring;
	}

var adultmenu= getcookie("adultmenu");
if(adultmenu == "")
  adultmenu = "0";

window.onload = init;
