(function ($, iTim) {

	var storedOptions = iTim.StoredOptions;

	$(function () {

		var defaultOptions = storedOptions.set('overlayStandard', {
			skin: 'default',
			plugins: {
				buttonPrint: false,
				buttonDownload: false,
				position: {
					horizontalConstrainTo: '#typo'
				},
				shadow: {
					t: '/swp/media/images_dokumente/00-layout/imagejquerymodal/shadow/shadowTop.png',
					rt: '/swp/media/images_dokumente/00-layout/imagejquerymodal/shadow/shadowRightTop.png',
					r: '/swp/media/images_dokumente/00-layout/imagejquerymodal/shadow/shadowRight.png',
					rb: '/swp/media/images_dokumente/00-layout/imagejquerymodal/shadow/shadowRightBottom.png',
					b: '/swp/media/images_dokumente/00-layout/imagejquerymodal/shadow/shadowBottom.png',
					lb: '/swp/media/images_dokumente/00-layout/imagejquerymodal/shadow/shadowLeftBottom.png',
					l: '/swp/media/images_dokumente/00-layout/imagejquerymodal/shadow/shadowLeft.png',
					lt: '/swp/media/images_dokumente/00-layout/imagejquerymodal/shadow/shadowLeftTop.png'
				}
			},
			lang: {
				'buttonClose.text': 'Schließen',
				'buttonPrint.text': 'Drucken',
				'galleryNav.next': 'Weiter',
				'galleryNav.previous': 'Zurück',
				'galleryPaging.pageOf': 'Bild {0} / {1}'
			}
		});

		storedOptions.set('overlayGallery', {
			inherits: 'overlayStandard',
			skin: 'gallery', // results in overlay container: <div class="modalOverlay overlayGallery">
			content: {
				gallery: 'globalGallery'
			}
		});

		$('a.modal').each(function (numLink) {
			var link = $(this);
			var linkOptions = 'overlayStandard';
			if (link.parent().parent('.galleryThumbs').length) {
				linkOptions = 'overlayGallery';
			}
			link.modalOverlay({
				inherits: linkOptions
			});
		});

		
		$('a.hiddenGallery').each(function (numHiddenGallery) {
			var gallery = 'hiddenGallery' + numHiddenGallery;
			$(this).bind('click', function (e) {
				items.eq(0).trigger('click');
				e.preventDefault();
			});
			var items = $(this).next('.hiddenGalleryItems').find('a').modalOverlay({
				inherits: 'overlayGallery',
				content: {
					gallery: gallery
				}
			});
		});

	});

})(jQuery, iTim);
