
$(function() {
	
	// Apply it to images
	if (typeof jQuery.fn.it === 'function') {
		$('img.it').it();
	}
	
	// Apply it to images
	if (typeof jQuery.fn.supersleight === 'function') {
		$('.supersleight').supersleight();
	}

	// Target _new
	$('a.new').attr('target', '_blank');
	
	// 
	$(window).load(function() {
		$('.bar .nav').after('<div class="piece_display"><div class="inner"></div><div class="overlay_"></div></div>');
		fillPieceDisplay();
	});
});

function fillPieceDisplay() {
	var fromBottom = 100;
	var barDiv = $('.bar');
	var mainDiv = barDiv.next('.main');
	var pieceDisplay = $('.piece_display');
	var pieceDisplayInner = pieceDisplay.find('.inner');
	pieceDisplay.css('height', pieceDisplay.height() + mainDiv.height() - barDiv.height() - fromBottom);
	if (pieceDisplayInner.height() < pieceDisplay.height()) {
		$.ajax({
			url: '/pieces/piece_display',
			cache: false,
			success: function(msg) {
				pieceDisplayInner.append(msg);
				fillPieceDisplay();
			}
		});
	}
}