$(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	var boxImgs = $('img.imgBox');
	
	boxImgs.each(function(){
		var t = $(this);		
		var link = t.parents('a').eq(0);
		
		link.addClass('boxLink');		
		t.wrap('<div class="boxWrap"><div class="inner"></div></div>');
		
		var wrap = t.parents('div.boxWrap').eq(0);
		
		t.show();
		
		if(t.width() < t.height()) {
			t.css({
				'width': 'auto',
				'height': '160px'
			});
		} else {			
			t.css({
				'width': '160px',
				'height': 'auto'
			});
			
			var inner = wrap.find('div.inner').eq(0);
			
			t.css({
				'margin-top': Math.round((inner.height() - t.height()) / 2)
			});
		}
		
		wrap.css({
			'margin-top': -(wrap.height()),
			'margin-left': 40,
		}).hide();
	});
	
	var boxWraps = $('div.boxWrap');
	boxWraps.hide();
	
	$('a.boxLink').mouseenter(function(){
		var t = $(this);
		boxWraps.hide();
		t.find('div.boxWrap').show();
	}).mouseleave(function(){
		boxWraps.hide();
	});
	
	boxWraps.mouseenter(function(){
		boxWraps.hide();
	});
});
