var running = false;
var to1;
var to2;
var second = false;

function selectMenu(sub) {
    clearTimeout(to1);
    clearTimeout(to2);
    running = false;
    if(!sub) {
        sub = menu;
    }

	document.getElementById('sub_nav').style.display = 'none';
	document.getElementById('sm_startpagina').style.display = 'none';
	document.getElementById('sm_voeding').style.display = 'none';
	document.getElementById('sm_beweging').style.display = 'none';
	document.getElementById('sm_ontspanning').style.display = 'none';
	document.getElementById('sm_verzorging').style.display = 'none';
	// document.getElementById('sm_zelftest').style.display = 'none';
	document.getElementById('sm_forum').style.display = 'none';
	
	document.getElementById('sm_' + sub).style.display = 'block';
    
}

function startMenuTimer() {
    running = true;
    var to2 = setTimeout('returnMenu()', 2000);
    clearTimeout(to1);
}

function returnMenu() {
    if(running == true) {        
        if(second == false) {
            var to1 = setTimeout('returnMenu()', 300);
            second = true;
            selectMenu();
        } else {
            var to1 = setTimeout('returnMenu()', 2000);
            selectMenu();
        }
    }
}

function stopMenuDelay() {
    running = false;
    clearTimeout(to1);
    clearTimeout(to2);
}

$(function() {
	var liCount;
	var ulClass;
	
	$('.d-block:even').each(function() {
		$(this).addClass('d-block-even');
	});
	
	$('.side-list-main').each(function() {
		liCount = $(this).find('li').size();
		moreLiCount = $(this).parent().parent().find('.side-list-meer li').size();
		if(liCount == 7 && moreLiCount > 1) {
			$(this).find('.meer-dossiers-button').fadeIn(100);
		}
	});
	
	$('.meer-dossiers-button').click(function() {
		$(this).slideUp(200, function() {
			$(this).parent().parent().parent().parent().find('.side-list-meer').slideDown(500);
		});
	});
	
	$('.minder-dossiers-button').click(function() {
		$(this).parent().parent().parent().find('.side-list-meer').slideUp(500, function() {
			$(this).parent().find('.meer-dossiers-button').slideDown(200);
		});
	});
	
	$('h1.d-side').click(function() {
		ulClass = $(this).attr('id');
		if($(this).find('span').hasClass('doc-count')) {
			$(this).find('.doc-count').removeClass('doc-count').addClass('doc-count-less');
			$('.' + ulClass).slideDown(500);
		} else {
			$(this).find('.doc-count-less').removeClass('doc-count-less').addClass('doc-count');
			$('.' + ulClass).slideUp(500);
		}
	});
	
	$('.tr_startpagina').click(function() {
		title = document.title;
		url = window.location;

		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else if(window.opera && window.print) { // Opera Hotlist
			return true;
		}
	});
});