$(function(){


	if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 6) {
	  try {
	    document.execCommand('BackgroundImageCache', false, true);
	  } catch(err) {}
	}
	

	Cufon.replace('#menu_block a, h2');

	$('.background').removeClass('hide').fullBg()
	$('.background').load(function(){
		$(this).fullBg();
	})
		
	$('.contact #contactform').before('<div class="fc"></div>')
	$('a.portfolio_img').click(function(){
		var el = $(this);
		if(!$(this).hasClass('active')){
			var img = $(this).attr('href');
			$(this).addClass('active').siblings('a.active').removeClass('active');
						
			if(typeof document.body.style.maxHeight === "undefined") {
				//ie6
				$('body').css({'background-image' : 'url('+img+')'})

			} else {
       			 // not ie6
				$(this).addClass('loading')
				$('.background').after('<img class="hide background" src="'+ img +'">')
				$('.background:last').load(function(){
					el.removeClass('loading')
					$('.background:last').fullBg();
					$('.background.hide').fadeIn(500, function(){
						$(this).removeClass('hide').prev().remove();
						
					});				
				})
			}
			
		}
		return false;
	})
	
	$('.prev, .next, .portfolio_img').hoverIntent(function(){
		var el = $(this);
		if(!$(this).next().data('positioned')){
			$(this).next('.tooltip').position({
				of: el,
				my: 'left bottom',
				at: 'left top',
				offset: '1 -5'
			}).data('positioned', true);			
		} 
		$(this).next('.tooltip').fadeIn(70);
	}, function(){
		$(this).next('.tooltip').fadeOut(100);		
	})
	
	$('.old_news_link').click(function(){
		$('#old_news').slideToggle();
		return false;
	})
	
	$('#contactform').validate({
		submitHandler: function(form){
			$(form).find("input[type='submit']").attr('disabled', 'disabled');
			$.ajax({
				type: 'post',
				url: '/site/ajax/contactform.php',
				data: $(form).serialize(),
				success: function(result){
					if(result == 'success'){
						$(form).fadeOut(300, function(){
							$(this).next().fadeIn(200);
						})
					} else {
						$(form).fadeOut(300, function(){
							$(this).next().text('Helaas is er een fout ontstaan, probeer het later nogmaals').fadeIn(200);
						})
					}
				}
			})
		}
	})
});

$(window).load(function(){
	var height = 0;
	$('.homeblock .blockcontent').each(function(){
		if($(this).height() > height){
			height = $(this).height();
		}
	})
	$('.homeblock .blockcontent').each(function(){
		if($(this).height() < height){
			$(this).height(height);
		}
	})
	
})
