
$(document).ready(function () {
	var debug = window.location.hash;
	if(debug == '#debug') debug = 1;
	$.get("/ajax.php", {'debug': debug}, function(data){
		$('body').html(data);
		adjust_posts();
	});
  
	$(window).bind("resize", adjust_posts);
});

function adjust_posts(){
	var size 	= 220;
	var width 	= $('body').width() - 20;
	var wdivs 	= Math.floor(width / size);
	var wdiff 	= width % size;
	$('.post').width(size + (Math.floor(wdiff) / wdivs));
	$('.post img.postedimg').width(size + (Math.floor(wdiff) / wdivs));
	
	var countDivs = $('.post').length;
	var showBefore = countDivs - (countDivs % wdivs) - 1;
	
	$('.post:hidden').show();
	$('.post:gt(' + showBefore + ')').hide();
	
	var height 	= $('body').height();
	var hdivs 	= Math.floor(height / size);
	var hdiff 	= height % size;
	$('.post').height(size + (hdiff / hdivs));
	$('.post img.postedimg').height(size + (hdiff / hdivs));
	
	$('body img.background').width(width - wdivs);
	$('body img.background').height(height);
	
	$('div.comingsoon').css('left',(width / 2) - ($('div.comingsoon').width() / 2));
	$('div.comingsoon').css('top',height / 2 - ($('div.comingsoon').height() / 2));
}
