/* -- bvn.js -- */

(function($) {
	$.extend( {

		config: (function() {
			// Put config settings in configObj (private):
			var confObj = {
				fontSize:		{
									maxOptions:	3,
									titles:	{
												1: "small",
												2: "medium",
												3: "large"
											}
								}
			};

			// Private methods:
			var extend = function(conf, callbacks) {
				if (!conf || typeof conf !== "object") { return; }
				var proceed;
				for (var key in conf) {
					proceed = true;
					if (callbacks) {
						// Call appropriate callback function, if specified:
						if (confObj[key] && callbacks.onAlter) { proceed = callbacks.onAlter(key, conf[key], confObj[key]); }
						else if (!confObj[key] && callbacks.onAdd) { proceed = callbacks.onAdd(key, conf[key]); }
					}
					// Set value, unless callback function returned false:
					if (proceed || proceed == null) { confObj[key] = conf[key]; }
				}
			};
			var get = function(key) {
				return key ? confObj[key] : confObj;
			};

			// Interface:
			return {extend: extend, get: get};
		})(),

		initTextResize: function() {
			var fsCookie = $.cookie('TEXT_RESIZE');
			var defaultSize = 1; // small is default
			var currentSize;

			if (!fsCookie) {
				// Check of cookies worden ondersteund en zet een cookie
				currentSize = defaultSize;
				$.cookie('TEXT_RESIZE', currentSize, { path: '/', expires: 10000 });
				fsCookie = $.cookie('TEXT_RESIZE');
			}

			if (fsCookie) {
				// Als cookies ondersteund worden

				// TextResize optie invoegen in de DOM
				$("#siteOptions").prepend('<li><p>lettergrootte</p><ul id="fontsize" class="nav"><li id="fontsizeSmall"><a href="#"><span class="offScreen">klein</span>&nbsp;</a></li><li id="fontsizeMedium"><a href="#"><span class="offScreen">normaal</span>&nbsp;</a></li><li id="fontsizeLarge"><a href="#"><span class="offScreen">groot</span>&nbsp;</a></li></ul></li>');

				// body voorzien van textsize class uit cookie
				$('body').addClass($.config.get().fontSize.titles[fsCookie]);

				// currentSize uit de cookie halen en zeker zijn dat het een number is
				currentSize = parseInt(fsCookie);

				$("#fontsizeSmall a").click( function(e) {
					$.setFontSize(1);
					e.preventDefault();
				});
				$("#fontsizeMedium a").click( function(e) {
					$.setFontSize(2);
					e.preventDefault();
				});
				$("#fontsizeLarge a").click( function(e) {
					$.setFontSize(3);
					e.preventDefault();
				});

			} else {
				// Als cookies niet worden ondersteund
			}
		},

		setFontSize: function(newTextSize) {
			$('body').removeClass('small medium large').addClass($.config.get().fontSize.titles[newTextSize]);
			$.cookie('TEXT_RESIZE',newTextSize, { path: '/', expires: 10000 });
		},

		popImages: function() {
			var links = $.config.get().popImages;
			for (lnk in links) {
				$("#" + lnk).popLink({width:links[lnk][0], height:links[lnk][1]})
			}
		},

		toggleSiteNav: function() {
			$("p.switchNav").click(function(e) {
				var $this = $(this);
				$this.parent().toggleClass("showNav");
				$this.find('a').text(($this.parent().hasClass("showNav") ? "Verberg menu" : "Toon menu"));
				e.preventDefault();
			});
		},
		
		initFancybox: function() {
	
			$("a[rel=imgPopup]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'titleShow' 	: false		
			});
			
			$("a.iframe").fancybox({
				'width'				: 680,
				'height'			: 540,
				'autoScale'     	: false,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'iframe'
			});
			
			$("a.iframeForm").fancybox({
				'width'				: 460,
				'height'			: 540,
				'autoScale'     	: false,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'iframe'
			});

			$("a.iframeLarge").fancybox({
				'width'				: 950,
				'height'			: 700,
				'autoScale'     	: false,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'iframe'
			});

		},
		
		externalLink: function(){
			$('a.external').click(function(){
				window.open(this.href);
				return false;
			});
		}
		
		
	// end
	} );
	
	$.fn.extend({
		
		
	});
} )(jQuery);

jQuery( function( $ ) {

	// extend $.config with window.config (if any):
	$.config.extend(window.config);

	// TextResize invoegen
	$.initTextResize();
	
	// externe links openen in nieuw venster (toevoegen class="external" aan <a>)
	$.externalLink();
	
	// popImages:
	$.popImages();

	// Toggle siteNav - switch text for subNav
	$.toggleSiteNav();
	
	// init Fancybox
	$.initFancybox();
	
	
} );


