// A=W JS written by Nathan Ford

$(function () {
	
	if ( window.location.href.match(/\?filter/) ) {
	
		var f = window.location.href.split(/\?filter=/),
		f = f[1].split(/&/);
		
		filter(f[0]);
	
	}
	
	$('#filter a, article h4 a').click(function () {
		
		if ( !window.location.href.match(/\/posts\//) ) {
		
			filter($(this).attr('rel'));	
		
		}
		else window.location = '/index.php?filter=' + $(this).attr('rel') + '#posts';
		
	});
	
});

filter = function (ele) {
	
	if (ele != 'all') {
		
		var id = ($('#posts').length) ? 'posts' : 'work';
		
		$('#filter-head').remove();
		
		$('#' + id).prepend( '<h1 id="filter-head"><a href="javascript:" rel="all">view all</a>Showing only <strong>&ldquo;'+ ele.replace('-', ' ').replace('#posts', '') +'&rdquo;</strong> '+ id +'</h1>' );
		
		$('#filter-head a').click(function () { filter('all'); });
		
		$('#posts article, #work article').css('display', 'none');
		$('.' + ele.replace('#posts', '')).css('display', 'block');
		
	}
	else {
		
		$('#filter-head').remove();
		$('#posts article, #work article').css('display', 'block');
		
	}

};
