//compiled with closure

Estate = (function() {
	/* START PUBLIC */
	return {
		Trace: function(string) {
			if (Estate.Develop && Estate.Develop.Trace) {
				Estate.Develop.Trace(string)
			}
		},

		TraceAttr: function(string) {
			if (Estate.Develop && Estate.Develop.Trace) {
				Estate.Develop.TraceAttr(string)
			}
		}
	}
	/* END PUBLIC */
})();






/*
* Summary:
* Tools to validate function arguments
*/
Estate.Check = (function() {
	/* START PRIVATE */
	function LiteralsAreCompatible(mainLiteral, updateLiteral) {
		for (prop in updateLiteral) {
			if (typeof (mainLiteral[prop]) == "undefined") {
				return "The variable '" + prop + "'in the object literal cannot be merged with the original object literal.";
			}

			if (typeof (updateLiteral[prop]) != typeof (mainLiteral[prop])) {
				return "The variable '" + prop + " is of the wrong type. It is '" + typeof (updateLiteral[prop]) + "' but it should be '" + typeof (mainLiteral[prop]) + "'";
			}

			if (typeof (updateLiteral[prop]) == "object") {
				LiteralsAreCompatible(mainLiteral[prop], updateLiteral[prop]);
			}
		}
	}
	/* END PRIVATE */



	/* START PUBLIC */
	return {
		/*
		* Summary:
		* Checks if the right amount of arguments are used when calling the function
		* 
		* Usage:
		error = Estate.Check.ArgumentsCount( arguments.length, 1 );
		if ( error != "" ) throw new Error( error );
		*/
		ArgumentsCount: function(CurrentArgumentsLength, CorrectArgumentsLength) {
			if (typeof (CorrectArgumentsLength) == "number") {
				if (CurrentArgumentsLength != CorrectArgumentsLength) {
					return "Wrong number of arguments. There argument count should be " + CorrectArgumentsLength + ", but it is " + CurrentArgumentsLength;
				}
			}
			if (typeof (CorrectArgumentsLength) == "array") {
				var CorrectArgumentsCount = false;
				for (var i = 0; i < CorrectArgumentsLength.length; i++) {
					if (CorrectArgumentsCount == CorrectArgumentsLength[i]) {
						CorrectArgumentsCount = true
					}
				}
			}
			return ""
		},

		/*
		* Summary:
		* Checks if an element with a particular id exists
		* 
		* Usage:
		error = Estate.Check.ElementById( 'elID' );
		*OR*
		error = Estate.Check.ElementById( 'elID', 'div' );

			if ( error != "" ) throw new Error( error );
		*/
		ElementById: function(ElementID, RequiredTagName) {
			if (typeof (ElementID) != "string") {
				return "Provided element id is not a string but  '" + typeof (ElementID) + "'.";
			}
			if (!document.getElementById(ElementID)) {
				return "Cannot find HTML element with the id '" + ElementID + "'";
			}
			if (arguments.length > 1 && typeof (RequiredTagName) == "string") {
				if (document.getElementById(ElementID).tagName.toLowerCase() != RequiredTagName && RequiredTagName != "") {
					return "HTML element with ID '" + ElementID + "' has the tagname '" + document.getElementById(ElementID).tagName + "' but it should be '" + RequiredTagName + "'";
				}
			}
			return ""
		},

		/*
		* Summary:
		* Checks if the referenced object is an HTML element
		* 
		* Usage:
		error = Estate.Check.Element( document.getElementsByTagName('a')[0] );
		if ( error != "" ) throw new Error( error );
		*/
		Element: function(Element) {
			if (typeof (Element.tagName) == "undefined") {
				return "HTML element expected. Type of checked variable is " + typeof (Element)
			}
			return ""
		},

		/*
		* Summary:
		* Checks if argument is of the expected variable type
		* 
		* Usage:
		error = Estate.Check.VariableType( id, "string" );
		if ( error != "" ) throw new Error( error );
		*/
		VariableType: function(Variable, ExpectedVariableType) {
			if (typeof (Variable) != ExpectedVariableType) {
				return "Unexpected variable type. There variable type should be " + ExpectedVariableType + ", but it is " + typeof (Variable);
			}
			return ""
		},

		/*
		* Summary:
		* Checks an object literal
		* 
		* Usage:
		oLiteral.foo = Estate.Check.SetLiteralIfDefined( oLiteral, oNewLiteral, "foo" )
		*/
		SetLiteralIfDefined: function(oldVariable, newVariable, arrayID) {
			if (typeof (newVariable) == "undefined") {
				return oldVariable[arrayID]
			}

			if (typeof (newVariable[arrayID]) == "undefined") {
				return oldVariable[arrayID]
			} else {
				return newVariable[arrayID]
			}
		},

		/*
		* Summary:
		* Updates object literal. The 2nd argument is merged with the 1st. Please use
		* Estate.Check.LiteralUpdatable if you want to be sure that this method
		* only updates variables and doesn't create new ones.
		* 
		* Usage:
		Estate.Check.UpdateLiteral( mainLiteral, updatingLiteral )
		*/
		UpdateLiteral: function(mainLiteral, updateLiteral) {
			for (prop in updateLiteral) {
				mainLiteral[prop] = updateLiteral[prop]

				if (typeof (updateLiteral[prop]) == "object") {
					Estate.Check.UpdateLiteral(mainLiteral[prop], updateLiteral[prop]);
				}
			}
		},

		/*
		* Summary:
		* Compares 2 object literals and checks if the 2nd argument can be merged
		* with the 1st. If there's a variable in the 1st argument that's not
		* been defined in the 2nd, the function returns the name of the variable.
		* 
		* Usage:
		error = Estate.Check.LiteralUpdatable( mainLiteral, updatingLiteral );
		if ( error != "" ) throw new Error( error );
		*/
		LiteralUpdatable: function(mainLiteral, updateLiteral) {
			if (typeof (mainLiteral) != "object") {
				throw new Error("Cannot check literal: 'mainLiteral' is not an object")
			}
			if (typeof (updateLiteral) != "object") {
				throw new Error("Cannot check literal: 'updateLiteral' second argument is not an object")
			}


			var isNotUpdatableVariable = LiteralsAreCompatible(mainLiteral, updateLiteral)

			if (typeof (isNotUpdatableVariable) == "undefined") {
				return ''
			} else {
				return isNotUpdatableVariable;
			}
		}
	}
	/* END PUBLIC */
})();






