$(document).ready(function(){
	
	// lees meer functie
	$(".leesmeer").live('click',function(){
		var $leesmeer = $(this).attr("title")
		$("#instant").animate({"left": "-=765px"}, "slow");
		$("#nieuwscontent div").load("module/nieuws.php?id=" + $leesmeer);
		$(".open").toggleClass("vast");
		$(".open").removeClass("open");
		$("html, body").animate({scrollTop:0}, 'slow');
	});
	
	// hack om ul li vast te maken
	$(".open").live('click',function(){
		var $leesmeer = $(this).attr("title")
		$("#instant").animate({"left": "-=765px"}, "slow");
		$("#nieuwscontent div").load("module/nieuws.php?id=" + $leesmeer);
		$(".open").toggleClass("vast");
		$(".open").removeClass("open");
		$("html, body").animate({scrollTop:0}, 'slow');
	});
	$(".vast").live('click',function(){
		$("#nieuwscontent div").fadeOut("slow");
		var $leesmeer = $(this).attr("title")
		setTimeout(function(){
		$("#nieuwscontent div").load("module/nieuws.php?id=" + $leesmeer);
		$("#nieuwscontent div").fadeIn("slow");
		
		},1000);
		$("html, body").animate({scrollTop:0}, 'slow');
	});
	
	// terug functie
	$(".back").click(function(){
		$("#instant").animate({"left": "+=765px"}, "slow");
		$(".vast").addClass("open");
		$(".open").toggleClass("vast");
		$("html, body").animate({scrollTop:0}, 'slow');
		setTimeout(function(){
		$("#nieuwscontent div").html("");
		},1000);
	});
	
	// oudere berichten handmatig ophalen
	$(".oudereberichten").live('click',function(){
		
		var $tellen	= $("span.leesmeer").last().attr("title")
		$.get("module/nieuws.php?append=" + $tellen, function(data) {
			$(".oud").append(data);
			$(".bericht").fadeIn();

		})
		
	});
	
	// ga naar boven functie
	$(".boven").live('click',function(){
		$("html, body").animate({scrollTop:0}, 'slow');
	});
	
	// scroll load functie
	$(window).scroll(function(){
		if  ($(window).scrollTop() == $(document).height() - $(window).height()){
			$(".loading").fadeIn();
				setTimeout(function(){
					$(".loading").fadeOut();
					var $tellen	= $("span.leesmeer").last().attr("title")
					$.get("module/nieuws.php?append=" + $tellen, function(data) {
						$(".oud").append(data);
						$(".bericht").fadeIn();
					})
				},2000)
			
		}
	});
})
