function resizeBackground() {
  var bg = $('#background');
  var pageWidth = $(window).width();
  var pageHeight = $(window).height();

  var aspect = bg.width() / bg.height();
  var width = aspect * pageHeight ;
  var height = pageWidth / aspect;

  if (width < pageWidth)
  {
    width = height * aspect;
  }
  if (height < pageHeight)
  {
    height = width / aspect;
  }

  $('#background').width(width);
  $('#background').height(height);
  //$('#background').css('top', (pageHeight - height));
  //$('#background').css('left', (pageWidth - width));
}

function resizeBoontjeBox() {
	var pageHeight = $(window).height();
	var boxHeight = pageHeight - 75;
	var contentHeight = pageHeight - 85;
	$('#box-boontje').height(boxHeight);
	$('#box-boontje .box-content').height(contentHeight);
	//console.log('resize-boontjebox-check');
}

function resizeAdvocatenBox() {
	var pageHeight = $(window).height();
	var boxHeight = pageHeight - 75;
	var contentHeight = pageHeight - 85;
	$('#box-advocaten').height(boxHeight);
	$('#box-advocaten .box-content').height(contentHeight);
}

function resizeActueelBox() {
	var pageHeight = $(window).height();
	var boxHeight = pageHeight - 75;
	var contentHeight = pageHeight - 85;
	$('#box-actueel').height(boxHeight);
	$('#box-actueel .box-content').height(contentHeight);
}
function resizeArbeidsrechtBox() {
	var pageHeight = $(window).height();
	var boxHeight = pageHeight - 243;
	var contentHeight = pageHeight - 254;
	$('#box-arbeidsrecht').height(boxHeight);
	$('#box-arbeidsrecht .box-content').height(contentHeight);
}
function resizeContactBox() {
	var pageHeight = $(window).height();
	var boxHeight = pageHeight - 243;
	var contentHeight = pageHeight - 254;
	$('#box-contact').height(boxHeight);
	$('#box-contact .box-content').height(contentHeight);
}
$(function() {
	$(window).resize(function(){
		//var pageWidth = $(window).width();
		//console.log('pagewidth: '+pageWidth);
		resizeBackground();
		//resize boontjeBox
		if($('#box-boontje').length != 0) {
			resizeBoontjeBox();
		}
		//resize advocatenBox
		if($('#box-advocaten').length != 0) {
			resizeAdvocatenBox();
		}
		//resize actueelBox
		if($('#box-actueel').length != 0) {
			resizeActueelBox();
		}
		//resize arbeidsrechtBox
		if($('#box-arbeidsrecht').length != 0) {
			resizeArbeidsrechtBox();
		}
		//resize contactBox
		if($('#box-contact').length != 0) {
			resizeContactBox();
		}
		//resize lichtkrant
		if($('marquee').length != 0 ){
			var pageWidth = $(window).width();
			$('.lichtkrant').attr('width', pageWidth);
		}
		//doe de scrollpane nogmaals alstublieft
		$('.scrollpane').jScrollPane({
			showArrows: false,
			arrowSize: 0,
			scrollbarWidth: 27
		});
});
  //resize boonjteBox
  if($('#box-boontje').length != 0) {
	resizeBoontjeBox();
  }
  //resize advocatenBox
  if($('#box-advocaten').length != 0) {
	resizeAdvocatenBox();
	//$('#box-advocaten').hide();
	//$('#box-advocaten').show('slow');
  }
  //resize actueelBox
  if($('#box-actueel').length != 0) {
	resizeActueelBox();
  }
  //resize arbeidsrechtBox
  if($('#box-arbeidsrecht').length != 0) {
	resizeArbeidsrechtBox();
  }
  if($('#box-contact').length != 0) {
	resizeContactBox();
  }
  if($('#background').lenght != 0) { 
  	resizeBackground();
  }
  $('.scrollpane').jScrollPane({
		showArrows: false,
		arrowSize: 0,
		scrollbarWidth: 27
  });
  if($('marquee').length != 0) {
  	var pageWidth = $(window).width();
  	$('.lichtkrant').attr('width', pageWidth);
	//sta stil on mouseover en draggable
  	$('marquee').marquee('lichtkrant').mouseover(function () {
		$(this).trigger('stop');
	}).mouseout(function () {
		$(this).trigger('start');
	}).mousemove(function (event) {
		if ($(this).data('drag') == true) {
			this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
		  }
	}).mousedown(function (event) {
		$(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
	}).mouseup(function () {
		$(this).data('drag', false);
	});
	//maak onselecteerbaar ivm esthetiek
	//lichtkrant.onselectstart = function() { return(false); };
	}
	//maak print-link aan
	if($('.meta').length !=0 ) { 
		$('ul.meta').prepend('<li class="print"><a href="#print" title="print"><span>></span> print</a></li>');
		$('ul.meta li.print a').click(function() {
			window.print();
			return false;
	 	});
	}
});