/*
* Summary:
* For getting, setting and deleting cookies
*/
Estate.Cookies = (function() {
	/* START PUBLIC */
	return {
		/*
		* Summary:
		* Sets a cookie
		* 
		* Usage:
		Estate.Cookies.Get( "cookieName", "cookieValue", new Date(2015, 12, 31, 23, 59, 59, 0), "/", "www.domain.com", "")
		*/
		Set: function(name, /* Name of the cookie */
					   value, /* Value of the cookie */
					   expires, /* Expiration date of the cookie (default: end of current session) */
					   path, /* Path where the cookie is valid (default: path of calling document) */
					   domain, /* Domain where the cookie is valid (default: domain of calling document) */
					   secure	/* Boolean value indicating if the cookie transmission requires a secure transmission */
					   ) {
			document.cookie = name + "=" + escape(value) +
				((expires) ? "; expires=" + expires.toGMTString() : "") +
				((path) ? "; path=" + path : "") +
				((domain) ? "; domain=" + domain : "") +
				((secure) ? "; secure" : "");
		},

		/*
		* Summary:
		* Gets cookie data
		* 
		* Usage:
		Estate.Cookies.Get()
		* 
		*/
		Get: function(name) {
			var dc = document.cookie;
			var prefix = name + "=";
			var begin = dc.indexOf("; " + prefix);
			if (begin == -1) {
				begin = dc.indexOf(prefix);
				if (begin != 0) return null;
			} else {
				begin += 2;
			}
			var end = document.cookie.indexOf(";", begin);
			if (end == -1) {
				end = dc.length;
			}
			return unescape(dc.substring(begin + prefix.length, end));
		},

		/*
		* Summary:
		* Deletes cookie data
		* 
		* Usage:
		Estate.Cookies.Delete()
		* 
		*/
		Delete: function(name, 	/* name of the cookie */
						  path, 	/* path of the cookie (must be same as path used to create cookie) */
						  domain	/* domain of the cookie (must be same as domain used to create cookie) */
						  ) {
			if (Estate.Cookies.Get(name)) {
				document.cookie = name + "=" +
				((path) ? "; path=" + path : "") +
				((domain) ? "; domain=" + domain : "") +
				"; expires=Thu, 01-Jan-70 00:00:01 GMT";
			}
		}
	}
	/* END PUBLIC */
})();






