/* Copyright (C) 2002-2009 by Home of the Brave
   Web http://home.of.the.brave.de
   E-Mail info@brave.de */
/* $Revision: 1.1 $ $Date: 2009/06/24 10:15:45 $ */

/*
 * Modal window for large versions of images.
 * dependencies: jQuery, jqModal
 * owner: Nico.Westermann@brave.de
 *
 */
 
$(document).ready(function() {
	$('body').append('<div class="jqmWindow" id="jqmDialog"><div id="jqmContent">loading...</div></div>');
	$('a.modalpopup').click(function() {
		var path = $(this).attr('href');
		if (!path.match(/^(?:https?:|\/)/))
			path = location.pathname.replace(/\/[^\/]*$/,'')+'/'+path;
		var alt = $(this).find('img').attr('alt');
		imgPreloader = new Image();
		imgPreloader.onload = function(){
			var width = imgPreloader.width;
			var height = imgPreloader.height+20;
			var margintop = document.body.scrollTop + ($(window).height()-height)/2;
			var marginleft = document.body.scrollLeft + ($(window).width()-width)/2;
			$('#jqmDialog').css({'height' : ''+height+'', 'width' : ''+width+'', 'left' : ''+marginleft+'', 'top' : ''+margintop+''});
			$('#jqmContent').html('<a href="#" class="jqmClose">X</a><img src="'+path+'" alt="'+alt+'"/>');
			$('#jqmDialog a').click(function() {
				$('#jqmDialog').jqm().jqmHide(); return false;
			});
			$('#jqmDialog').jqm().jqmShow();
		};
		imgPreloader.src = path;
		return false;
	});
});
