var positions = [
	 -3, 263,
	 -3, 285,
	 -3, 312,
	 -3, 333,
	 -3, 355,
	  0, 380,
	 24, 382,
	 46, 382,
	 68, 382,
	 90, 382,
	112, 382,
	134, 382,
	156, 382,
	178, 382,
	200, 382,
	222, 382,
	244, 382,
	266, 382,
	288, 380,
	310, 380,
	332, 380,
	354, 380,
	376, 380,
	398, 380,
	421, 380,
	443, 380,
	465, 380,
	487, 380,
	509, 380,
	531, 380,
	554, 380,
	575, 380,
	599, 380,
	621, 380,
	643, 380,
	665, 380,
	687, 380,
	709, 380,
	731, 380,
	756, 377,
	758, 353,
	758, 329,
	758, 308,
	758, 281,
	746, 261,
	734, 241,
	749, 222,
	752, 198,
	746, 174,
	750, 148,
	748, 121,
	740, 95,
	732, 74,
	723, 52,
	719, 30,
	715, 5,
	696, 4,
	674, 3,
	651, 3,
	628, 3,
	606, 3,
	583, 2,
	561, 2,
	540, 2,
	517, 1,
	494, 1,
	472, 1,
	452, 1,
	429, 0,
	404, 0,
	383, -1,
	361, -1,
	339, -1,
	317, -1,
	295, -1,
	273, -1,
	251, -1,
	228, -2,
	206, -2,
	184, -2,
	162, -2,
	141, -3,
	119, -3,
	 97, -3,
	 75, -3
];

function header_animate() {
	var lit = $('<img />');
	lit.attr('src', 'marquee-on.png');
	lit.css('position', 'absolute');
	$('#marquee').append(lit);

	var position_index = 0;
	var flicker_counter = 0;

	// 0: counter clockwise
	// 1: clockwise
	// 2: flicker
	// 3: solid
	var direction = 0;
	
	var unlit = $('<img />');
	unlit.attr('src', 'marquee-off.png');
	unlit.css('position', 'absolute');
	
	for (var i = 0; i < positions.length; i += 2) {
		var clone = unlit.clone();
		clone.css('left', (positions[i] + 4) + 'px');
		clone.css('top', (positions[i + 1] + 4) + 'px');
		$('#marquee').append(clone);
	}
	
	var interval = setInterval(function() {
		if (direction == 0 || direction == 1) {
			lit.css('left', positions[position_index] + 'px').css('top', positions[position_index + 1] + 'px');
			if (direction == 0) {
				position_index += 2;
			} else if (direction == 1) {
				position_index -= 2;
			}
			if (position_index >= positions.length) {
				position_index = positions.length - 4;
				direction = 1;
			}
			if (position_index <= 0) {
				direction = 2;
			}
		} else if (direction == 2) {
			position_index = Math.floor(Math.random() * (Math.floor(positions.length / 2))) * 2;
			lit.css('left', positions[position_index] + 'px').css('top', positions[position_index + 1] + 'px');
			flicker_counter++;
			if (flicker_counter >= 100)
				direction = 3;
		} else if (direction == 3) {
			lit.detach();
			var alllit = $('<img />');
			alllit.attr('src', 'marquee-alllit.png');
			alllit.css('position', 'absolute');
			alllit.css('left', '-8px');
			alllit.css('top', '-8px');
			
			$('#marquee').append(alllit);
			clearInterval(interval);
		}
	}, 20);
}