Estate.CSSTools = (function() {
	/* START PUBLIC */
	return {

		/*
		* Summary:
		* With ClassToggle you can let a specific class on an element be switched on or off
		* 
		* Usage:
		* Estate.CSSTools.ClassToggle( document.getElementById('elementId'), 'className')
		*/
		ClassToggle: function(el, className) {
			var error;
			error = Estate.Check.Element(el);
			if (error != "") throw new Error(error);
			error = Estate.Check.VariableType(className, "string")
			if (error != "") throw new Error(error);


			if (el.className.indexOf(className) < 0) {
				el.className += " " + className
			} else {
				while (el.className.indexOf(className) >= 0) {
					el.className = el.className.replace(" " + className, "")
					el.className = el.className.replace(className, "")
				}
			}
		},

		AddClass: function(el, className) {
			var error;
			error = Estate.Check.Element(el);
			if (error != "") throw new Error(error);
			error = Estate.Check.VariableType(className, "string")
			if (error != "") throw new Error(error);


			if (el.className.indexOf(className) < 0) {
				el.className += " " + className
			}
		},

		RemoveClass: function(el, className) {
			var error;
			error = Estate.Check.Element(el);
			if (error != "") throw new Error(error);
			error = Estate.Check.VariableType(className, "string")
			if (error != "") throw new Error(error);


			while (el.className.indexOf(className) >= 0) {
				el.className = el.className.replace(" " + className, "")
				el.className = el.className.replace(className, "")
			}
		},

  		/**
		 * Center image in a box with a fixed width and height
		 *
		 * @since 1.0 - 2011-01-31
		 * @version 1.0 - 2011-01-31
		 * @param {Object} jQuery selector. Selects image container
		 * @example
		 * Estate.CSSTools.CenterImage('ul.gallery li')
		 */
		CenterImage: function( selector ) {
			var error;
			error = Estate.Check.ArgumentsCount(arguments.length, 1);
			if (error != "") throw new Error(error);


			jQuery(selector).each( function(index) {
				var containerWidth = jQuery(this).innerWidth()
				var containerHeight = jQuery(this).innerHeight()
				
				var imageOverflowX = jQuery(this).find('img').innerWidth() - jQuery(this).innerWidth()
				var imageOverflowY = jQuery(this).find('img').innerHeight() - jQuery(this).innerHeight()
				if (imageOverflowX > 0) {
					imageOverflowX = -Math.round( (imageOverflowX / 2) )
					jQuery(this).find('img').css('margin-left', imageOverflowX +"px")
				}
				if (imageOverflowY > 0) {
					imageOverflowY = -Math.round( (imageOverflowY / 2) )
					jQuery(this).find('img').css('margin-top', imageOverflowY +"px")
				}
			})
		},

		/*
		* Summary:
		* Adds and removes a css class on the body. The class is used to show the website with a larger font
		* 
		* Usage:
		* Estate.Custom.ToggleFontSize(linkTextHolder)
		*/
		ToggleFontSize: function(linkTextHolderId) {
			if (arguments.length > 0) {
				var error
				error = Estate.Check.ElementById(linkTextHolderId);
				if (error != "") throw new Error(error);
			}


			var fontSizeClassName = "FontSize"
			var smallerTextLink = "Kleinere letters"
			var largerTextLink = "Grotere letters"

			if (Estate.Cookies.Get("fontSize") == null) {
				Estate.Cookies.Set("fontSize", "1")
				Estate.CSSTools.AddClass(document.body, fontSizeClassName + '1')
				if (linkTextHolderId != undefined) {
					document.getElementById(linkTextHolderId).innerHTML = smallerTextLink
				}
			} else {
				Estate.Cookies.Delete("fontSize")
				Estate.CSSTools.RemoveClass(document.body, fontSizeClassName + '1')
				if (linkTextHolderId != undefined) {
					document.getElementById(linkTextHolderId).innerHTML = largerTextLink
				}
			}
		}
	}
	/* END PUBLIC */
})();






Estate.Events = (function() {
	/* START PUBLIC */
	return {
		/*
		* Summary:
		* Adds a function to an event of a single element
		* 
		* Usage:
		* Estate.Events.AddEvent( document.getElementById('elementId'), functionName, "onclick" )
		*/
		AddEvent: function(element, 	/* the element on which the event is placed */
						   	newFunction, /* the function that has to be added to the event */
							eventType		/* the event type itself */
							  ) {
			var error;
			error = Estate.Check.VariableType(element, "object")
			if (error != "") throw new Error(error);
			error = Estate.Check.VariableType(newFunction, "function")
			if (error != "") throw new Error(error);


			var oldEvent = eval("element." + eventType);
			var eventContentType = eval("typeof element." + eventType)

			if (eventContentType != 'function') {
				eval("element." + eventType + " = newFunction")
			} else {
				eval("element." + eventType + " = function(e) { oldEvent(e); newFunction(e); }")
			}
		}
	}
	/* END PUBLIC */
})();






Estate.Forms = (function() {
	/* START PUBLIC */
	return {
		/*
		* Summary:
		* Inverts the checked state of all checkboxes in a box
		*
		* Usage:
		* Estate.Forms.InvertCheckboxSelection( document.getElementsByTagName('form')[0] )
		*/
		InvertCheckboxSelection: function(collectionParent) {
			var error;
			error = Estate.Check.Element(collectionParent);
			if (error != "") throw new Error(error);


			var formFieldsCollection = collectionParent.getElementsByTagName("input")
			if (collectionParent.alt == "true") {
				collectionParent.alt = ""
			} else {
				collectionParent.alt = "true"
			}
			var isAllChecked = collectionParent.alt

			for (var i = 0; i < formFieldsCollection.length; i++) {
				if (formFieldsCollection[i].type == "checkbox") {
					if (collectionParent.alt != "true") {
						formFieldsCollection[i].checked = ""
					} else {
						formFieldsCollection[i].checked = "checked"
					}
				}
			}
		}
	}
	/* END PUBLIC */
})();






