window.allowresize = true;
$(document).ready(function() {
	
	var WindowHeight = $(window).height();
	var libreak = SizeContainer(WindowHeight);
	GetResults(libreak);
	
	$(window).bind("resize", resizeWindow);
	function resizeWindow( e ) {
		var WindowHeight = $(window).height();
		var libreak = SizeContainer(WindowHeight);
		if(window.allowresize) GetResults(libreak);
	}

	/*$(window).resize(function() {
		alert($(window).height());
	})*/
	
	
});

function SizeContainer(WindowHeight){
	if($(window).height()>=720){
		return '3';
	}
	else {
		return '2';
	}
} 

var ajaxcall;

function GetResults(libreak) {	
	var showNiveau = 'false';
	var result = $('#nieuws');
	var show = $('#show').html();

	 if(ajaxcall && ajaxcall.readystate != 4){
            ajaxcall.abort();
        }

	
	ajaxcall = $.ajax({
		type: "POST",
		datatype: "html",
		cache: false,
		url: "http://www.hockeyspecialisten.nl/nieuws/ajax.php",
		targetDiv: result, 
		data: { 
			show: show,
			libreak: libreak
		},
		success: function(msg){
			$(this.targetDiv)
				.delay(200) 
				.html(msg);
				
			$("a.bericht").click(function(){
				allowresize = false;
			});
			
			$("a.bericht").fancybox({
				'hideOnContentClick': true,				
			});	
			
			$("a.group").fancybox({
				'padding': 0,
				'overlayOpacity': 0.7,
				'overlayColor': '#000',
			});
			
			allowresize = true;
			
			jQuery(function( $ ){
	
				$('#slideshow').each(function() {
				
					$("#items .prev").hide();
					slidePos = 0;
					slideWidth = 200;
					slideSize = $("li", this).size();
					function nextSlide() {
					
						if(slidePos < 0)
							slidePos = slideSize - 3;
						if(slidePos > slideSize - 3)
							slidePos = 0;
							
						if(slidePos == 1)
							$("#items .prev").show();
							
						if(slidePos == 0)
							$("#items .prev").hide();
							
						if(slidePos == slideSize - 3)
							$("#items .next").hide();
							
						if(slidePos == slideSize - 4)
							$("#items .next").show();
					
						$("#slideshow ul").stop(true, false).animate({left: -slidePos * slideWidth});
					
					}
					
					$("#items .prev").click(function() {
					
							slidePos--;
							nextSlide();
					
					});
					
					$("#items .next").click(function() {
					
							slidePos++;
							nextSlide();
					
					});
				
				});
				
			});
			
		}
	});
	
};
