// document ready functions

$(document).ready(function()
{	
	resizeBackgroundImage($('#background img'));

	$('#menu').localScroll({duration: 700,offset: {top:-50}});
	
	
	$('#logo').click(function(){
		window.location = 'http://www.zinnebeeld.nl';
	});
	
	// on window resize
	
	$(window).resize(function()
	{
		resizeBackgroundImage($('#background img'));
	});
	
	

	
	$('.image_zoom').live('mouseenter', function(){
		$(this).fadeTo('fast', 1)
	});
	$('.image_zoom').live('mouseleave', function(){
		$(this).fadeTo('fast', 0.7)
	});
	$('.image_zoom').fadeTo('fast', 0.7)
	
	$(".colorbox").colorbox();

	
});
	
	
	
	

// resize the background image

function resizeBackgroundImage(bgImage)
{
	var availableWidth = $(window).width();
	var availableHeight = $(window).height();
	var imageHeight = 800;
	var imageWidth = 1200;
	var curWidth;
	var curHeight;
	
	if(imageHeight < availableHeight || imageWidth < availableWidth)
	{
		var percWidth = Math.floor((availableWidth * 100) / imageWidth);
		var percHeight = Math.floor((availableHeight * 100) / imageHeight);
		
		if(percWidth > percHeight)
		{
			curWidth = availableWidth;
			curHeight = resizeImage(imageWidth, imageHeight, availableWidth, 0, 'returnheight');
		
		} else if(percWidth < percHeight)
		{
			curHeight = availableHeight;
			curWidth = resizeImage(imageWidth, imageHeight, 0, availableHeight, 'returnwidth');
		}
	} else
	{
		//image full size
		
		curHeight = imageHeight;
		curWidth = imageWidth;
	}
	
	bgImage.css('width', curWidth);
	bgImage.css('height', curHeight);
}

function resizeImage (w, h, nw, nh, coord)
{
	if(coord == 'returnheight')
	{
		var newH = Math.floor((h * nw) / w);
		return newH;
	} else if(coord == 'returnwidth')
	{
		var newW = Math.floor((w * nh) / h);
		return newW;
	}
}

$(function()
{
	// form validation of the contact form
	
	if($('.form').length){
		$('.form').each(function(){			
			$(this).validate({
				submitHandler: function(form){
					form.submit();
				}
			})			
		})
	}
});

