$(document).ready(function()
{
	//init-hide
	$('.cycle-nav div a').hide();
	
	//img rollover magic
	$('#serieswrapper li:not(.active) img').hover(function()
	{
		$(this).next().css('z-index','99');
	}, function()
	{
		$(this).css('z-index','-1')
	});
	
	if($('.cycle img').size()>1)
	{
		$('.cycle-nav div').hover(function()
		{
			$(this).children().toggleClass('hover');
		});
	}
	
	//random home
	var series = $('#serieswrapper .series').hide();
	series.sort(function() {return 0.5 - Math.random()}) //Array elements now scrambled
	
	var delay = 0;
	series.each(function()
	{
		$(this).delay(delay).fadeIn(900);
		delay += 750;
	});
	
	//als pics geladen zijn
	$(window).load(function()
	{
		//cycle
		if($('.cycle img').size()>1)
		{
			$('.cycle').cycle(
			{ 
				speed:		1, 
				timeout:	0,
				prev:		$('.cycle-prev'),
				next:		$('.cycle-next'),
				after:		onAfter,
			}).children('img').each(function()
			{
				$(this).wrap($('<div />').css('left', Math.round( (1010-$(this).width())/2 )-1+'px'));
			});
		}
		else
		{
			$('.cycle img:first').wrap($('<div />').css('left', Math.round( (1010-$('.cycle img:first').width())/2 )-1+'px')).css('display','block');
		}
		
		$('.cycle-nav div a').show();
	});
	
	function onAfter(curr,next,opts)
	{
		$('#cycle-count').text((opts.currSlide + 1)+'/'+opts.slideCount);
	}
});
