(function ($) {
	$(function (e) {
		var hd = $('head');
		if (hd.length > 0) {
			hd.append('<link href="css/hidden.css" rel="stylesheet" type="text/css" media="screen,projection" />');
		}
		var lightboxOptions = {
			fileLoadingImage: 'img/lightbox/loading.gif',
			fileBottomNavCloseImage: 'img/lightbox/closelabel.gif',
			overlayOpacity: 0.8,
			borderSize: 10,
			imageArray: new Array,
			activeImage: null,
			inprogress: true,
			resizeSpeed: 350,
			widthCurrent: 250,
			heightCurrent: 250,
			xScale: 1,
			yScale: 1,
			displayTitle: true,
			navbarOnTop: false,
			slideNavBar: false,
			navBarSlideSpeed: 350,
			displayHelp: false,
			strings: {
				help: ' \u2190 / P - vorhergehendes Bild\u00a0\u00a0\u00a0\u00a0\u2192 / N - n&auml;chstes Bild\u00a0\u00a0\u00a0\u00a0ESC / X - schliessen',
				prevLinkTitle: 'vorhergehendes Bild',
				nextLinkTitle: 'n&auml;chstes Bild',
				prevLinkText:  '&laquo; vorhergehendes',
				nextLinkText:  'n&auml;chstes &raquo;',
				closeTitle: 'schliessen',
				image: 'Image ',
				of: ' of '
			},
			fitToScreen: true
		};
		$(".lightbox").lightbox(lightboxOptions);
		var openLinkNewWindow = function (e) {
			e.preventDefault();
			window.open($(this).attr('href'));
		};
		$('a.newWindow').bind('click', openLinkNewWindow);
		$('span.ml').each(function () {
			var $this = $(this);
			var removeEntities = function (str) {
				return str.replace('&quot;', '"').replace('&gt;', '>').replace('&lt;', '<');
			};
			var ml = removeEntities($this.metadata().ml);
			var mi = removeEntities($this.metadata().mi);
			var ot = "";
			for (j = 0; j < mi.length; j++) {
				ot += ml.charAt(mi.charCodeAt(j) - 48);
			}
			$(this).replaceWith($(ot));
		});
	});
})(jQuery);
