function cookieSet(index) {
	jQuery.cookie(index, 'opened', {expires: null, path: '/'}); // Set mark to cookie (submenu is shown):
}

function cookieDel(index) {
	jQuery.cookie(index, null, {expires: null, path: '/'}); // Delete mark from cookie (submenu is hidden):
}

/*function cookieSet(index, id) {
	jQuery.cookie('submenuMark-' + index, id, {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):
}*/


jQuery(document).ready(function () {
											
	/*cookieSet(0);*/
	//alert(opened);
	
	jQuery('ul#left-menu ul').each(function(i) { // Check each submenu:
		//if (jQuery.cookie('submenuMark-' + i) == jQuery(this).attr('id')) {  // If index of submenu is marked in cookies:
		if (jQuery.cookie(jQuery(this).attr('id'))) {  // If index of submenu is marked in cookies:
			//jQuery(this).show().prev().removeClass('ico_plus').addClass('ico_minus'); // Show it (add apropriate classes)
		}else {
			jQuery(this).hide().prev().removeClass('ico_minus').addClass('ico_plus'); // Hide it
		}
		jQuery(this).prev().addClass('collapsible').click(function() { // Attach an event listener
			var this_i = jQuery('ul#left-menu ul').index($(this).next()); // The index of the submenu of the clicked link
			if ($(this).next().css('display') == 'none') {
				jQuery(this).next().slideDown(200, function () { // Show submenu:
					jQuery(this).prev().removeClass('ico_plus').addClass('ico_minus');
					//cookieSet(this_i);
					//cookieSet(this.id);
				});
			}else {
				jQuery(this).next().slideUp(200, function () { // Hide submenu:
					jQuery(this).prev().removeClass('ico_minus').addClass('ico_plus');
					//cookieDel(this.id);
					jQuery(this).find('ul').each(function() {
						jQuery(this).hide(0, cookieDel($('ul#left-menu ul').index($(this)))).prev().removeClass('ico_minus').addClass('ico_plus');
					});
				});
			}
		return false; // Prohibit the browser to follow the link address
		});
	});
	
	if(opened != ''){jQuery('ul#' + opened).show().prev().removeClass('ico_plus').addClass('ico_minus');}


	jQuery("#callback_link").fancybox({
		'width'           : 450,
		'height'          : 400,
		'padding'			: 1,
		'scrolling'			: false,
		'autoScale'       : true,
		'overlayColor'    : '#000000',
		'transitionIn'    : 'none',
		'transitionOut'   : 'none',
		'type'            : 'iframe'
	});
	
	jQuery(".callback_link").fancybox({
		'width'           : 450,
		'height'          : 400,
		'padding'			: 1,
		'scrolling'			: false,
		'autoScale'       : true,
		'overlayColor'    : '#000000',
		'transitionIn'    : 'none',
		'transitionOut'   : 'none',
		'type'            : 'iframe'
	});
	
	jQuery("#feedback_link").fancybox({
		'width'           : 450,
		'height'          : 400,
		'padding'			: 1,
		'scrolling'			: false,
		'autoScale'       : true,
		'overlayColor'    : '#000000',
		'titleShow'       : false,
		'transitionIn'    : 'none',
		'transitionOut'   : 'none',
		'type'            : 'iframe'
	});
	
	$('#login_link').fancybox({
		'padding' : 0,
		'titleShow' : false,
		'overlayColor' : '#000',
		'overlayOpacity' : 0.9
	});
	
	$('#reg_link').fancybox({
		'padding' : 0,
		'titleShow' : false,
		'overlayColor' : '#000',
		'overlayOpacity' : 0.9
	});
	
	$(".video").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});

});
