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, "" )
			}
		},
		

        /*
         * 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 */
})();






/*
* Summary:
* Creates a gallery from a predefined list with images See ESDN for more information.
* 
* Usage:
	var gallery = new Estate.Gallery();
	gallery.Run();
*/
Estate.Gallery = (function() {
	var Class = function() {
		var config = {
			containerSelector: "#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: false, 			/* If false, no popup is offered */
			thumbWidth: 152, 					/* Width of a single thumbnail */
			thumbHeight: 152, 					/* Height of a single thumbnail */
			thumbScrollOrientation: "vertical", /* Scrolling through the thumbnails is either 'horizontal' or 'vertical' */
			thumbScrollOffset: 75,				
			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;
		var isScrollable;

		// Returns object literal with URL to medium and large size version of the thumbnail
		function getImageSet(el) {
			var imageSet = {
				medium: "",
				large: ""
			}
			var imageSetArray = new Array(jQuery(el).attr("href"), jQuery(el).attr("rel"));
			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 img").attr("src", imageSet.medium);
				if (config.showImageSizeLarge == true) {
					jQuery(gallery).find("a.mediumSize").attr("href", imageSet.large);
					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()) + ") a"))
			setMediumSize(gallery, imageSet);

			if (isScrollable == true) {
				if (pager.ThumbBarIndexSkip() != false) {
					if (config.thumbScrollOrientation == 'horizontal') {
						jQuery(gallery).find("ul").css("margin-left", -((pager.ThumbBarIndexSkip() * config.thumbWidth) + 1) + "px")
					} else if (config.thumbScrollOrientation == 'vertical') {
						jQuery(gallery).find("ul").css("margin-top", -((pager.ThumbBarIndexSkip() * config.thumbHeight) + 1 + config.thumbScrollOffset) + "px")
					}
				}

				if (config.thumbScrollOrientation == 'horizontal') {
					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)
					}
				} else if (config.thumbScrollOrientation == 'vertical') {
					jQuery(gallery).find("ul").animate({ marginTop: -((pager.ThumbBarIndex() * config.thumbHeight) + 1 + config.thumbScrollOffset) }, 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() });
			})
		}
		
		// Checks if the content is larger than the container
		function setIsScrollable(gallery) {
			var thumbsList = jQuery(gallery).find('ul')
			
			if (config.thumbScrollOrientation == 'horizontal') {
				var thumbsListWidth = jQuery(thumbsList).width()
				var thumbsListContentWidth = jQuery(thumbsList).find('li').size() * config.thumbWidth
				if (thumbsListWidth < thumbsListContentWidth) {
					return true
				}
			} else if (config.thumbScrollOrientation == 'vertical') {
				var thumbsListHeight = jQuery(thumbsList).height()
				var thumbsListContentHeight = jQuery(thumbsList).find('li').size() * config.thumbHeight
				if (thumbsListHeight < thumbsListContentHeight) {
					return true
				}
			}
			return false;
		}

		// 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;
					isScrollable = setIsScrollable(gallery)
					
					if (config.thumbLoopType == "continuous") {
						if (isScrollable == true) {
							totalListItems = jQuery(gallery).find("ul").html()
							jQuery(gallery).find("ul").html(totalListItems + totalListItems)
						}
					}
					
					if (isScrollable == false) {
						jQuery(gallery).addClass("galleryNoScroll")
					}

					var imageSet = getImageSet(jQuery(gallery).find("li:first a"))
					if (config.thumbScrollOrientation == 'horizontal') {
						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 a").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)
						return false;
					})

					// 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;
})();






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 */
})();






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 */
})();






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(newConfig) {
	var isIE6 = /MSIE 6/i.test(navigator.userAgent)
	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 */
		scrollToWindowOffsetY: -10, 			/* If the page scrolls to the popup, this value alters the destination position with Y pixels */
		animationSpeed: 250, 			/* Sets the animation speed in milliseconds */
		closeText: "x", 					/* Sets the text in the close button */
		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 + config.scrollToWindowOffsetY) }, 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)
		}
	}

	// ### START HACK
	function close() {
		if (jQuery("#DivPopupBackgroundImage:visible").size() > 0) {
			jQuery("#DivPopupWindowImage").slideUp(config.animationSpeed);
			jQuery("#DivPopupBackgroundImage").animate({ opacity: 0 }, config.animationSpeed, function() { jQuery("#DivPopupBackgroundImage").hide() });
		} else if (jQuery("#DivPopupBackgroundKleuren:visible").size() > 0) {
			jQuery("#DivPopupWindowKleuren").slideUp(config.animationSpeed);
			jQuery("#DivPopupBackgroundKleuren").animate({ opacity: 0 }, config.animationSpeed, function() { jQuery("#DivPopupBackgroundKleuren").hide() });
		} else if (jQuery("#DivPopupBackground:visible").size() > 0) {
			jQuery("#DivPopupWindow").slideUp(config.animationSpeed);
			jQuery("#DivPopupBackground").animate({ opacity: 0 }, config.animationSpeed, function() { jQuery("#DivPopupBackground").hide() });
		}
		if (isIE6) {
			jQuery("select").show();
		}
	}
	// ### END HACK



	var error
	error = Estate.Check.ArgumentsCount(arguments.length, [0, 1]);
	if (error != "") throw new Error(error);

	if (arguments.length > 0) {
		setConfig(newConfig)
	}

	/* START PUBLIC */
	this.Open = function(id) {
		isActive()

		if (config.popupDeactivated == false) {
			if (isIE6) {
				jQuery("select").hide();
			}
			jQuery(config.windowSelector).find("div.close").text(config.closeText);
			jQuery(config.windowSelector).css("top", (jQuery(window).scrollTop() + 20) + "px")
			jQuery(config.windowSelector).slideDown(config.animationSpeed);
			jQuery(config.backgroundSelector).css("opacity", 0)
			jQuery(config.backgroundSelector).show()
			jQuery(config.backgroundSelector).animate({ opacity: 0.5 }, config.animationSpeed);
			if (isIE6 == true) {
				jQuery(config.backgroundSelector).css("height", jQuery("body").height() + "px")
			}
			if (jQuery(config.windowSelector).data("hasEvents") != "true") {
				jQuery(config.backgroundSelector + ", " + config.windowSelector + " div.close, " + config.windowSelector + " span.closeButton").click(function() {
				jQuery(config.windowSelector).data("hasEvents", "true")
					close()
				})
				jQuery(config.windowSelector + " input.tag_deactivate").change(function() {
					if (jQuery(this).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 */
}



/**
* @namespace Manages html popups.
* @requires jQuery
* @see ESDN for related HTML and CSS
* @class
* @since 1.0 - 2010-02-23
* @version 1.0 - 2010-02-23
* @constructor
* @example
* var popupConfig = {
*     animationSpeed: 250
* }
* var popup = new Estate.Popup2(popupConfig);
* popup.Open();
*/
Estate.Popup2 = (function() {
	/**
	* The popup class
	* @class
	* @constructs
	*/
	var Class = function() {
		var isIE6 = /MSIE 6/i.test(navigator.userAgent)
		var popCounter = 0
		var config = {
			popupCookieName: "deactivated",
			popupDeactivated: false,
			scrollToWindow: false,
			animationSpeed: 250,
			closeText: "x",
			windowSelector: "#DivPopupWindow",
			backgroundSelector: "#DivPopupBackground",
			backgroundOpacity: 0.5,
			cookieExpire: new Date(2015, 12, 31, 23, 59, 59, 0)
		}

		function isActive() {
			checkDeactivation();
		}
	
		function checkDeactivation() {
			if (Estate.Cookies.Get(config.popupCookieName) == null && Estate.StringTools.GetQueryString("attentie") != "false") {
				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 */
		/**
		* Creates popup object
		*
		* @since 1.0 - 2010-02-23
		* @version 1.0 - 2010-02-23
		* @param {Object} [newConfig] Configuration object.
		* @param {String} [newConfig.popupCookieName] The name of the cookie that determines if a popup should be shown or not
		* @param {Boolean} [newConfig.popupDeactivated] The value of the cookie that determines if a popup should be shown or not
		* @param {Boolean} [newConfig.scrollToWindow] If true, the page will be scrolled to the popup window
		* @param {Number} [newConfig.animationSpeed] Sets the animation speed in milliseconds
		* @param {String} [newConfig.closeText] Sets the text in the close button
		* @param {String} [newConfig.windowSelector] The selector of the popup div
		* @param {String} [newConfig.backgroundSelector] The selector of the background div
		* @see ESDN for related HTML and CSS
		* @example
		* var popupConfig = {
		*     animationSpeed: 250
		* }
		* var popup = new Estate.Popup(popupConfig);
		* popup.Open();
		*/
		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)
			}

			/**
			* Shows popup
			*/
			this.Open = function() {
				isActive()

				if (config.popupDeactivated == false) {
					jQuery(config.windowSelector).find("div.close").text(config.closeText);
					jQuery(config.windowSelector).slideDown(config.animationSpeed, scrollToPopupWindow);
					jQuery(config.backgroundSelector).css("opacity", 0)
					jQuery(config.backgroundSelector).animate({ opacity: config.backgroundOpacity }, config.animationSpeed);
					jQuery(config.backgroundSelector).show()
					if (isIE6 == true) {
						jQuery(config.backgroundSelector).css("height", jQuery("body").height() + "px")
					}
					if (popCounter == 0) {
						jQuery(config.backgroundSelector + ", " + config.windowSelector + " div.close").click(function() {
							close()
						})
						jQuery(config.windowSelector + " input.tag_deactivate").change(function() {
							if (jQuery(this).is(':checked')) {
								Estate.Cookies.Set(config.popupCookieName, "true", config.cookieExpire, "/", "", false);
/*								if (typeof(parent.frames[0]) == "object") {
									var currentDomain = document.domain
									var parentDomain = ""
									if (currentDomain.indexOf("neowood.plastica.nl") >= 0) {
										parentDomain = "www.neowood.nl"
									}
									if (currentDomain.indexOf("ticalockers.plastica.nl") >= 0) {
										parentDomain = "www.ticalockers.nl"
									}
									if (currentDomain.indexOf("ticacabines.plastica.nl") >= 0) {
										parentDomain = "colorstone-panels.nl"
									}
									if (currentDomain.indexOf("facapanel.plastica.nl") >= 0) {
										parentDomain = "www.facapanel.nl"
									}
									if (currentDomain.indexOf("alucopal.plastica.nl") >= 0) {
										parentDomain = "www.alucopal.nl"
									}
									Estate.Cookies.Set(config.popupCookieName, "true", config.cookieExpire, "/", parentDomain, false);
									alert(parentDomain)
								}*/
							} else {
								Estate.Cookies.Delete(config.popupCookieName);
							}
						})
					}
					popCounter++
				}
			},

			/**
			* Hides popup
			*/
			this.Close = function() {
				close();
			}
		}
		/* End public */
	} ()

	return Class;
})();


Estate.Sitefinity = (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>
		*/
		IsInEditMode: function() {
			var pagemode = Estate.StringTools.GetQueryString("cmspagemode")
			if (pagemode == "edit") {
				return true;
			} else {
				return false;
			}
		}
	}
	/* END PUBLIC */
})();






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 */
})();

