function resizeFancy(){
	var fancybox = $('#fancybox-content')
	
	w = $(fancybox).find('.content').width();
	h = $(fancybox).find('.content').height();

	w_crop = w / ($(window).width() - 100);
	h_crop = ($(window).height() - 100) * w_crop;

	if(h_crop < h)
	{
		w = 'auto';
		h = $(window).height() - 100;
	}
	else
	{
		w = $(window).width() - 100;
		h = 'auto';
	}

	$(fancybox).find('img')
		.width(w)
		.height(h);
		
	$(fancybox).find('.image').removeClass('hidden');
	
	
	$.fancybox.resize();
}

function formatTitle(title, currentArray, currentIndex, currentOpts) {
	return '<div class="content"><p id="fancyclose" class="close">Close <a onclick="$.fancybox.close(); return false;" href="#">[ x ]</a></p><p>'+ (title && title.length ? title : '' ) +'</p><div class="clear"></div></div>';
}

function positioningOnLoad() {
	var singleitem = $('.index .content .items .item_i').outerWidth(true);
	var itemwidth = Math.floor($('body').width() / singleitem)* singleitem;
	var rightPos = ($(window).width()-1086)/2;
	
	$('div.items').css('width', itemwidth+'px');
	
	if (rightPos > 0)
		$('body').removeClass('smaller');
	else
		$('body').addClass('smaller');
}

$(document).ready(function() {
	/*
	$(".fancy").fancybox({
		'autoDimensions'	: true,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'overlayColor'      : '#fff'
	});
	*/
	$(".fancy").fancybox({				autoDimensions: true,		autoScale: true,		overlayColor: '#fff',		overlayOpacity: 1,		titlePosition: 'inside',		titleFormat: formatTitle	});
	
	positioningOnLoad();
	
	$(window).resize(function(){
		positioningOnLoad();
	});
	
	$(".index .content .items .item_i a").hover(
	  function () {
		$(this).find('span').animate({
			top: "138"
		  }, 250 );
		$(this).find('span').show();
	  }, 
	  function () {
   		$(this).find('span').animate({
			top: "276"
		  }, 250 );
	  }
	);
});
