/* Copyright (c) 2010 Ryan Baudoin
 * All rights reserved.
 */
$(document).ready(function() {
	$('#header_inner').css({'display': 'none'});
	var header_img = new Image();
	$(header_img).attr('src','http://www.thegreatestgameyouwilleverplay.com/images/nethack_bg.jpg').load(function(){
		$('#header_inner').animate({'opacity': 'toggle'}, 1500);
	});
	
	$('.ll').css({'opacity': 0});
	$('#getit > ul > li').css({'opacity': 0});
	$('#fivetips > ul > li').css({'opacity': 0});
	$('#whatis_right > h4').css({'opacity': 0});
	
	var updateDisplay = function(){
		$('.ll').each(function() {
			if($(this).isOnScreen() && $(this).css('opacity') == 0) {
				if($(this).attr('id') == 'getit') {
					$(this).animate({'opacity': 1}, 500, function() {
						$(this).children('ul > li:first').animate({'opacity': 1}, 200, function() {
							$(this).next('li').animate({'opacity': 1}, 200, arguments.callee);
						});
					});
				}
				else if($(this).attr('id') == 'fivetips') {
					$(this).animate({'opacity': 1}, 500, function() {
						$(this).children('ul').children('li:first').animate({'opacity': 1}, 500, function() {
							$(this).next('li').animate({'opacity': 1}, 500, arguments.callee);
						});
					});
				}
				else if($(this).attr('id') == 'whatis') {
					$(this).animate({'opacity': 1}, 500, function() {
						$(this).children('#whatis_right > h4:first').animate({'opacity': 1}, 500, function() {
							$(this).next('h4').animate({'opacity': 1}, 300, arguments.callee);
						});
					});
				}
				else {
					$(this).animate({'opacity': 1}, 1000);
				}
				$(this).removeClass('ll');
			}
		});
	}
	updateDisplay();
	$(window).resize(updateDisplay).scroll(updateDisplay);
	$('input').keyup(updateDisplay);
});
