var xOffset;
function hideLinks() {
	xOffset = $('#nav').find('a').last().position().left + 200;
	$('#nav').find('a').each(function(index) {
		$(this).delay(Math.random() * 200).animate({
			'left': '-=' + xOffset + 'px'
		}, 500, 'swing');
	});
	$('#search-bar').animate({
		'left': '-=2000px'
	}, 500, 'swing', function() {
		$('#search-bar').focus();
	});
}

function showLinks() {
	$('#search-bar').animate({
		'left': '+=2000px'
	}, 500, 'swing', function() {
		$('#nav').find('a').each(function(index) {
			$(this).delay(Math.random() * 200).animate({
				'left': '+=' + xOffset + 'px'
			}, 500, 'swing');
		});
	});
}

$(document).ready(function() {
	$('#search-bar').autocomplete({
		source: "/list_of_games.php",
		minLength: 3,
		delay: 2
	});
	$('#search-button').click(function() {
		if($('#search-bar').position().left >= 2000) {
			hideLinks();
		} else {
			showLinks();
		}
	});
});