Estate.GetElements = (function() {
	/* START PUBLIC */
	return {
		/*
		* Summary:
		* Returns all elements with a specific class as an array
		* 
		* Usage:
		* var elementCollection = Estate.GetElements.ByClassName( 'className', 'a', document.getElementById('parentElement') );
		*/
		ByClassName: function(CurrentArgumentsLength, CorrectArgumentsLength) {
			if (document.getElementsByClassName) {
				getElementsByClassName = function(className, tag, elm) {
					elm = elm || document;
					var elements = elm.getElementsByClassName(className),
						nodeName = (tag) ? new RegExp("\\b" + tag + "\\b", "i") : null,
						returnElements = [],
						current;
					for (var i = 0, il = elements.length; i < il; i += 1) {
						current = elements[i];
						if (!nodeName || nodeName.test(current.nodeName)) {
							returnElements.push(current);
						}
					}
					return returnElements;
				};
			}
			else if (document.evaluate) {
				getElementsByClassName = function(className, tag, elm) {
					tag = tag || "*";
					elm = elm || document;
					var classes = className.split(" "),
						classesToCheck = "",
						xhtmlNamespace = "http://www.w3.org/1999/xhtml",
						namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace) ? xhtmlNamespace : null,
						returnElements = [],
						elements,
						node;
					for (var j = 0, jl = classes.length; j < jl; j += 1) {
						classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
					}
					try {
						elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
					}
					catch (e) {
						elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
					}
					while ((node = elements.iterateNext())) {
						returnElements.push(node);
					}
					return returnElements;
				};
			}
			else {
				getElementsByClassName = function(className, tag, elm) {
					tag = tag || "*";
					elm = elm || document;
					var classes = className.split(" "),
						classesToCheck = [],
						elements = (tag === "*" && elm.all) ? elm.all : elm.getElementsByTagName(tag),
						current,
						returnElements = [],
						match;
					for (var k = 0, kl = classes.length; k < kl; k += 1) {
						classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
					}
					for (var l = 0, ll = elements.length; l < ll; l += 1) {
						current = elements[l];
						match = false;
						for (var m = 0, ml = classesToCheck.length; m < ml; m += 1) {
							match = classesToCheck[m].test(current.className);
							if (!match) {
								break;
							}
						}
						if (match) {
							returnElements.push(current);
						}
					}
					return returnElements;
				};
			}
			return getElementsByClassName(className, tag, elm);
		}
	}
	/* END PUBLIC */
})();






/*
* Summary:
* Truncates a string until it fits in its parent block.
*
* Warning:
* In most cases it's better to cut the string on the server side
* 
* Usage:
	jQuery(document).ready( function() {
	Estate.jQuery.TextOverflowFix( ['.block1','.block2'], ['span',''] )
})
*/
Estate.jQuery = (function() {
	/* START PUBLIC */
	return {
		TextOverflowFix: function(aQueryBlock,  /* array of containers (as jQuery selector) */
                                                          aQueryText /* array of tags with the text that has to be shortened (as jQuery selector) */
                                                          ) {
			Estate.Develop.Trace(typeof (jQuery))
			var error
			error = Estate.Check.VariableType(aQueryBlock, "object")
			if (error != "") throw new Error(error);
			error = Estate.Check.VariableType(aQueryText, "object")
			if (error != "") throw new Error(error);
			if (typeof (jQuery) != "function") throw new Error("jQuery library must be loaded before you can use this method")

			var cutStringStepSize = 15;
			var articleText = '';
			var loopCount;
			var maxCount = 100;

			for (var i = 0; i < aQueryBlock.length; i++) {
				loopCount = 0;
				jQuery(aQueryBlock[i]).scrollTop(100);
				if (jQuery(aQueryBlock[i] + ' ' + aQueryText[i]).size() > 0) {
					while (jQuery(aQueryBlock[i]).scrollTop() != 0) {
						articleText = jQuery(aQueryBlock[i] + ' ' + aQueryText[i]).html()
						jQuery(aQueryBlock[i] + ' ' + aQueryText[i]).html(articleText.substr(0, articleText.length - cutStringStepSize) + "...")
						jQuery(aQueryBlock[i]).scrollTop(0)
						jQuery(aQueryBlock[i]).scrollTop(100)
						loopCount++
						if (loopCount > maxCount) {
							break;
						}
					}
				}

				loopCount = 0;
				jQuery(aQueryBlock[i]).scrollLeft(100);
				if (jQuery(aQueryBlock[i] + ' ' + aQueryText[i]).size() > 0) {
					while (jQuery(aQueryBlock[i]).scrollLeft() != 0) {
						articleText = jQuery(aQueryBlock[i] + ' ' + aQueryText[i]).html()
						jQuery(aQueryBlock[i] + ' ' + aQueryText[i]).html(articleText.substr(0, articleText.length - cutStringStepSize) + "...")
						jQuery(aQueryBlock[i]).scrollLeft(0)
						jQuery(aQueryBlock[i]).scrollLeft(100)
						jQuery(aQueryBlock[i] + ' ' + aQueryText[i]).width('auto')
						loopCount++
						if (loopCount > maxCount) {
							break;
						}
					}
				}
			}
		}
	}
	/* END PUBLIC */
})();






Estate.Layers = (function() {
	/* START PUBLIC */
	return {
		/*
		* Summary:
		* Returns the position of the element on the y-axis
		* 
		* Usage:
		* Estate.Layers.GetPositionX( document.getElementById('elementId') )
		*/
		GetPositionX: function(obj) {
			var error
			error = Estate.Check.Element(obj);
			if (error != "") throw new Error(error);


			var x = 0
			if (obj.offsetParent) {
				while (obj.offsetParent) {
					x += obj.offsetLeft
					obj = obj.offsetParent
				}
			} else if (obj.x) {
				x += obj.x
			}
			return x
		},

		/*
		* Summary:
		* Returns the position of the element on the x-axis
		* 
		* Usage:
		* Estate.Layers.GetPositionX( document.getElementById('elementId') )
		*/
		GetPositionY: function(obj) {
			var error
			error = Estate.Check.Element(obj);
			if (error != "") throw new Error(error);


			var y = 0
			if (obj.offsetParent) {
				while (obj.offsetParent) {
					y += obj.offsetTop
					obj = obj.offsetParent
				}
			} else if (obj.y) {
				y += obj.y
			}
			return y
		}
	}
	/* END PUBLIC */
})();







