$(document).ready(function(){
	$(window).mouseenter(function(){
		$('.attention').removeClass('border');
		$('.appear').fadeTo(333, 1);
	});
	$('#spread').mouseenter(function(){
		$('#intro').stop().fadeTo(333, 0);
		$('#asl').stop().fadeTo(333, 1);
	}).mouseleave(function(){
		$('#asl').stop().fadeTo(333, 0);
		$('#intro').stop().fadeTo(333, 1);
	});
  	var sidebar = $('.spine'), offset = sidebar.offset();
	$(window).scroll(function(){
		if ($(window).scrollTop()>offset.top) {sidebar.stop().animate({marginTop: $(window).scrollTop()-offset.top}, 333); }
		else { sidebar.stop().animate({marginTop: 0}, 333); }
	});
	function k(a, b){
		var a = a.toLowerCase(), b = b.toLowerCase();
		if (b!='all') {
			$('#variable li:not(.'+a+'.'+b+')').stop().slideUp(333);
			$('#variable li.'+a+'.'+b).stop().slideDown(333);
		} else {
			$('#variable li:not(.'+a+')').stop().slideUp(333);
			$('#variable li.'+a).stop().slideDown(333);
		}
	}
	$('#craft a, #tag a').click(function(a){
		a.preventDefault();
		$(this).parent().find('a').removeClass('selected');
		$(this).addClass('selected');
		var c = window.location.hash;
		if (c!='') {
			c = c.split('/');
			c = c[1].split('-');
		}
		if ($(this).parent().parent().attr('id')=='craft') {
			var e = (c!='') ? c[1] : $('#tag').find('.selected').text().toLowerCase();
			window.location.hash = '/'+$(this).text()+'-'+e;
			k($(this).text(), e);
		} else {
			var e = (c!='') ? c[0] : $('#craft').find('.selected').text().toLowerCase();
			window.location.hash = '/'+e+'-'+$(this).text();
			k(e, $(this).text());
		}
	});
	var c = window.location.hash.toLowerCase();
	if (c!='') {
		c = c.split('/');
		c = c[1].split('-');
		k(c[0], c[1]);
		$('#craft').find('.selected').removeClass('selected').parent().find('.f'+c[0]).addClass('selected');
		$('#tag').find('.selected').removeClass('selected').parent().find('.f'+c[1]).addClass('selected');
	}
	$('.more').click(function(x){
		x.preventDefault();
		var y = $(this).parent().parent();
		$(this).hide();
		y.find('p').slideDown(333);
		y.find('.less').show();
	});
	$('.less').click(function(x){
		x.preventDefault();
		var y = $(this).parent().parent();
		$(this).hide();
		y.find('p').slideUp(333);
		y.find('.more').show();
	});
});