$(document).ready(function () {
	slideshow = 'box1';
	setTimeout("timerImage('1')",3000);
	setTimeout("timerImage('2')",3500);
	setTimeout("timerImage('3')",4000);
	heights = new Array();
	$(".box").each(function () {
		var height = $(this).children('.boxtitle').height();
		$(this).children('.boxtitle').data('height',height).css('height','40px');
		$(this).mouseover(function () {
			var curr = $(this).attr('id').split('box')[1];
			if (!$(this).children('.boxtitle').data('visible')) {
				var oheight = $(this).children('.boxtitle').data('height');
				$(this).children('.boxtitle').animate({height: oheight+'px'}, 350).data('visible',true).children('img').fadeIn('fast');
				$(".box:not(#box"+curr+") .boxtitle").animate({height: '40px'}, 350).data('visible',false).children('img').fadeOut('fast');
				slideshow = $(this).attr('id');
			}
		});
	}).click(function () {
		var link = $(this).children('.boxtitle').children('a').attr('href');
		window.location.href = link;
	});
});

function timerImage (what) {
	nextImage(what);
	setTimeout("timerImage('"+what+"')",4500);
}

var a = 0;

function nextImage (box) {
	var maxAantal = $(".box").length;
	if (box > 0 && box <= maxAantal) var selector = '#box'+box;
	else var selector = '.box';
	$(selector).each(function () {
		var box = $(this).attr('id');
		var boxnum = box.split('box')[1];
		var howmany = $("#"+box).children('.boximg').length;
		if (howmany != 0) {
			var current = $("#"+box).children('.selected').attr('id').split('boximg'+boxnum+'_')[1];
			var next = parseInt(current) + 1 <= howmany ? parseInt(current) + 1 : 1;
			$("#"+box).children(".boximg").removeClass('selected').removeClass('prev');
			$("#"+box).children("#boximg"+boxnum+"_"+current).addClass('prev');
			$("#"+box).children("#boximg"+boxnum+"_"+next).hide().addClass('selected').fadeIn('slow');
		}
	});
}

