$(document).ready(function() {
	
	
	var fader_content_loop = false;
	var fader_auto_loop;
	
	if (fader_auto_loop == undefined || fader_auto_loop == true) {
		fader_content_loop = setInterval('switchFaderContent()', 8000);
	}
	
//	$('#fader-content-controls img').hover(
//	
//		function() {
//
//			var rel = $(this).attr('rel');
//			var src = $(this).attr('src');
//			
//
//			// Alleen faden bij meer dan een content item
//			if ($('#fader-content div.teaser').length > 1)
//			{		
//				// Fade in en fade out
//				var next_div = $('#' + rel);
//
//				// deze regel geeft een unrecognized expression, wanneer je fade - hovert - fade - hovert
//				var prev_div = $('#fader-content div.teaser:not("#' + rel + '")');
//				
//				if (fading == 0) {
//					fading = 1;
//					
//					prev_div.css('z-index', '10');
//					next_div.css('z-index', '11');
//					next_div.fadeIn('fast', function() {
//						prev_div.hide();
//						fader_content_current = next_div.attr('id');
//						fading = 0;
//					});
//					
//					// Control button switch
//					$('#fader-content-controls img').attr('src', src.replace('on', 'off'));
//					$(this).attr('src', src.replace('off', 'on'));
//				}
//			}
//			
//			// Interval resetten
//			clearInterval(fader_content_loop);
//			fader_content_current = '';
//		}, 
//		
//		function() {
//			// Bij mouse out interval opnieuw setten
//			fader_content_loop = setInterval('switchFaderContent()', 4000);
//		}
//	);
	
});


var fader_content_current = '';
var fading = 0;

function switchFaderContent()
{
	// Huidig zichtbare content
	if (fader_content_current == '') {
		fader_content_current = $('#teaser div.teaser:visible').attr('id');
	}
	
	// De volgende div
	var next_div = $('#' + fader_content_current + ' ~ div.teaser:first');
	
	// Als die niet bestaat, dan de eerste div pakken
	if (next_div.length == 0) next_div = $('#teaser div:first');

	// Als de huidige en de volgende content hetzelfde zijn, niet faden
	if (fader_content_current != next_div.attr('id'))
	{
		if (fading == 0) {
			fading = 1;

			$('#' + fader_content_current).css('z-index', '10');
			next_div.css('z-index', '11');
			next_div.fadeIn(2000, function() {
				$('#' + fader_content_current).hide();
				fader_content_current = next_div.attr('id');
				fading = 0;
			});
			
			// En control button switch
//			$('#fader-content-controls img').each(function() {
//				
//				$(this).attr('src', $(this).attr('src').replace('indicator-on', 'indicator-off'));
//
//				if ($(this).attr('rel') == next_div.attr('id')) {
//					$(this).attr('src', $(this).attr('src').replace('indicator-off', 'indicator-on'));
//				}
//			});
		}
	}
}
