$(document).ready(function () {
		
		var countCarouselImages = $(".carousel IMG").length; 
		var countCarouselLoadedImages = 0;
		
		$(".carousel IMG").each(function(){
			var img = new Image();
			var src =  $(this).attr('src');
			$(img).load(function () {
				countCarouselLoadedImages++;
				if ( countCarouselImages == countCarouselLoadedImages ) carousel();
			}).error(function () { }).attr('src', src);

		});		
		
		$('.video-lightbox UL LI A, ul.links li a.video').click(function(){
			$('.overlay').width($(document).width());
			$('.overlay').height($(document).height());
			$('.overlay').show();
			var arrPageSizes = ___getPageSize();
			var arrPageScroll = ___getPageScroll();
			$('.lightbox-video').css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
				left:	(arrPageSizes[0]/2) - ($('.lightbox-video').width()/2)
			}).show();
			$('.lightbox-video .close-link, .overlay').click(function(){
				if ( $('#player') ) $('#player').remove();
				$('.overlay').hide();
				$('.lightbox-video').hide();
				return false;
			});
			initPlayer('./',$(this).attr("alt"),'video-player-id');
			return false;
		});
		
		$('.footer a#disclaimer').click(function(){
			$('.overlay').width($(document).width());
			$('.overlay').height($(document).height());
			$('.overlay').show();
			var arrPageSizes = ___getPageSize();
			var arrPageScroll = ___getPageScroll();
			$('.disclaimer-box').css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
				left:	(arrPageSizes[0]/2) - ($('.disclaimer-box').width()/2)
			}).show();
			$('.disclaimer-box .close-link, .overlay').click(function(){
				$('.overlay').hide();
				$('.disclaimer-box').hide();
				return false;
			});
			return false;
		});
		
		$('.dropdown-button').click(function(){
			$('#dropdown-menu').slideToggle();
		});
		
		// PJ: Open link in new window to avoid target="_blank" which causes invalid xhtml strict
		$(function(){    
			$('a.new-window').click(function(){
				window.open(this.href);        
		   		return false;    
		   	});
		});
		
		$("button#zoekbtn").click(function()
		{
			$("#ZoekForm").submit();
		});
		
		$("input#logout").click(function()
		{
			location.href= "./index.php?action=kllgout";
		});
		
		$("body #page").fontScaler({
			target: '#page',
			containerclass: 'font-sizes',
			store:true,
			fixed: {size1: '100',size2: '120',size3: '140'}
		}); 
		
});

function initPlayer(path,file,id){
	var swf = new SWFObject(path+"/swf/player.swf","player","480","292","9","#fff");
	swf.addParam("movie", path+"/swf/player.swf");
	swf.addParam("allowfullscreen", "true");
	swf.addParam("allowscriptaccess", "always");
	swf.addParam("flashvars", "file="+file);
	swf.setAttribute('redirectUrl','http://get.adobe.com/flashplayer');
	swf.write(id);
}

function carousel(){
	$(".accommodatie-box .carousel").jCarouselLite({
	 	btnNext: ".accommodatie-box .next-btn",
		btnPrev: ".accommodatie-box .prev-btn",
		visible:3
	});
	$('.lightbox li a').lightBox({
		containerBorderSize: 18,
		fixedNavigation: false
	});
	$('.lightbox li a').click(function(){
		$('#lightbox-container-image-box').corner({
			  tl: { radius: 20 },
			  tr: { radius: 20 },
			  bl: { radius: 20 },
			  br: { radius: 20 }
		});
		$('#lightbox-container-image-data-box').css("display","none");
		if (!$('#lightbox-secNav-btnClose').hasClass('close-link')) $('#lightbox-secNav-btnClose').addClass('close-link');
		$('#lightbox-secNav-btnClose').text('SLUITEN X');
		$('#lightbox-container-image-box').prepend($('#lightbox-secNav-btnClose'));
		$('#lightbox-secNav-btnClose').css('position','absolute');
		$('#lightbox-secNav-btnClose').css('z-index','200');
		$('#lightbox-secNav-btnClose').css('right','-7px');
		$('#lightbox-secNav-btnClose').css('top','-36px');
	});
	

}

function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
function ___getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};