/*
* Summary:
* Loads Javascript library when needed
*
* Usage:
Estate.LoadLibrary.GoogleAnalytics("UA-9330954-1")
*/
Estate.LoadLibrary = (function() {
	/* START PUBLIC */
	return {
		GoogleAnalytics: function(trackerCode) {
			var script = document.createElement("script");
			var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
			script.type = "text/javascript";
			script.src = gaJsHost + "google-analytics.com/ga.js";
			document.body.appendChild(script);
			try {
				var pageTracker = _gat._getTracker(trackerCode);
				pageTracker._trackPageview();
			}
			catch (err) { }
		}
	}
	/* END PUBLIC */
})();






Estate.Navigation = (function() {
	/* START PUBLIC */
	return {

		/*
		* Summary:
		* Navigates one step backwards in browser history. If no browser history is available the static link in the href is used
		* 
		* Usage:
		* <a href="contact.asp" onclick="return Estate.Navigation.LinkBack()">Terug</a>
		*/
		LinkBack: function() {
			if (history.length > 0) {
				history.go(-1)
				return false
			} else {
				return true
			}
		}
	}
	/* END PUBLIC */
})();






/*
* Summary:
* Shows an animated popup.
*
* Dependencies:
* Requires jQuery
* 
* Usage (See ESDN for related HTML and CSS):
	<script type="text/javascript">
	var popupConfig = {
		animationSpeed: 250
	}
	var popup = new Estate.Popup(popupConfig);
	popup.Open();
	</script>
*/
Estate.Popup = (function() {
	var Class = function() {
		var config = {
			popupCookieName: "deactivated", /* The name of the cookie that determines if a popup should be shown or not */
			popupDeactivated: false, 	/* The value of the cookie that determines if a popup should be shown or not */
			scrollToWindow: false, 		/* If true, the page will be scrolled to the popup window */
			animationSpeed: 250, 		/* Sets the animation speed in milliseconds */
			windowSelector: "#DivPopupWindow", /* The id of the popup div */
			backgroundSelector: "#DivPopupBackground"	/* the id of the background div */
		}

		function isActive() {
			checkDeactivation();
		}

		function checkDeactivation() {
			if (Estate.Cookies.Get(config.popupCookieName) == null) {
				config.popupDeactivated = false;
			} else {
				config.popupDeactivated = true;
			}
		}

		function scrollToPopupWindow() {
			if (config.scrollToWindow == true) {
				jQuery('html, body').animate({ scrollTop: jQuery(config.windowSelector).offset().top }, 500)
			}
		}

		function setConfig(newConfig) {
			var error
			error = Estate.Check.ArgumentsCount(arguments.length, 1);
			if (error != "") throw new Error(error);
			error = Estate.Check.LiteralUpdatable(config, newConfig);
			if (error != "") throw new Error(error);

			if (newConfig != null) {
				Estate.Check.UpdateLiteral(config, newConfig)
			}
		}

		function close() {
			jQuery(config.windowSelector).slideUp(config.animationSpeed);
			jQuery(config.backgroundSelector).animate({ opacity: 0 }, config.animationSpeed, function() { jQuery(config.backgroundSelector).hide() });
		}

		/* START PUBLIC */
		return function(newConfig) {
			var error
			error = Estate.Check.ArgumentsCount(arguments.length, [0, 1]);
			if (error != "") throw new Error(error);

			if (arguments.length > 0) {
				setConfig(newConfig)
			}

			this.Open = function(id) {
				isActive()

				if (config.popupDeactivated == false) {
					jQuery(config.windowSelector).slideDown(config.animationSpeed, scrollToPopupWindow);
					jQuery(config.backgroundSelector).css("opacity", 0)
					jQuery(config.backgroundSelector).animate({ opacity: 0.5 }, config.animationSpeed);
					jQuery(config.backgroundSelector).show()
					jQuery(config.backgroundSelector + ", " + config.windowSelector + " *.tag_close").click(function() {
						close()
					})
					
					var input = jQuery(config.windowSelector + " input.tag_deactivate")

					jQuery(input).change(function() {
						setCookie(jQuery(this));
					})
					
					if (input.filter(':checked').size() > 0) {
						setCookie(input);
					}
				}
				
				function setCookie(arg_input) {
					if (arg_input.is(':checked')) {
						Estate.Cookies.Set(config.popupCookieName, "true", new Date(2015, 12, 31, 23, 59, 59, 0), "/", "", false);
					} else {
						Estate.Cookies.Delete(config.popupCookieName);
					}
				}
			},

			this.Close = function() {
				close();
			}
		}
		/* END PUBLIC */
	} ()

	return Class;
})();






