$('#category .toggler a').click(
	function (e) {
		e.preventDefault();
		$('#category .content').slideToggle('slow', 
			function() {
				if ($(this).is(':visible')) {
					$('#category .toggler a').addClass('open');
				} else {
					$('#category .toggler a').removeClass('open');
				}
			}
		);
	}
);

$('#social .item-wrapper:first .toggler').addClass('current');
$('#social .item-wrapper:first .item').show();

$('#social .item-wrapper .toggler').click(
	function(e) {
		e.preventDefault();
		var element = $(this).next();
		if (!element.is(':visible')) {
			$('#social .current').removeClass('current');
			$(this).addClass('current');
			$('#social .item-wrapper .item:visible').hide();
			element.show();
		}
	}
);

var view = $.cookie('view');

if (view == 'gallery') {
	$('.post:not(.featured) .post-content').hide();
	$('.post:not(.featured) .thumb').show();
	$('.tools li a').removeClass('selected');
	$('#gallery-view').addClass('selected');
}

$('#gallery-view').click(
	function(e) {
		e.preventDefault();
		$('.post:not(.featured) .post-content').hide();
		$('.post:not(.featured) .thumb').show();
		$('.tools li a').removeClass('selected');
		$(this).addClass('selected');
		view = 'gallery';
	}
);

$('#list-view').click(
	function(e) {
		e.preventDefault();
		$('.post:not(.featured) .post-content').show();
		$('.post:not(.featured) .thumb').hide();
		$('.tools li a').removeClass('selected');
		$(this).addClass('selected');
		view = 'list';
	}
);

$(window).unload(
	function() {
		$.cookie('view', view, { path: '/' });
		//alert('view: ' + view + ' cookie: ' + $.cookie('view'));
	}
);
