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

$(document).ready(function () {

	var fd = new function () {

		var self			= this;
		var instances		= [];

		this.imageResizer	= new fd_imageResizer();

		var _construct = function () {
			$(document).find('div.fd_header').each(function () {
				instances.push(new fd_header(self, this));
			});
			
			$('form.fd_form').each(function () {
				instances.push(new fd_form(self, this));
			});
			
			$('.fd_imageResizer').each(function () {
				self.imageResizer.add(this);
			});
			
			$('.fd_dropdown').each(function () {
				instances.push(new fd_dropdown(self, this));
			});
			
			$('.fd_imageSwitcher').each(function () {
				instances.push(new fd_imageSwitcher(self, this));
			});
			
			$('.fd_popup').each(function () {
				instances.push(new fd_popup(self, this));
			});
			
			$('.fd_blur_focus').each(function () {
				_setEvents(this);
			})
			
			// De Fotogallery bij elk product:
			$('a.main.fade').each(function () {
				$(this).click(function () {
					
					var items = [];
					$('div.gallery').find('img').each(function () {
						items.push({
							'href': $(this).attr('src'), 
							'title': ($(this).attr('alt') == 'Thumbnail')? '' : $(this).attr('alt')
						});
					})
					
					 $.fancybox(items, {
						 titlePosition: 'over', 
						 overlayColor: '#00447C', 
						 overlayOpacity: 0.9
					});
					return false;
				});
			});
		};
		
		// Blur en focus functie voor input / textarea's.
		var _setEvents = function (object) {
			$(object).blur(function () {
				if ($(object).val() == '') {
					$(object)	.val(object.defaultValue)
								.removeClass('focus')
								.addClass('blur');
				}
			});
			
			$(object).focus(function () {
				if ($(object).val() == object.defaultValue) {
					$(object)	.val('')
								.removeClass('blur')
								.addClass('focus');
				}
			});
		};

		_construct();
	}();

});
