$(document).ready(function() {
	
	$('#banners-splash-left, #banners-splash-right').fadeContent({
		'interval'   : 5000,
		'speed'      : 2000,
		'fader_item' : '.banner'
	});
	
	
//	var fader_banners_left = setInterval(function() {
//		switchFaderContent({
//			fader_wrapper : '#banners-splash-left',
//			fader_item    : '.banner-left'
//		});
//	}, 2000);
//	
//	var fader_banners_right = setInterval(function() {
//		switchFaderContent({
//			fader_wrapper : '#banners-splash-right',
//			fader_item    : '.banner-right'
//		});
//	}, 2000);
	
//	var fader_content_loop = false;
//	var fader_auto_loop;
//	
//	if (fader_auto_loop == undefined || fader_auto_loop == true) {
//		fader_content_loop = setInterval('switchFaderContent()', 2000);
//	}
	
//	$('#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.wrapper').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.wrapper: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();
//						current_visible_id = 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);
//			current_visible_id = '';
//		}, 
//		
//		function() {
//			// Bij mouse out interval opnieuw setten
//			fader_content_loop = setInterval('switchFaderContent()', 4000);
//		}
//	);
	
});

(function($) {
	$.fn.fadeContent = function(options) {
		var settings = {
			'interval'   : 4000,
			'speed'      : 2000,
			'fader_item' : '.wrapper'
		};
		
		return this.each(function() {
			if (options) {
				$.extend(settings, options);
			}
			
			var inst     = this;
			this.curr_id = '';
			this.fading  = false;
			
			this.fade = function() {
				
				// Huidig zichtbare div
				if (inst.curr_id == '') {
					inst.curr_id = $(this).find('div' + settings.fader_item + ':visible').attr('id');
				}
				
				//alert($(this).find('div' + settings.fader_item + ':visible').attr('id'));
				
				// De volgende div
				var next_div = $('#' + inst.curr_id + ' ~ div' + settings.fader_item + ':first');
				
				// Als die niet bestaat, dan de eerste div pakken
				if (next_div.length == 0) next_div = $(this).find('div:first');
			
				//alert(inst.curr_id + "\n" + next_div.attr('id'));
				
				// Als de huidige en de volgende content hetzelfde zijn, niet faden
				if (inst.curr_id != next_div.attr('id')) {
					if (inst.fading == 0) {
						inst.fading = 1;
			
						$('#' + inst.curr_id).css('z-index', '10');
						next_div.css('z-index', '11');
						next_div.fadeIn(2000, function() {
							$('#' + inst.curr_id).hide();
							inst.curr_id = next_div.attr('id');
							inst.fading = 0;
						});
					}
				}
			}
			
			var fadeInterval = setInterval(function() { 
				inst.fade();
			}, settings.interval);
		});
	}
})(jQuery);



/*

var current_visible_id = '';
var fading = 0;

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

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

			$('#' + current_visible_id).css('z-index', '10');
			next_div.css('z-index', '11');
			next_div.fadeIn(2000, function() {
				$('#' + current_visible_id).hide();
				current_visible_id = 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'));
//				}
//			});
		}
	}
}
*/
