jQuery.fn.center = function(ele) {
	this.css({ 'position': 'absolute', 'left': ((ele.width() - this.width()) / 2+$(ele).scrollLeft() + 'px') });
	return this;
}

$(document).ready(function() {
	if($('#portfolio-grid').length) {
		$('#portfolio-grid li[class!="section"]').mouseenter(function(e) {
			var item = $(this);
			$('#portfolio-grid .overlay').fadeOut('fast', function() { $(this).remove(); });
			$(e.srcElement).closest('li').append('<div class="overlay"><h5>' + item.find('a').attr('title') + '</h5></div>');
			$(e.srcElement).closest('li').find('.overlay').width($(this).width()).height($(this).height()).animate({ opacity: 1, top: 0 }, 220, 'easeOutExpo', function() {
				
			}).unbind().bind('click', function() {
				window.location.href = item.find('a').attr('href');
			});								
		});
		
		$('#portfolio-grid .overlay').live('mouseleave', function(e) {
			$(e.srcElement).parent().find('.overlay').fadeOut('fast', function() { $(this).remove(); });
		});
	}
});

$(window).load(function() {
	$('#slider').nivoSlider({
		afterLoad: function() {
			$('.nivo-controlNav').center($('#slider'));
		}
	});
});
