/**
 * fd
 * desciption:
 *
 *
 * @author communicatie bureau fourdesign_ Menno Tempelaar
 *
 *
 */

$(document).ready(function () {

	var fd = new function () {

		var self			= this;
		var instances		= [];

		var _construct = function () {
			$(document).find('div.fd_header').each(function () {
				instances.push(new fd_header(self, this));
			});
			
			$('.fd_form').each(function () {
				instances.push(new fd_form(self, this));
			});
			
			$('.fd_submenuSide').each(function () {
				instances.push(new fd_submenuSide(self, this));
			});
			
			$('.fd_imageResizer').each(function () {
				instances.push(new fd_imageResizer(self, this));
			});
			
			$("a[rel=photo-gallery]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
			
			
			$('div.widget div.photo').each(function () {
				$(this).click(function () {
					
					var items = [];
					$(this).find('div.gallery').each(function () {
						$(this).find('img').each(function () {
							items.push({
								'href': $(this).attr('src'), 
								'title': ($(this).attr('alt') == 'Thumbnail')? '' : $(this).attr('alt')
							});
						});
					});
					
					 $.fancybox(items, {
						 titlePosition: 'over', 
						 overlayColor: '#777777',
						 overlayOpacity: 0.9
					});
					
					return false;
				});
			});
		};

		_construct();

	}();

});
