$(document).ready(function() {
	$("#wrapper").masonry({
		itemSelector: ".tile.visible",
		columnWidth: 232,
		isAnimated: true
	});
});

var types = new Array();

function swap(type, anchor) {
	$(anchor).toggleClass("active");
	
	var index   = $.inArray(type, types),
	    wrapper = $("#wrapper");
	
	if (index == -1) {
		if (types.length == 0) {
			wrapper.find(".tile:not(#logo)").removeClass("visible").hide();
		}
		
		wrapper.find(".tile." + type).addClass("visible").show();
		types.push(type);
	}
	else {
		types.splice(index, 1);
		if (types.length == 0) {
			wrapper.find(".tile").addClass("visible").fadeIn();
		}
		else if (index != -1) {
			wrapper.find(".tile." + type).removeClass("visible").hide();
		}
	}
	
	wrapper.masonry("reload");
}

function doAjaxRequest(pars, div, callback) {
	$.ajax({
		type: "POST",
		url: "?",
		data: pars,
		success: callback
	});
}
