﻿/// Foto gallery
jQuery(function ($) {
	$.fn.fotoGallery = function () {
		var toHide = $('iframe, object');

		return this.each(function () {
			var self = $(this);

			var fotoBoxes = self.children('a');
			fotoBoxes.each(function (i, n) {
				var fotoBox = $(n);
				var originFotoUrl = fotoBox.attr('href');
				var fileId = fotoBox.attr('u-id');
				var width = fotoBox.outerWidth();
				var height = fotoBox.outerHeight();
				var thumb = $('<img/>', {
					'src': 'Services/GetImage.ashx?id=' + fileId + '&width=' + width + '&height=' + height
				});
				fotoBox.append(thumb);
			});

			fotoBoxes.fancybox({
				'padding': 2,
				'titlePosition': 'over',
				'transitionIn': 'elastic',
				'transitionOut': 'elastic',
				onStart: function (a, b) {
					// Hide iframes and object
					toHide.css('visibility', 'hidden');
				},
				onClosed: function () {
					// Show iframes and object
					toHide.css('visibility', 'visible');
				}
			});
		});
	}
});
