$(function() {
	var channel = new channels();
	var image = new Image();
	image.src = "webimages/whitenoise.gif";
});

function channels() {
	var cur = 0;
	var $li = $('#film li');
	var timer;
	setTimer(5000);
	
	function next() {
		var n = cur + 1;
		if(n == $li.length) { n = 0; }
		$li.eq(n).fadeIn(2000,function() {
			$li.eq(cur).css({display:'none','zIndex':5}).removeClass();
			$(this).css('zIndex','4');
			cur = n;
			setTimer(7000);
		});
		if(Modernizr.csstransitions) {
			$li.eq(cur).addClass('out'+randomInt(1,6));
		}
	}
	function setTimer(time) {
		timer = setTimeout(function() { next(); }, time);
	}
	
	// white noise on hover
	var $wn = $('#whitenoise');
	$('#links').hover(function() {
		$wn.stop().css({opacity:.30,display:'block'});
		noiseLoop();
	},function() {
		$wn.stop().fadeOut(700);
	});
	$('#television').mouseover(function() {
		$wn.stop().fadeOut(700);
	});
	function noiseLoop() {
		$wn.animate({opacity:.50},1000,function() {
			$wn.animate({opacity:.20},1000,function() {
				noiseLoop();
			});
		});
	}
}
function randomInt(min, max) {
    return Math.floor(Math.random()*(max+1-min)) + min;
};
