$(document).ready( function () {
	// hook up any modal boxes
	doModals();
});

function doModals () {
	$('[rel="modal"]').click (
	   	function (event) {
			event.preventDefault();
			modalPopup($(this).attr('href'));
		});
	$('[rel="hide-modal"]').click (
	   	function (event) {
			event.preventDefault();
			hideModal();
		});
	$('#modal-bg').click (
		function () {
			hideModal();
		});
}

function modalPopup (url) {
	// Add a flag that the url is being viewed by ajax
	$.get(url, function (data) {
		showModal(data);
	 },'html');
}

function showModal (data) {
	$('#modal-content-holder').html(data);
	doModals();

	// an IE check to compensate for the lack of position: fixed support in IE quirks mode
	if ($.browser.msie) {
		marginTop = 40 + $(window).scrollTop();
		$('#modal-content').css('margin-top', marginTop+'px');
	}
	
	$('#modal-bg').css ('display','block');
	$('#modal-content-holder').css ('display','block');
}

function hideModal () {
	$('#modal-content-holder').css ('display','none');
	$('#modal-bg').css ('display','none');
	$('#modal-content-holder').html('');
}
