/*******************************************************************************
On page load.
*******************************************************************************/

$(function()
{		
	$('#listing .item').hover(
		function(){ $(this).attr('class', 'item hover'); },
		function(){ $(this).attr('class', 'item'); }
	);
		
	$('#listing .item').click(function()
	{
		document.location = $('a:first', this).attr('href');
	});	
		
	// Header Phone box.		
	var $a = $('#visual a');
	var p = parseInt($a.css('padding-left')) * 2;
	$('#visual .box').css({
		width: $a.width() + p + 'px',
		height: $a.height() + p + 'px',	
		opacity: 0.8,
		left: $a.position().left + 1 + 'px',
		top: $a.position().top + 1 + 'px'	
	});
		
	// Make reset empty all fields
	$(':reset').click(function()
	{	
		$('option[selected]').removeAttr('selected');
		$('select').val('');		
		$(':checkbox').attr('checked', false);		
		$(this).parents('form:first').submit();
		return false;
	});	
	
	// IE 6 specific...
	if ($.browser.msie && parseInt($.browser.version) < 7)
	{		
		$('[src$=.png], .newBox, #visual > a, #visual > .bar, .sectionNav > li > a > .icon').ifixpng();
		$('#details .columnRight img').css('float', 'none');
		$('.sectionNav').css({'float':'none'});
	}
		
	// Fix icon render jumping.
	$('.sectionNav > li > a > .icon').show();
	
	// Pic gallery
	$('#content p + ul').each(function()
	{
		var $ul = $(this);
		var $p = $ul.prev('p:first'); 
			
		if ($.trim($p.text()) !== 'Fotogallerij:') return;
		
		$p.remove();
		
		var $div = $('<div class="lightBox"></div>').css({
			clear: 'both',
			overflow: 'hidden'
		});
		
		$ul.children('li').each(function()
		{
			var src = $.trim($(this).text()).split('/').pop();
			$div.append(
				$('<a href="/file/'+ src +'"><img src="/thumb/'+ src +'" alt="/file/'+ src +'" /></a>').css({
					display: 'inline-block',
					width: '220px',
					height: '165px',					
					textAlign: 'center',
					background: '#fff',
					verticalAlign: 'top',
					margin: '0 4px 4px 0',
					padding: '4px',
					border: 'solid 1px #ccc'
				})
			);
		});
		
		$ul.replaceWith($div);		
	});
	
	initLightBox('#content .lightBox a');
		
});

function initLightBox(selector)
{
	// LightBox		
	var imgPath = '/images/layout/lightbox/';
	$(selector).lightBox({
		imageLoading: imgPath + 'loading.gif',
		imageBtnClose: imgPath + 'close.gif',
		imageBtnPrev: imgPath + 'prev.gif',
		imageBtnNext: imgPath + 'next.gif',
		imageBlank: imgPath + 'blank.gif',
		txtImage: '',
		txtOf: ' / '
	});
}

/*
function animateNewBox(dir)
{
	$('.newBox a').animate({backgroundPosition: 990 * dir}, 500, function()
	{		
		$(this).css({backgroundImage: ''}).animate({backgroundPosition: dir * 990}, 6000 + 1000, function(){
			$(this).css({backgroundImage: 'url(/images/layout/newbox_gloss.png)'});
			animateNewBox(dir * -1);
		});		
	});
}*/
