var obj = new Object();
var t;
var i = 1;
var first = true;

function slider()
{
	var aantal = obj.length;
	
	if(aantal > 0 && i < obj.length)
	{
		t = setTimeout('slider()', home_slider.ms );
		
		if(first !== true)
		{
			showSlide(obj[i]);
			i++;
		}else{
			first = false;
		}
	}else{
		i = 0;
		slider();
	}
}

function showSlide(obj)
{
	$("#top_content_right").animate({
		marginRight: '-400px',
		filter: ''
	}, {
		duration: 400,
		complete: function()
		{
			var img = new Image();
			
			$(img).load(function() {
				$(this).hide();
				
				$('#top_content_right img').remove();
				
				$('#top_content_right').append(this);
				
				$(this).show();
				
				$('#top_content_right').animate({
					marginRight: '0px',
					filter: ''
				}, 1000);
			})
			.attr('src', obj.afbeelding);
		}		
	} );
	
	$('#top_content_left').animate({
		opacity: 0,
		filter: ''
	}, {
		duration: 400,
		complete: function() {
			$('#top_content_left').html('<h1>'+obj.titel+'</h1><br />'+obj.tekst+'<button class="readmore_big" onclick="window.location.href=\''+obj.link+'\'">'+transl_readmore+'</button>');
			
			$('#top_content_left').animate({opacity: 1, filter: ''}, 1000);
		}
	})
	
	$('#top_content_left').fadeIn('slow');
}

$(function() {
	$.get( '/json/slider', function(res) {
		obj = JSON.parse(res);
		
		slider();
	});
})
