$(document).ready(function() {
	var fader_visual_loop = false;
	
	if (fader_auto_loop == undefined || fader_auto_loop == true) {
		fader_visual_loop = setInterval('switchFaderVisual()', 5000);
	}
	
	$('#fader-visual-controls img').not('.control-video img').hover(
		function() {
			$('#brand-movie-container').fadeOut('fast', function() {
				$('#fader-visual').fadeIn('fast');
			});
			
			var rel = $(this).attr('rel');
			var src = $(this).attr('src');
			
			// Alleen faden bij meer dan een foto
			if ($('#fader-visual img').length > 1)
			{		
				// Fade in en fade out
				$('#fader-visual img:not("#' + rel + '")').fadeOut('normal');
				$('#' + rel).fadeIn('normal');
				
				// Control button switch
				$('#fader-visual-controls img').not('.control-video img').attr('src', src.replace('on', 'off'));
				$(this).attr('src', src.replace('off', 'on'));
			}
			
			// Interval resetten
			clearInterval(fader_visual_loop);
			fader_visual_current = '';
		}, 
		
		function() {
			// Bij mouse out interval opnieuw setten
			fader_visual_loop = setInterval('switchFaderVisual()', 5000);
		}
	);
	
	$('.control-video img').hover(
		function() {
			var src = $(this).attr('src');
			$(this).attr('src', src.replace('off', 'on'));
		},
		function() {
			var src = $(this).attr('src');
			
			if ($(this).attr('class') != 'control-on') {
				$(this).attr('src', src.replace('on', 'off'));
			}
		}
	);
});


var fader_visual_current = '';


function switchFaderVisual()
{
	// Huidig zichtbare visual
	if (fader_visual_current == '') {
		fader_visual_current = $('#fader-visual img:visible').attr('id');
	}
	
	// De volgende visual
	var next_img = $('#' + fader_visual_current + ' ~ img:first');
	
	// Als die niet bestaat, dan de eerste visual pakken
	if (next_img.length == 0) next_img = $('#fader-visual img:first');

	// Als de huidige en de volgende visual hetzelfde zijn, niet faden
	if (fader_visual_current != next_img.attr('id'))
	{
		$('#' + fader_visual_current).fadeOut(2000);
		next_img.fadeIn(2000);
		fader_visual_current = next_img.attr('id');
		
		// En control button switch
		$('#fader-visual-controls img').each(function() {
			$(this).attr('src', $(this).attr('src').replace('block-on', 'block-off'));
			
			if ($(this).attr('rel') == next_img.attr('id')) {
				$(this).attr('src', $(this).attr('src').replace('block-off', 'block-on'));
			}
		});
	}
}