Estate.StringTools = (function() {
	/* START PRIVATE */
	function TranslateScrambledAddress(string) {
		var returnString = "";
		var aCharacters;

		string = string.replace("scrambled:", "")
		string = string.substring(1, (string.length - 1))
		aCharacters = string.split("][")
		for (var i = 0; i < aCharacters.length; i++) {
			returnString += String.fromCharCode(aCharacters[i])
		}

		return returnString
	}
	/* END PRIVATE */

	/* START PUBLIC */
	return {
		/*
		* Summary:
		* Returns the filename is it exists in the address bar
		*
		* Usage:
		* var filename = Estate.StringTools.GetFilenameFromUrl()
		*/
		GetFilenameFromUrl: function() {
			var error;
			error = Estate.Check.ArgumentsCount(arguments.length, 0);
			if (error != "") throw new Error(error);


			var file_name = document.location.href;
			var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
			return file_name.substring(file_name.lastIndexOf("/") + 1, end);
		},

		GetFilenameWithoutExtension: function(data) {
			var data = data.replace(/^\s|\s$/g, "");
			if (/\.\w+$/.test(data)) {
				var m = data.match(/([^\/\\]+)\.(\w+)$/);
				if (m)
					return m[1];
				else
					return "no file name";
			} else {
				var m = data.match(/([^\/\\]+)$/);
				if (m)
					return m[1];
				else
					return "no file name";
			}
		},

		/*
		* Summary:
		* Removes measurement unit from a string
		*
		* Usage:
		* width = Estate.StringTools.RemoveMeasurement( width )
		*/
		RemoveMeasurement: function(SuppliedString) {
			var error;
			error = Estate.Check.ArgumentsCount(arguments.length, 1);
			if (error != "") throw new Error(error);
			error = Estate.Check.VariableType(SuppliedString, "string");
			if (error != "") throw new Error(error);


			var StringWithoutMeasure = SuppliedString
			StringWithoutMeasure = StringWithoutMeasure.replace("px", "")
			StringWithoutMeasure = StringWithoutMeasure.replace("em", "")
			StringWithoutMeasure = StringWithoutMeasure.replace("pt", "")

			return StringWithoutMeasure
		},

		/*
		* Summary:
		* Searches all scrambled mailto:links and unscrambles them
		*
		* Requires:
		* jQuery
		*
		* Usage:
		* Estate.StringTools.ShowScrambledMailtoLinks()
		*/
		ShowScrambledMailtoLinks: function() {
			var error;
			error = Estate.Check.ArgumentsCount(arguments.length, 0);
			if (error != "") throw new Error(error);

			//alert( jQuery( 'a[href^="scrambled:"]').size() )
			var mailaddress
			jQuery('a[href^="scrambled:"]').each(function() {
				mailaddress = TranslateScrambledAddress(jQuery(this).attr('href'))
				jQuery(this).attr('href', "mailto:" + mailaddress)
				jQuery(this).html(mailaddress)
			})
		},

		GetQueryString: function(variable) {
			var query = window.location.search.substring(1);
			var vars = query.split("&");
			for (var i = 0; i < vars.length; i++) {
				var pair = vars[i].split("=");
				if (pair[0] == variable) {
					return pair[1];
				}
			}
		}
	}
	/* END PUBLIC */
})();






/*
* Summary:
* UI/interactivity components
*/
Estate.UI = (function() {
	/* START PUBLIC */
	return {
		/*
		* Summary:
		* Shows tabbed content
		*
		* Requires:
		* jQuery
		*
		* Usage:
		* Estate.UI.SetTabbedCOntent("TabbedContent")
		*/
		SetTabbedCOntent: function(container) {
			jQuery("#" + container + " div.contents div").hide()
			jQuery("#" + container + " div.contents div:first").fadeIn()
			jQuery("#" + container + " div.tabs a:first").addClass("active")
			jQuery("#" + container + " div.tabs a").each(function(index) {
				jQuery(this).click(function() {
					jQuery("#" + container + " div.contents div").hide()
					jQuery("#" + container + " div.contents div:eq(" + index + ")").fadeIn()
					jQuery("#" + container + " div.tabs a").removeClass("active")
					jQuery("#" + container + " div.tabs a:eq(" + index + ")").addClass("active")
				})
			})
		}
	}
	/* END PUBLIC */
})();






/*
* Summary:
* Hacks to bypass browser errors
*/
Estate.Hack = (function() {
	/* START PUBLIC */
	return {
		SetFloatingImages: function() {
			jQuery('img[align="left"]').addClass("imgAlignLeft")
			jQuery('img[align="right"]').addClass("imgAlignRight")
		}
	}
	/* END PUBLIC */
})();






