$(document).ready(function() {
	$.get('index.php/videos/random_thumbs', function(data) {
		videoThumbs = data.split('|');
		for (i=1; i<=6; i++) {
			$('#video-thumb-' + (i) + ' img').attr('src', videoThumbs[i]);
		}
		
		for (i=7; i<=12; i++) {
			$('#video-thumb-' + (i-6)).css({ backgroundImage: 'url(' + videoThumbs[i] + ')' });
		}
		
		to = setTimeout('transitionOut()', 3000);
	});
});

function transitionOut() {
	clearTimeout(to);
	$('#video-thumb-1 img').stop().fadeOut(500).queue(function() {
		$('#video-thumb-2 img').stop().fadeOut(500).queue(function() {
			$('#video-thumb-3 img').stop().fadeOut(500).queue(function() {
				$('#video-thumb-4 img').stop().fadeOut(500).queue(function() {
					$('#video-thumb-5 img').stop().fadeOut(500).queue(function() {
						$('#video-thumb-6 img').stop().fadeOut(500);
					});
				});
			});
		});
	});
	to = setTimeout('transitionIn()', 6000);
}

function transitionIn() {
	clearTimeout(to);
	$('#video-thumb-1 img').stop().fadeIn(500).queue(function() {
		$('#video-thumb-2 img').stop().fadeIn(500).queue(function() {
			$('#video-thumb-3 img').stop().fadeIn(500).queue(function() {
				$('#video-thumb-4 img').stop().fadeIn(500).queue(function() {
					$('#video-thumb-5 img').stop().fadeIn(500).queue(function() {
						$('#video-thumb-6 img').stop().fadeIn(500);
					});
				});
			});
		});
	});
	to = setTimeout('transitionOut()', 6000);
}