$().ready(function(){
	var ran_unrounded=Math.random()*7;
	var ran_number=Math.floor(ran_unrounded);
	$('body').css('background','url(/lib/styles/images/body-bg-'+ran_number+'.jpg) no-repeat');
	$('.newsitem').each(function(){
		$oNewsitem = $(this);
		$(this).find('img:first').each(function(){
			if( !$('body').hasClass('home') ){
			$imgSrc = $(this).attr('src');
			$imgHeader = $('<div class="imgheader"><img src="'+$imgSrc+'"/></div>')
			$oNewsitem.before($imgHeader);
			}
			$(this).remove();
		})
	})
	$('.nieuws #main-content').each(function(){
		$oNewsitem = $(this);
		$(this).find('img:first').each(function(){
			if( !$('body').hasClass('home') ){
				$imgSrc = $(this).attr('src');
				$imgHeader = $('<div class="imgheader"><img src="'+$imgSrc+'"/></div>')
				$('#sub-content').prepend($imgHeader);
			}
			$(this).remove();
		})
	})
	initLinks();
	
	$('#frmQuery').focus(function(){
		if( $(this).val() == '...zoeken' ){
			$(this).val('');
		}
	});
	$('#frmQuery').blur(function(){
		if( $(this).val() == '' ){
			$(this).val('...zoeken');
		}
	})
	
	$('.lightbox a').lightBox({fixedNavigation:false, txtImage: 'Afbeelding', txtOf: 'van'});
	
	
});

function initLinks(){
	
	$('a').each(function(){
		test = $(this).attr('href');
		
		if( test.substr(0,7) == 'http://' ){
			$(this).addClass('extern');
			$(this).attr('target','_blank');
		}

	})
}

// Iframes
$(document).ready(function()
	{
		// Set specific variable to represent all iframe tags.
		var iFrames = document.getElementsByTagName('iframe');

		// Resize heights.
		function iResize()
		{
			// Iterate through all iframes in the page.
			for (var i = 0, j = iFrames.length; i < j; i++)
			{
				// Set inline style to equal the body height of the iframed content.
				nHeight = iFrames[i].contentWindow.document.body.offsetHeight+ 20;
				iFrames[i].style.height =  nHeight + 'px';
			}
		}

		// Check if browser is Safari or Opera.
		if ($.browser.safari || $.browser.opera)
		{
			// Start timer when loaded.
			$('iframe').load(function()
				{
					setTimeout(iResize, 0);
				}
			);

			// Safari and Opera need a kick-start.
			for (var i = 0, j = iFrames.length; i < j; i++)
			{
				var iSource = iFrames[i].src;
				iFrames[i].src = '';
				iFrames[i].src = iSource;
			}
		}
		else
		{
			// For other good browsers.
			$('iframe').load(function()
				{
					// Set inline style to equal the body height of the iframed content.
					nHeight = this.contentWindow.document.body.offsetHeight+20;
					this.style.height = nHeight + 'px';
				}
			);
		}
	}
);

