function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);

	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} 
	else
		begin += 2;

	var end = document.cookie.indexOf(";", begin);

	if (end == -1)
		end = dc.length;

	return unescape(dc.substring(begin + prefix.length, end));
}

// List all category id's 
menus_array = new Array ();
menus_status_array = new Array (); // remembers state of switches
<!-- img_close = 'http://'+document.domain+'/templates/default/images/main/menu-collapse.png'; -->
<!-- img_open = 'http://'+document.domain+'/templates/default/images/main/menu-expand.png'; -->

function toggleCategory (category_id) {

	if (document.getElementById) {
		var category = document.getElementById('cat'+category_id);
		var button_id = document.getElementById('cat'+category_id+'button');
		var category_parent_id = document.getElementById('cat'+category_id+'parent');

		if (menus_status_array[category_id] == 'hide' || typeof(menus_status_array[category_id]) == "undefined") {
			showCategory(category_id,1);
		}
		else {
			hideCategory(category_id,1);
		}
	}
}

function toggleCategoryHover (category_parent_id) {
	category_parent_id_1 = category_parent_id.replace(/cat/i, "");
	category_id = category_parent_id_1.replace(/button/i, "");

	if (document.getElementById) {
		var category = document.getElementById('cat'+category_id);
		var button_id = document.getElementById('cat'+category_id+'button');
		var category_parent_id = document.getElementById('cat'+category_id+'parent');

		if (menus_status_array[category_id] == 'hide' || typeof(menus_status_array[category_id]) == "undefined") {
			showCategory(category_id,1);
		}
		else {
			hideCategory(category_id,1);
		}
	}
}

function hideCategory (category_id,writecookie) {
	var category = document.getElementById('cat'+category_id);
	var button_id = document.getElementById('cat'+category_id+'button');
	var category_parent_id = document.getElementById('cat'+category_id+'parent');
	
	<!-- button_id.style.background = "url('"+img_open+"') top left;"; -->
	button_id.className = 'arrow arrow-expand';
	category_parent_id.className = 'item parent cat-close';
//	category.style.display = 'none';
	$j(category).toggle("fast");

	menus_status_array[category_id] = 'hide';

	if(writecookie == 1)
		document.cookie = 'cat'+category_id+'=hide;path=/';
}
function showCategory (category_id,writecookie) {
	var category = document.getElementById('cat'+category_id);
	var button_id = document.getElementById('cat'+category_id+'button');
	var category_parent_id = document.getElementById('cat'+category_id+'parent');

	<!-- button_id.style.background = "url('"+img_close+"') top left;"; -->
	button_id.className = 'arrow arrow-collapse';	
	category_parent_id.className = 'item parent cat-open';	
//	category.style.display = 'block';
	$j(category).toggle("fast");
	menus_status_array[category_id] = 'show';

	if(writecookie == 1)
		document.cookie = 'cat'+category_id+'=show;path=/';
}
function resetMenu () { // read cookies and set menus to last visited state
	if (document.getElementById) {
		for (var i=0; i<menus_array.length; i++) {
			var category_id = menus_array[i];
			var category = document.getElementById('cat'+category_id);
			var button_id = document.getElementById('cat'+category_id+'button');
			var item_id = document.getElementById('cat'+category_id+'item');

			if (getCookie('cat'+category_id) == 'show')
				hideCategory(category_id,0);
			else if(getCookie('cat'+category_id) == 'hide')
				showCategory(category_id,0);
			else {
				hideCategory(category_id,0);
			}
		}
	}
}

