$().ready(function(){

jQuery.fn.center = function () {

var pos = {
  sTop : function() {
    return window.pageYOffset
    || document.documentElement && document.documentElement.scrollTop
    ||  document.body.scrollTop;
  },
  wHeight : function() {
    return window.innerHeight
    || document.documentElement && document.documentElement.clientHeight
    || document.body.clientHeight;
  }
};

var vPos = pos.sTop() + (pos.wHeight() / 2) - (this.outerHeight() / 2);
			this.css({
			 position: 'absolute',
			 left: '50%',
			 top: vPos,
			 marginLeft: - (this.outerWidth() / 2) +"px"
			 });
    return this;
}

// ajax

$.ajaxSetup ({
	cache: false
});

function overlay(title) {
	$('body').prepend('<div id="overlay" style="display: none" ><div id="load"></div></div>');
	var pageHeight = $(document).height();
	//var css = 'Contact';
	$('#overlay')
		.css({
			height: pageHeight
		})
		.fadeIn();	
	$('#load')
		.addClass('radius')
		.addClass('load')
		.addClass(title)
		.center()
}

function ajaxWindow() {
	var title = $(this).attr('title');
	overlay(title);
	var loading = '';
	var loadUrl = $(this).attr('href');
	
	$('#load').html(loading).load(loadUrl,function(){
		var close = '<a id="close" href="#"></a>';
		$('#load')
			.append(close)
		$('#close').click(function(){
			$('#overlay').remove()
			$('#message-wrap').remove();
			return false;
		})
	});
	return false;
}

$ajaxLinks = $('#nav a[title=Contact],#nav a[title=About],.photo-covers li a');
$ajaxLinks.click(ajaxWindow);

$lastChilds = $('.links li:last-child a');
$lastChilds.addClass('last');

$('#comments-list li p:last-child').addClass('last');

});

