function evaluateModalScroll() {
	var offsetTop = ($(window).height() - $('#global').outerHeight()) / 2;
	$('#modal').css('top', (offsetTop > 0 ? offsetTop+57 : 57) +'px');
}

function modalDidLoad() {
	//for admin
	$('#admin_modal').jqmAddTrigger('#modal .adminLink a:not(.delete)');
	$('#modal .adminLink a:not(.delete)').click(function() {
		$('#modal').jqmHide();
	});
	
	$(window).resize(function() {
		evaluateModalScroll();
	});
	
}

/* from			: http://dev.iceburg.net/jquery/jqModal/
 * trigger	: .jqModal
 * close		: .jqmClose
 */
$(function() {
	$('body').prepend('<div class="jqmWindow" id="modal"></div>');
	
	$('#modal').jqm({
		modal: false,
		overlay: 70,
		ajax: '@href',
		ajaxText: '<div class="loading"></div>',
		onLoad: function(){
			modalDidLoad();
			$('#cycle').cycle({ 
			    fx:     'fade', 
			    speed:  'fast', 
			    timeout: 0, 
			    next:   '.next', 
			    prev:   '.prev' 
			});
			
		},
		onShow: function(hash){
			hash.w.show();
			evaluateModalScroll();
		}
	});
});