/*
* Summary:
* Creates a gallery from a predefined list with images See ESDN for more information.
* 
* Usage:
var gallery = new Estate.Destil.Gallery();
gallery.containerSelector = "#Gallery";
gallery.Run();
*/
Estate.Gallery = (function() {
	var Class = function() {
		var config = {
			containerSelector: "div.gallery", /* The selector to the gallery container */
			popupAnimationSpeed: 250, 			/* Duration of the div popup in milliseconds */
			showImageSizeMedium: true, 			/* If false, no medium size image is shown */
			showImageSizeLarge: true, 			/* If false, no popup is offered */
			thumbWidth: 80, 					/* Width of a single thumbnail */
			thumbHeight: 80, 					/* Height of a single thumbnail */
			thumbLoopType: "continuous", 		/* Looping through the thumbnails is either 'scrollback' or 'continuous' */
			thumbScrollSpeed: 200, 			/* Duration of animating to the new thumb */
			navigationTemplate: "<div style='width: 100%; height: 0; clear: both;'></div> <span class='status'></span> <span class='back'></span> <span class='forward'></span>",
			mediumSizeTemplate: "<a class='mediumSize'><img alt=''></a>"
		}
		var pager;

		// Returns object literal with URL to medium and large size version of the thumbnail
		function getImageSet(el) {
			var imageSet = {
				medium: "",
				large: ""
			}
			var imageSetArray = jQuery(el).attr("rel").split(",");
			imageSet.medium = imageSetArray[0];
			imageSet.large = imageSetArray[1];

			return imageSet;
		}

		// Shows selected medium size image & adds link to large size image
		function setMediumSize(gallery, imageSet) {
			if (config.showImageSizeMedium == true) {
				jQuery(gallery).find("a.mediumSize").attr("href", imageSet.large);
				jQuery(gallery).find("a.mediumSize img").attr("src", imageSet.medium);
				if (config.showImageSizeLarge == true) {
					jQuery(gallery).find("a.mediumSize").click(function() {
						showPopup(jQuery(this).attr("href"))
						return (false);
					})
				}
				jQuery(gallery).find("span.status").text((pager.ImageIndex() + 1) + " van " + pager.ImageCount())
			} else if (config.showImageSizeLarge == true) {
				showPopup(imageSet.large);
			}
		}

		// Moves focus to an image in the thumblist
		function scroll(gallery, index, scrollType) {
			pager.ImageIndex(index, scrollType);

			var imageSet = getImageSet(jQuery(gallery).find("li:eq(" + (pager.ImageIndex()) + ") img"))
			setMediumSize(gallery, imageSet);

			if (pager.ThumbBarIndexSkip() != false) {
				jQuery(gallery).find("ul").css("margin-left", -((pager.ThumbBarIndexSkip() * config.thumbWidth) + 1) + "px")
			}

			if (Estate.IsIE6) {
				jQuery(gallery).find("ul").animate({ marginLeft: -((pager.ThumbBarIndex() * (config.thumbWidth / 2)) + 1) }, config.thumbScrollSpeed)
			} else {
				jQuery(gallery).find("ul").animate({ marginLeft: -((pager.ThumbBarIndex() * config.thumbWidth) + 1) }, config.thumbScrollSpeed)
			}
		}

		// Shows large image in div popup
		function showPopup(url) {
			var popupHTML = ''
			popupHTML += '<div id="DivPopupWindowGallery" class="divPopupWindow">'
			popupHTML += '	<span class="divPopupContent">'
			popupHTML += '		<span class="close">Sluiten <span>x</span></span>'
			popupHTML += '		<br />'
			popupHTML += '		<img src="" alt="" id="DivPopupImage">'
			popupHTML += '	</span>'
			popupHTML += '</div>'
			popupHTML += '<div id="DivPopupBackgroundGallery" class="divPopupBackground"></div>'

			if (jQuery("#DivPopupWindowGallery").size() == 0) {
				jQuery("body").append(popupHTML)
			}
			jQuery("#DivPopupImage").attr("src", url)
			jQuery("#DivPopupWindowGallery").slideDown(config.popupAnimationSpeed, function() { jQuery('html, body').animate({ scrollTop: 0 }, 500) });
			jQuery("#DivPopupBackgroundGallery").css("opacity", 0)
			jQuery("#DivPopupBackgroundGallery").show()
			jQuery("#DivPopupBackgroundGallery").animate({ opacity: 0.5 }, config.popupAnimationSpeed);

			jQuery("#DivPopupWindowGallery span.close").click(function() {
				jQuery("#DivPopupWindowGallery").slideUp(config.popupAnimationSpeed);
				jQuery("#DivPopupBackgroundGallery").animate({ opacity: 0 }, config.popupAnimationSpeed, function() { jQuery("#DivPopupBackgroundGallery").hide() });
			})
		}

		// updates the internal config literal
		function setConfig(newConfig) {
			var error
			error = Estate.Check.ArgumentsCount(arguments.length, 1);
			if (error != "") throw new Error(error);
			error = Estate.Check.LiteralUpdatable(config, newConfig);
			if (error != "") throw new Error(error);

			if (newConfig != null) {
				Estate.Check.UpdateLiteral(config, newConfig)
			}
		}



		/* START PUBLIC */
		return function(newConfig) {
			var error
			error = Estate.Check.ArgumentsCount(arguments.length, [0, 1]);
			if (error != "") throw new Error(error);

			if (arguments.length > 0) {
				setConfig(newConfig)
			}

			// Finds all containers in the selectors and makes galleries of it.
			this.Run = function() {
				jQuery(config.containerSelector).each(function() {
					var gallery = this;
					var totalListItems = 0;

					if (config.thumbLoopType == "continuous") {
						totalListItems = jQuery(gallery).find("ul").html()
						jQuery(gallery).find("ul").html(totalListItems + totalListItems)
					}

					var imageSet = getImageSet(jQuery(gallery).find("li:first img"))
					jQuery(gallery).find("ul").width(jQuery(gallery).find("li").size() * config.thumbWidth);   // Set width thumbs container
					jQuery("body").addClass("JsEnabled"); /* rm */
					jQuery(gallery).prepend(config.mediumSizeTemplate)   // Shows medium size image
					jQuery(gallery).append(config.navigationTemplate)   // Add navigation to gallery

					// Create pager instance
					var pagerConfig = {
						imageCount: jQuery(gallery).find("li").size(),
						thumbLoopType: config.thumbLoopType
					}
					pager = new Estate.Gallery.Pager(pagerConfig)

					// Selects first item in the gallery
					setMediumSize(gallery, imageSet)
					scroll(gallery, pager.ImageIndex(), "")

					// Handles click on a thumbnail
					jQuery(gallery).find("li img").click(function() {
						var index = jQuery(gallery).find("ul li").index(jQuery(this).parent());
						scroll(gallery, index + 1, "goto")
						var imageSet2 = getImageSet(jQuery(this))
						setMediumSize(gallery, imageSet2)
					})

					// Handles click on back button
					jQuery(gallery).find("span.back").click(function() {
						scroll(gallery, -1, "move")
					})

					// Handles click on forward button
					jQuery(gallery).find("span.forward").click(function() {
						scroll(gallery, 1, "move")
					})
				})
			}
		}
		/* END PUBLIC */
	} ()

	return Class;
})();






