var animation_interval = null;

$(function() {
	
	$('.validate-form').each(function() {
		return $(this).validate();
	});
	
	$('.validate-form input:text,.validate-form textarea').each(function() {
		$(this).attr('default_val', $(this).val());
	});
	
	$('.validate-form input:text,.validate-form textarea').focus(function() {
		var default_val = $(this).attr('default_val'), val = $(this).val();
		
		if (val == default_val) {
			$(this).val('');
		}
		
		$(this).addClass('focus');
		
	}).blur(function() {
		var default_val = $(this).attr('default_val'), val = $(this).val();
		
		if (val.length == 0) {
			$(this).val(default_val);
		}
		
		$(this).removeClass('focus');
	});
	
	var fotoalbum_heading_h = 0;
	$('.fotoAlbum .foto-heading').each(function() {
		if ($(this).height() > fotoalbum_heading_h) {
			fotoalbum_heading_h = $(this).height();
		}
	});
	
	$('.fotoAlbum .foto-heading').height(fotoalbum_heading_h);
	
	var fa_h = 0;
	$('.fotoAlbum li').each(function() {
		if ($(this).height() > fa_h) {
			fa_h = $(this).height();
		}
	});
	
	$('.fotoAlbum li').height(fa_h);
	
	
	var gordonAlbum_h = 0;
	$('.gordonAlbum li').each(function() {
		if ($(this).height() > gordonAlbum_h) {
			gordonAlbum_h = $(this).height();
		}
	});
	
	$('.gordonAlbum li').height(gordonAlbum_h);
	
	$('a[rel="foto"]').colorbox({
									transition: 'elastic'
								});
	
	var fb_h = 0;
	$('.fotos .foto-btn').each(function() {
		if (fb_h < $(this).height()) {
			fb_h = $(this).height();
		}
	});
	
	$('.fotos .foto-btn').each(function() {
		if ($(this).height() < fb_h) {
			$(this).css('line-height', fb_h + 'px');
		}
		
		$(this).height(fb_h);
	});
	
	 $('.menukaart li span.right-link').parent().click(function() {
		 if (!$(this).parent().hasClass('menukaart-active')) {
			 $(this).find('.right-link').text('sluit venster');
			 $(this).parent().addClass('menukaart-active');
			 $(this).parent().find('div.items').slideDown('medium');
		 } else {
			 $(this).find('.right-link').text('bekijk');
			 $(this).parent().removeClass('menukaart-active');
			 $(this).parent().find('div.items').slideUp(400);
		 }
		 
		 return false;
	 });
	
	var max_h = 0;
	$('.calender .article').each(function() {
		if ($(this).height() > max_h) {
			max_h = $(this).height();
		}
	});
	
	$('.calender .article').height(max_h);
	
	$('#images-box #left-arrow a').click(function() {
		var old_index = parseInt($('.bar .buttons li.active-img a').attr('index')),
			total = $('.bar .buttons li').length, new_index = 0;
		
		if ((old_index - 1) > -1) {
			new_index = old_index - 1;
		} else {
			new_index = total - 1;
		}
		
		clearInterval(animation_interval);
		animation_interval = setInterval('continuous_banner_animation()', 7000);
		transition_banner(old_index, new_index);
		
		return false;
	});
	
	$('#images-box #right-arrow a').click(function() {
		var old_index = parseInt($('.bar .buttons li.active-img a').attr('index')),
			total = $('.bar .buttons li').length, new_index = 0;
		
		if ((old_index + 1) < total) {
			new_index = old_index + 1;
		} else {
			new_index = 0;
		}
		
		clearInterval(animation_interval);
		animation_interval = setInterval('continuous_banner_animation()', 7000);
		transition_banner(old_index, new_index);
		
		return false;
	});
	
	$('.bar .buttons a').click(function() {
		var new_index = parseInt($(this).attr('index')),
			old_index = parseInt($('.bar .buttons li.active-img a').attr('index'));
		
		if (new_index != old_index) {
			clearInterval(animation_interval);
			animation_interval = setInterval('continuous_banner_animation()', 7000);
			transition_banner(old_index, new_index);
		}
		
		return false;
	});
	
	$('#images-box').mouseover(function() {
		clearInterval(animation_interval);
	}).mouseout(function() {
		animation_interval = setInterval('continuous_banner_animation()', 7000);
	});
	
	animation_interval = setInterval('continuous_banner_animation()', 7000);
});

function transition_banner(old_index, new_index)
{
	var banner_txt = $('#banner-rotator-images > li:eq(' + new_index + ') > div').text();
	$('#images .bar .home-bar').text(banner_txt);
	
	$('.bar .buttons li:eq(' + old_index + ')').removeClass('active-img');
	$('.bar .buttons li:eq(' + new_index + ')').addClass('active-img');
	
	$('#banner-rotator-images > li:eq(' + old_index + ')').fadeOut(400);
	$('#banner-rotator-images > li:eq(' + new_index + ')').fadeIn(1000);
}

function continuous_banner_animation()
{
	$('#images-box #right-arrow a').click();
	
	clearInterval(animation_interval);
	animation_interval = setInterval('continuous_banner_animation()', 7000);
}
