$(document).ready(function() {

	// Hide all questions
	$('li.toOpen p, li.toOpen ul').hide();
	
	// Question behavior
	$('li.toOpen h4').css({cursor: "pointer"});
	$('li.toOpen h4').click(function() {
		$('li.toOpen h4.opened ~ p, li.toOpen h4.opened ~ ul').slideUp();
		$('li.toOpen h4.opened').removeClass('opened');
		
		$(this).siblings('p, ul').slideDown();
		$(this).addClass('opened');
	});
	
	// =================
	// = Floating menu =
	// =================
	// var menuname = "#floatMenu";
	// var menulock = null;
	// menulock = parseInt($(menuname).css("top").substring(0,$(menuname).css("top").indexOf("px")))
	// 
	// $(window).scroll(function () { 
	// 	if($(document).scrollTop() > menulock) {					
	// 		offset = $(document).scrollTop()+20 +"px";
	// 	} else {
	// 		offset = menulock;	
	// 	}
	// 	$(menuname).animate({top:offset},{duration:500,queue:false});
	// });
	
	// Menu highlite
	$('#floatMenu li a').click(function(event) {
		$('#floatMenu a').removeClass("currentsidenav");
		$(this).addClass('currentsidenav');
		
		var target_y = $("a[name='"+ $(this).attr('href').substring(1) +"']").offset().top;
		target_y = target_y - ($(this).offset().top - $('#floatMenu').offset().top);
		
		$('#floatMenu').animate({
			top: target_y
		});
		
		event.preventDefault();
		
	});
	// ================
	
	
	// jQuery LocalScroll
	// Process links in the menu
	$('#floatMenu, a.backtotop').localScroll();
	
	$('a.backtotop').click(function () {
		$("#first_menu_item").trigger('click');
		$.scrollTo('body');
	})

// ========================

});