/*
* Summary:
* Helper class for Estate.Gallery. Manages the logic behind the navigation through the thumbs
*/
Estate.Gallery.Pager = (function() {
	var Class = function() {
		var config = {
			imageCount: 0,
			imageIndex: 1,
			imagePreviousIndex: 1,
			thumbLoopType: "undefined"
		}

		function setConfig(newConfig) {
			var error
			error = Estate.Check.ArgumentsCount(arguments.length, 1);
			if (error != "") throw new Error(error);
			error = Estate.Check.LiteralUpdatable(config, newConfig);
			if (error != "") throw new Error(error);

			if (newConfig != null) {
				Estate.Check.UpdateLiteral(config, newConfig)
			}
		}

		function getImageIndex() {
			if (config.thumbLoopType == "continuous") {
				var imageIndex = config.imageIndex - config.imageCount
				if (imageIndex < 0) {
					imageIndex = (config.imageCount - 1)
				}
				return imageIndex;
			} else if (config.thumbLoopType == "scrollback") {
				return config.imageIndex;
			}
		}

		function setImageIndex(index, moveCursorType) {
			config.imagePreviousIndex = config.imageIndex;
			if (moveCursorType == "move") {
				config.imageIndex += index; // Moves cursor
			} else if (moveCursorType == "goto") {
				config.imageIndex = index - 1; // Sets cursor
			}

			if (config.thumbLoopType == "scrollback") {
				if (config.imageIndex < 0) {
					// scrolls from first to last
					config.imageIndex = config.imageCount - 1;
				}
				if (config.imageIndex >= config.imageCount) {
					// scrolls from last to first
					config.imageIndex = 0;
				}
			} else if (config.thumbLoopType == "continuous") {
				if (config.imageIndex < (config.imageCount - 2)) {
					// scrolls from first to last
					config.imageIndex = (config.imageCount * 2) - 3;
				}
				if ((config.imageIndex + 1) >= (config.imageCount * 2)) {
					// scrolls from last to first
					config.imageIndex = config.imageCount - 1;
				}
			}
		}

		function thumbBarIndex() {
			var moveIndex = config.imageIndex - 1;

			if (config.thumbLoopType == "scrollback") {
				if (moveIndex < 1) {
					moveIndex = 0;
				}
				if (moveIndex > config.imageCount - 3) {
					moveIndex = config.imageCount - 3;
				}
			}
			return moveIndex;
		}



		/* START PUBLIC */
		return function(newConfig) {
			var error
			error = Estate.Check.ArgumentsCount(arguments.length, [0, 1]);
			if (error != "") throw new Error(error);

			if (arguments.length > 0) {
				setConfig(newConfig)
				if (config.thumbLoopType == "continuous") {
					config.imageCount = config.imageCount / 2
					config.imageIndex = config.imageCount
				}
			}

			this.Init = function(newConfig) {
				setConfig(newConfig)
			},

			// Image count getter
			this.ImageCount = function() {
				return config.imageCount
			},

			// Returns value of what the new selected image index should be
			this.ThumbBarIndex = function() {
				return thumbBarIndex();
			},

			// Indicates if there has to be a jump when a user is moving through the image index.
			this.ThumbBarIndexSkip = function() {
				var difference = config.imagePreviousIndex - config.imageIndex;
				if (difference > 1) {
					return thumbBarIndex() - 1;
				} else if (difference < -1) {
					return thumbBarIndex() + 1;
				} else {
					return false;
				}
			},

			// Either gets or sets the index of the selected image
			this.ImageIndex = function(index, moveCursorType) {
				if (arguments.length == 0) {
					return getImageIndex();
				} else {
					setImageIndex(index, moveCursorType);
				}
			}
		}
		/* END PUBLIC */
	} ()

	return Class;
})();

