// JavaScript Document
$(document).ready(function() {
	$('ul#leftMenu ul').each(function(i) { // Check each submenu:
		if ($.cookie('submenuMark-' + i)) {  // If index of submenu is marked in cookies:
			$(this).show().parent().addClass('click'); // Show it (add apropriate classes)
		} else {
			$(this).hide();
		}
		$(this).parent().find('a:eq(0)').click(function() { // Attach an event listener
			var this_i = $('ul#leftMenu ul').index($(this).parent().find('ul')); // The index of the submenu of the clicked link
			if ($(this).parent().find('ul').css('display') == 'none') {
				$(this).parent().find('ul').slideDown(200, function () { // Show submenu:
					$(this).parent().addClass('click').find('div.hover').stop().animate({opacity: 1}, 300);
					cookieSet(this_i);
				});
			} else {
				$(this).parent().find('ul').slideUp(200, function () { // Hide submenu:
					$(this).parent().removeClass('click').removeAttr('class');
					cookieDel(this_i);
					$(this).find('ul').each(function() {
						$(this).hide(0, cookieDel($('ul#leftMenu ul').index($(this)))).parent().removeClass('click').removeAttr('class');
					});
				});
			}
			return false; // Prohibit the browser to follow the link address
		});
	});
});
function cookieSet(index) {
	$.cookie('submenuMark-' + index, 'opened', {expires: null, path: '/'}); // Set mark to cookie (submenu is shown):
}
function cookieDel(index) {
	$.cookie('submenuMark-' + index, null, {expires: null, path: '/'}); // Delete mark from cookie (submenu is hidden):
}
