//dojo.require("dojox.fx.scroll");
//dojo.require("dojox.image.Lightbox");
dojo.require("dijit.dijit");
dojo.addOnLoad(function () {
    //~ console.log(",,,");
    dojo.declare("MenuAnimator", null, {

        mainMenu: null,
        baseTop: null,
        statics: { idCounter: 0 },
        curtain: null,
        animationHandle: null,
        curtainDelayId: null,

        relatedUL: null,
        endHeight: null,

        constructor: function (elm) {
            // initialize the basic properties
            this.mainMenu = elm;

            var listItems = dojo.query("li", this.mainMenu);
            this.baseTop = dojo.coords(this.mainMenu).y + dojo.coords(this.mainMenu).h;

            dojo.forEach(listItems, function (listItem) {
                if (dojo.query("ul", listItem).length > 0) {
                    dojo.addClass(listItem, "children");
                }
            });

            // create the beautiful curtain
            this.curtain = dojo.create("div", { className: "menuCurtain" });
            this.mainMenu.parentNode.insertBefore(this.curtain, this.mainMenu);

            // attach the listeners
            listItems.connect("onmouseover", this, this.onLiMouseOver);
            listItems.connect("onmouseout", this, this.onLiMouseOut);
            dojo.connect(this.mainMenu, "onmouseout", this, this.onMenuMouseOut);
            dojo.connect(this.curtain, "onmouseout", this, this.onCurtainMouseOut);
        },
        __generateId: function () {
            return "qi_generatedId" + this.statics.idCounter++;
        },
        onLiMouseOver: function (e) {
            if (dojo.query("li > ul > li > ul > li", this.mainMenu).indexOf(e.currentTarget) != -1) {
                if (this.parentHoverTimerId) {
                    clearTimeout(this.parentHoverTimerId);
                    this.parentHoverTimerId = null;
                }
                if (e.currentTarget.parentNode.parentNode.parentNode.nodeName == "UL") {
                    dojo.addClass(e.currentTarget.parentNode.parentNode.parentNode, "parentHover");
                }
            }

            if (e.currentTarget.id == "") {
                e.currentTarget.id = this.__generateId();
            }

            var ulList = dojo.query(">ul", e.currentTarget);
            var ulHeight;

            dojo.addClass(e.currentTarget, "hover");
            if (ulList.length) {
                var childUl = ulList[0];
                ulHeight = this.calculateMaxHeight();
                this.animateCurtain(ulHeight, childUl);
            } else {
                ulHeight = this.calculateMaxHeight();
                this.animateCurtain(ulHeight);
            }

            dojo.stopEvent(e);
        },

        calculateMaxHeight: function () {
            var maxHeight = 0;
            var elmHeight = 0;
            dojo.query(".hover > ul", this.mainMenu).forEach(dojo.hitch(this, function (elm) {
                elmHeight = this.calculateULHeight(elm);
                if (elmHeight > maxHeight) {
                    maxHeight = elmHeight;
                }
            }));

            return maxHeight;
        },

        animateCurtain: function (endHeight, relatedUL) {
            if (endHeight == "41") {
                return;
            } else if (endHeight == "0") {
                //~ console.log("closing......" + relatedUL);
            }
            if (this.curtainDelayId) clearTimeout(this.curtainDelayId);
            this.endHeight = endHeight;
            if (dojo.hasClass(this.mainMenu.parentNode, "breadCrumb")) {
                this.endHeight = endHeight + 20;
            }
            dojo.query(".waiting", this.mainMenu).forEach(dojo.partial(this.updateAnimatingULElement, true));

            if (dojo.isObject(relatedUL)) {

                if (dojo.coords(this.curtain).h <= this.calculateMaxHeight()) {
                    this.updateAnimatingULElement(false, relatedUL);
                }
            }

            this.curtainDelayId = setTimeout(dojo.hitch(this, this.__onCurtainDelayEvent), 100);
        },

        updateAnimatingULElement: function (visible, elm) {
            if (this.mainMenu == elm) return;
            if (visible) {
                dojo.removeClass(elm, "waiting");
                dojo.style(elm, "opacity", 1);
            } else {
                dojo.addClass(elm, "waiting");
                dojo.style(elm, "opacity", 0.01);
            }
        },

        __onCurtainDelayEvent: function (endHeight, relatedUL) {
            if (Math.abs(dojo.coords(this.curtain).h - this.endHeight) <= 1) return;

            if (this.animationHandle) this.animationHandle.stop();

            this.animationHandle = dojo.animateProperty(
				{ node: this.curtain,
				    duration: Math.abs(this.endHeight - dojo.coords(this.curtain).h) * 2.0,
				    properties: {
				        height: {
				            end: this.endHeight,
				            unit: "px"
				        }
				    },
				    onEnd: dojo.hitch(this, this.__onAnimationEnd)
				});
            this.animationHandle.play();

            if (this.curtainDelayId) {
                clearTimeout(this.curtainDelayId);
                this.curtainDelayId = null;
            }
        },
        __onAnimationEnd: function (e) {
            dojo.query(".waiting", this.mainMenu).forEach(dojo.partial(this.updateAnimatingULElement, true));
        },

        calculateULHeight: function (element) {
            var box = dojo.coords(element);
            var itemTop = box.y;
            var itemHeight = box.h;
            return (itemTop + itemHeight - this.baseTop);
        },

        onLiMouseOut: function (e) {
            var parentHoverList = dojo.query('.parentHover', this.mainMenu);
            if (!this.parentHoverTimerId) {
                this.parentHoverTimerId = setTimeout(dojo.hitch(this, function () {
                    dojo.forEach(dojo.query('.parentHover'), function (item) {
                        dojo.removeClass(item, "parentHover");
                    });
                    clearTimeout(this.parentHoverTimerId);
                    this.parentHoverTimerId = null;
                }), 10);
            }

            if (e.relatedTarget != this.curtain) {
                if (this.isChildOf(this.mainMenu, e.relatedTarget)) {
                    var parentUl = e.currentTarget.parentNode;
                    var hoverList = dojo.query(".hover", this.mainMenu);
                    hoverList.forEach(dojo.hitch(this, this.__updateHoverStatus, e.relatedTarget));
                    var ulHeight = this.calculateMaxHeight();
                    this.animateCurtain(ulHeight, parentUl);
                    dojo.stopEvent(e);
                } else {
                    this.animateCurtain(0);
                }
            } else {
                dojo.stopEvent(e);
            }
        },

        __updateHoverStatus: function (relatedElement, elm) {
            if (this.isChildOf(elm, relatedElement) == false) {
                dojo.removeClass(elm, "hover");
            }
        },
        /** 
        * returns true if childElement is a child of the base element 
        **/
        isChildOf: function (baseElement /**node**/, childElement/**node**/) {
            if (!childElement) return false;
            if (childElement.id == "") {
                childElement.id = this.__generateId();
            }

            var possibleChildList = dojo.query("#" + childElement.id, baseElement);
            if (possibleChildList.length) {
                return true;
            }

            return false;
        },
        onMenuMouseOut: function (e) {
            var oldHighlightedParents = dojo.query('.parentHover');
            dojo.forEach(oldHighlightedParents, function (oldParent) {
                dojo.removeClass(oldParent, "parentHover");
            });

            if (this.isChildOf(this.mainMenu, e.relatedTarget) == false) {
                this.animateCurtain(0);
                dojo.query(".hover", this.mainMenu).removeClass("hover");
            } else {
                var hoverList = dojo.query(".hover", this.mainMenu);
                hoverList.forEach(dojo.hitch(this, this.__updateHoverStatus, e.relatedTarget));
            }
        },
        onCurtainMouseOut: function (e) {
            if (this.isChildOf(this.mainMenu, e.relatedTarget) == false) {
                this.animateCurtain(0);
                dojo.query(".hover", this.mainMenu).removeClass("hover");
            } else {
                var hoverList = dojo.query(".hover", this.mainMenu);
                hoverList.forEach(dojo.hitch(this, this.__updateHoverStatus, e.relatedTarget));
            }
        }
    });

    dojo.query(".mainMenu > ul, .breadCrumb > ul").forEach(function (elm) { new MenuAnimator(elm); });


    /* slideSidebars */
    function PositionSideBars() {
        var subNavigation = dojo.query('.subNavigation')[0];
        var introText = dojo.query('.mainContent div.intro')[0];
        var promoBar = dojo.query('.promoBar')[0];
        if (subNavigation != undefined || introText != undefined || promoBar != undefined) {
            subNavigation.style.marginTop = dojo.marginBox(introText).h + introText.style.marginTop - 29 + "px";
            promoBar.style.marginTop = dojo.marginBox(introText).h + introText.style.marginTop - 29 + "px";
        }
    }
    PositionSideBars();
    /* end of slideSidebars */

    /* clear inputfields */
    var inputFields = dojo.query('.firstTime input, .firstTime textarea, .searchField input[type="text"]');
    dojo.forEach(inputFields, function (field) {
        dojo.connect(field, "onfocus", function (e) {
            dojo.addClass(field, "focus");
            if (field.title == field.value) {
                field.value = "";
            }
        });
        dojo.connect(field, "onblur", function (e) {
            dojo.removeClass(field, "focus");
            if (field.value == "") {
                field.value = field.title;
            }
        });
    });
    /* end of clear inputfields */

    /* searchFields */

    var searchFields = dojo.query('.searchField');
    dojo.forEach(searchFields, function (searchField) {
        //clear inputfields on focus
        var inputField = dojo.query('input[type="text"]', searchField)[0];
        var hiddenField = dojo.query('input[type="hidden"]', searchField)[0];
        //console.dir(inputField);

        //hintlist
        var hintList = dojo.query('.hintList', searchField)[0];
        var hintListButton = dojo.query('.hintListBtn', searchField)[0];
        var newHeight = dojo.marginBox(hintList).h;
        var status = "closed";

        function Animation(e) {
            dojo.stopEvent(e);
            if (status == "closed") {
                var listItems = dojo.query('li', hintList);
                if (dojo.hasClass(hintList, "footerHintList") && listItems.length > 9) {
                    newHeight = 175;
                    dojo.style(hintList, "overflow", "auto");
                }
                hintList.style.visibility = "visible";
                searchField.style.zIndex = "998";
                hintList.style.height = "0px";
                dojo.animateProperty({
                    node: hintList,
                    properties: {
                        height: { end: newHeight, units: "px" }
                    },
                    duration: 250,
                    onEnd: function () { status = "open"; /*console.log('klaar met openen');*/ }
                }).play();
            }
            else {
                //alert('close');
                //console.log('begin met sluiten');
                dojo.animateProperty({
                    node: hintList,
                    properties: {
                        height: { end: 0, units: "px" }
                    },
                    duration: 250,
                    onEnd: function () { status = "closed"; hintList.style.visibility = "hidden"; searchField.style.zIndex = "1"; console.log('klaar met sluiten'); }
                }).play();
            }
        }

        dojo.connect(hintListButton, "onclick", Animation);
        var hints = dojo.query('li a', hintList);
        dojo.forEach(hints, function (hint) {
            dojo.connect(hint, "onclick", function (e) {
                if (hiddenField != undefined) {
                    hiddenField.value = hint.rel.replace("&amp;", "&");
                }
                inputField.value = hint.innerHTML.replace("&amp;", "&");
                dojo.addClass(inputField, "focus");
                /*Aanpassing BB set focus after selection*/
                inputField.focus();
                status = "open";
                Animation(e);
            });
        });
    });
    /* end of searchFields */

    /* tabs */
    var footerTabs = dojo.query('.footer .tabHeader div a');
    var footerTabContentHolders = dojo.query('.footer .tabContent');
    var tabs = dojo.query('.mainContent .tabHeader div a');
    var tabContentHolders = dojo.query('.mainContent .tabContent');
    dojo.forEach(footerTabs, TabSwitch);
    var searchTab = dojo.query('.mainContent.search')
    if (searchTab == "") {
        dojo.forEach(tabs, TabSwitch);
    }


    function TabSwitch(tab) {
        dojo.connect(tab, "onclick", function (e) {
            dojo.stopEvent(e);

            if (!dojo.hasClass(tab, "active")) {
                //remove class 'active' from other tabs
                if (tab.parentNode.parentNode.parentNode.className == "footer") {
                    dojo.forEach(footerTabs, function (otherTab) {
                        dojo.removeClass(otherTab, "active");
                    });
                }
                else {
                    dojo.forEach(tabs, function (otherTab) {
                        dojo.removeClass(otherTab, "active");
                    });
                }

                //add class 'active' to the right tab
                dojo.addClass(tab, "active");
            }

            function TabContentSwitch(tabContentHolder) {
                //hide all content
                dojo.removeClass(tabContentHolder, "active");
                dojo.addClass(tabContentHolder, "inactive");

                //show the right content with the clicked tab
                if (dojo.hasClass(tabContentHolder, tab.id)) {
                    if (dojo.hasClass(tabContentHolder, "inactive")) {
                        dojo.addClass(tabContentHolder, "active");
                        dojo.removeClass(tabContentHolder, "inactive");

                        //if the tabs is the servicestab then instantiate the companyticker
                        if (e.target.id == "servicesTab") {
                            var documentBody = dojo.query('body')[0];
                            if (!dojo.hasClass(documentBody, "tickerRuns")) {
                                companyTicker();
                            }
                        }
                    }
                }
            }

            //serve the right tabContent to the TabContentSwitch function
            if (tab.parentNode.parentNode.parentNode.className == "footer") {
                dojo.forEach(footerTabContentHolders, TabContentSwitch);
            }
            else {
                dojo.forEach(tabContentHolders, TabContentSwitch);
            }
        });
    }
    /* end of tabs */

    /* custom radioButtons */
    var radioBtnHolders = dojo.query('.radioButtonHolder');
    dojo.forEach(radioBtnHolders, function (radioBtnHolder) {
        var radioBtnElements = dojo.query('label span', radioBtnHolder);
        dojo.forEach(radioBtnElements, function (radioBtnElement) {
            var radioBtn = dojo.query('input[type="radio"]', radioBtnElement)[0];
            var textField = dojo.query('input[type="text"]', radioBtnElement);
            if (radioBtn.checked == true) {
                dojo.addClass(radioBtnElement, "active");
            }
            dojo.connect(radioBtnElement, "onclick", function (e) {
                dojo.forEach(radioBtnElements, function (otherHolder) {
                    dojo.removeClass(otherHolder, "active");
                    var otherTextField = dojo.query('input[type="text"]', otherHolder);
                    if (otherTextField.length > 0) {
                        dojo.removeClass(otherTextField[0], "required");
                    }
                });
                if (dojo.hasClass(radioBtnElement, "active")) {
                    dojo.removeClass(radioBtnElement, "active");
                    radioBtn.checked = false;
                }
                else {
                    dojo.addClass(radioBtnElement, "active");
                    if (textField.length > 0) {
                        radioBtn.checked = true;
                        //textField[0].value = "";
                        textField[0].focus();
                        dojo.addClass(textField[0], 'required');
                    }

                }
            });
        });
    });
    /* end of custom radioButtons */

    /* folding Fieldsets */
    var feedbackForms = dojo.query('.feedbackForm');
    dojo.forEach(feedbackForms, function (form) {
        var openHeight = dojo.marginBox(form).h;
        dojo.addClass(form, "closed");
        var clickElements = dojo.query('strong', form);
        dojo.forEach(clickElements, function (clickElement) {
            var closedHeight = dojo.marginBox(clickElement).h;
            dojo.connect(clickElement, "onclick", function (e) {
                var otherForms = dojo.query('.feedbackForm');
                dojo.forEach(otherForms, function (otherForm) {
                    dojo.animateProperty({
                        node: otherForm,
                        properties: {
                            height: { end: closedHeight, units: "px" }
                        },
                        duration: 350,
                        onEnd: function () { dojo.addClass(otherForm, "closed"); }
                    }).play();
                });
                if (dojo.hasClass(form, "closed")) {
                    dojo.animateProperty({
                        node: form,
                        properties: {
                            height: { end: openHeight, units: "px" }
                        },
                        duration: 350,
                        onEnd: function () { dojo.removeClass(form, "closed"); }
                    }).play();
                }
                else {
                    dojo.animateProperty({
                        node: form,
                        properties: {
                            height: { end: closedHeight, units: "px" }
                        },
                        duration: 350,
                        onEnd: function () { dojo.addClass(form, "closed"); }
                    }).play();
                }
            });
        });
    });
    /* end of folding Fieldsets */

    /* GoogleMaps route */
    function GoogleMapsRoute() {
        var submitButton = dojo.byId('executeButton');
        if (submitButton != null) {
            dojo.connect(submitButton, "onclick", function (e) {
                dojo.stopEvent(e);
                var daddr = dojo.byId('daddr').value;
                var saddr = dojo.byId('saddr').value;
                var goToUrl = "http://maps.google.nl/?daddr=" + daddr + "&saddr=" + saddr;
                window.open(goToUrl);
            });
        }
    }
    GoogleMapsRoute();
    /* end of GoogleMaps route */

    /* googleMaps view */
    function ShowGoogleMaps() {
        var googleMapsHolders = dojo.query('.googleMapsHolder');
        if (googleMapsHolders.length > 0) {
            var map;
            var myPano;
            var panoClient;
            var nextPanoId;

            function initialize() {

                var latitudeValue = parseFloat(dojo.byId('latitude').value);
                var longitudeValue = parseFloat(dojo.byId('longitude').value);
                var povRotationValue = parseFloat(dojo.byId('pov_rotation').value);
                var povPitchValue = parseFloat(dojo.byId('pov_pitch').value);

                var conclusionBuilding = new GLatLng(latitudeValue, longitudeValue);
                var conclusionBuildingPOV = { yaw: povRotationValue, pitch: povPitchValue };

                panoClient = new GStreetviewClient();

                map = new GMap2(document.getElementById("map_canvas"));
                var customUI = map.getDefaultUI();
                // Remove MapType.G_HYBRID_MAP
                customUI.maptypes.hybrid = false;
                map.setUI(customUI);
                map.addOverlay(new GMarker(conclusionBuilding));


                map.setCenter(conclusionBuilding, 15);
                GEvent.addListener(map, "click", function (overlay, latlng) {
                    panoClient.getNearestPanorama(latlng, showPanoData);
                });

                myPano = new GStreetviewPanorama(document.getElementById("pano"));
                myPano.setLocationAndPOV(conclusionBuilding, conclusionBuildingPOV);
                GEvent.addListener(myPano, "error", handleNoFlash);
                panoClient.getNearestPanorama(conclusionBuilding, showPanoData);
            }

            function showPanoData(panoData) {
                var locationName = dojo.byId('location_name').value;
                if (panoData.code != 200) {
                    //GLog.write('showPanoData: Server rejected with code: ' + panoData.code);
                    return;
                }
                nextPanoId = panoData.links[0].panoId;
                var displayString = [
				"<strong>" + locationName + "</strong>",
                //"LatLng: " + panoData.location.latlng,
                //"Copyright: " + panoData.copyright,
                //panoData.location.description,
                //"Next Pano ID: " + panoData.links[0].panoId
			  ].join("<br/>");
                map.openInfoWindowHtml(panoData.location.latlng, displayString);

                //GLog.write('Viewer moved to' + panoData.location.latlng);
                myPano.setLocationAndPOV(panoData.location.latlng);
            }

            function next() {
                // Get the next panoId
                // Note that this is not sophisticated. At the end of the block, it will get stuck
                panoClient.getPanoramaById(nextPanoId, showPanoData);
            }

            function handleNoFlash(errorCode) {
                if (errorCode == 603) {
                    alert("Error: Flash doesn't appear to be supported by your browser");
                    return;
                }
            }
            initialize();
            dojo.addOnUnload(GUnload);
        }
    }
    ShowGoogleMaps();
    /* end of googleMaps view */

    /* serviceList */
    function ServiceList() {
        var holderList = dojo.query('.resultListHolder');

        if (holderList.length == 0) return;

        resultList = holderList[0];
        holderList = null;

        var _endPos = 0;
        var deltaY = 0;
        var previousPos = 0;
        function updateScroll() {
            deltaY = _endPos - resultList.scrollTop;
            //~ console.log(Math.abs(deltaY));
            //~ if(Math.abs(deltaY) > 1)

            previousPos = resultList.scrollTop;
            var endResult = resultList.scrollTop + (0.3 * (deltaY));
            resultList.scrollTop = endResult;

            if (Math.abs(deltaY) < 1) {
                clearInterval(windowId);
                windowId = null;
            }
            if (resultList.scrollTop == previousPos) {
                _endPos = resultList.scrollTop;
            }
        }
        var windowId = window.setInterval(updateScroll, 10);

        //scroll to the right content
        var indexItems = dojo.query('.index li a');
        dojo.forEach(indexItems, function (indexItem) {
            dojo.connect(indexItem, "onclick", function (e) {
                dojo.stopEvent(e);
                currentClass = '.' + indexItem.innerHTML;

                var linkedContent = dojo.query(currentClass);
                //alert(linkedContent + ":" + resultList)
                if (linkedContent != undefined && linkedContent != null && linkedContent != "") {

                    var scrollPosition = dojo.coords(linkedContent[0]).y - dojo.coords(resultList).y;
                    scrollPosition += resultList.scrollTop;

                    _endPos = scrollPosition;
                    //alert(resultList.scrollTop);
                    if (windowId == null) {
                        windowId = window.setInterval(updateScroll, 10);
                    }
                }
            });
        });


        //open the list under the clicked word
        var serviceItems = dojo.query('.resultList .serviceItem');
        dojo.forEach(serviceItems, function (serviceItem) {
            dojo.removeClass(serviceItem, "active");
            dojo.connect(serviceItem, "onclick", function (e) {
                dojo.forEach(serviceItems, function (otherElement) {
                    dojo.removeClass(otherElement, "active");
                });
                dojo.addClass(serviceItem, "active");
            });
        });
    }
    ServiceList();
    /* end of serviceList */

    /* randomImage */
    function getRandomNumber(maxNumber) {
        //var maxNumber = 8; //het hoogste getal dat random kan worden gegenereerd
        var number = (Math.random() * maxNumber) + 1; //maak een random getal aan
        var randomNumber = Math.floor(number); //rond af naar beneden zodat het een heel getal wordt
        return randomNumber;
    }
    function randomImage() {
        var signatures = dojo.query('.randomArtwork img');
        dojo.forEach(signatures, function (signature) {
            signature.src = "/Sites/Conclusion/images/footerArtwork/sign_" + getRandomNumber(15) + ".jpg";
        });

        var headerImages = dojo.query('.headerImage');
        dojo.forEach(headerImages, function (headerImage) {
            headerImage.src = "/Sites/Conclusion/images/headerArtwork/header_" + getRandomNumber(29) + ".jpg";
        });

        var homepageArt = dojo.query('.backgroundImage');
        dojo.forEach(homepageArt, function (art) {
            art.src = "/Sites/Conclusion/images/headerArtwork/homeArt" + getRandomNumber(8) + ".jpg";
        });
    }
    randomImage();
    /* end of randomImage */

    /* homepage personSwitcher */
    function personSwitch() {
        var linkHolder = document.createElement('div');
        linkHolder.className = "transparent";
        var pageContent = dojo.query('.pageContent');
        dojo.forEach(pageContent, function (element) {
            dojo.style(linkHolder, "opacity", 0.65);
            element.appendChild(linkHolder);
        });

        var i = 0;
        var itemCount = dojo.query('.pageContent ul.invisible li').length;
        var hiddenInfoList = dojo.query('.pageContent ul.invisible')[0];

        function showNextPerson(listElement, i) {
            if (hiddenInfoList != undefined) {
                dojo.style(dojo.query('.personPicture')[0], "opacity", 0);
                var companyLinkURL = dojo.query('li .companyLink', listElement)[i].href;
                var functionName = dojo.query('li .companyLink', listElement)[i].innerHTML;
                var linkedInURL = dojo.query('li .linkedIn', listElement)[i].href;
                var personPicture = dojo.query('li .person', listElement)[i].href;
                var personName = dojo.query('li .person', listElement)[i].innerHTML;

                dojo.query('.personInfo .linkedIn')[0].innerHTML = personName + ",";
                dojo.query('.personInfo .linkedIn')[0].href = linkedInURL;
		dojo.query('.personInfo .linkedIn')[0].target = "_blank";
                dojo.query('.personInfo .companyLink')[0].innerHTML = functionName;
                dojo.query('.personInfo .companyLink')[0].href = companyLinkURL;
                dojo.query('.personPicture img')[0].src = personPicture;
                //dojo.query('.personPicture img')[0].alt += personName;
                dojo.query('.personPicture img')[0].alt = "foto van " + personName;
                var bgImage = dojo.query('.backgroundImage')[0].src;
                dojo.style(dojo.query('.personPicture')[0], "background", "url(" + bgImage + ") -505px -2px");

                animateIn();
            }
        }

        function animateIn() {
            dojo.animateProperty({
                node: dojo.query('.personPicture')[0],
                properties: {
                    opacity: { end: 1 }
                },
                duration: 350,
                onEnd: function () { }
            }).play();
        }

        function animateOut() {
            dojo.animateProperty({
                node: dojo.query('.personPicture')[0],
                properties: {
                    opacity: { end: 0 }
                },
                duration: 350,
                onEnd: function () { showNextPerson(hiddenInfoList, i); }
            }).play();
        }
        /*function animateInLTR(){
        dojo.animateProperty({
        node:dojo.query('.personPicture')[0],
        properties: {
        opacity: { end: 1 }
        },
        duration: 350,
        onEnd: function(){}
        }).play();
        }
		
        function animateOutLTR(){
        dojo.animateProperty({
        node:dojo.query('.personPicture')[0],
        properties: {
        opacity: { end: 0 }
        },
        duration: 350,
        onEnd: function(){showNextPerson(hiddenInfoList, i, "LTR");}
        }).play();
        }*/

        var personStartId = getRandomNumber(itemCount);
        //alert(personStartId);
        showNextPerson(hiddenInfoList, personStartId);

        var btnNext = dojo.query('.pageContent .arrowRight');
        dojo.forEach(btnNext, function (btn) {
            dojo.connect(btn, "onclick", function (e) {
                dojo.stopEvent(e);
                if (i < (itemCount - 1)) {
                    i++;
                }
                else {
                    i = 0;
                }
                animateOut();
            });
        });

        var btnPrev = dojo.query('.pageContent .arrowLeft');
        dojo.forEach(btnPrev, function (btn) {
            dojo.connect(btn, "onclick", function (e) {
                dojo.stopEvent(e);
                if (i <= 0) {
                    i = itemCount;
                }
                i--;
                animateOut();
            });
        });
    }
    personSwitch();
    /* end of homepage personSwitcher */

    /* formMessage */
    var messageHolder = dojo.query('.errorFieldset, .feedbackFieldset');
    dojo.forEach(messageHolder, function (holder) {

        dojo.removeClass(holder, "closed");

        var titleElement = dojo.query('.errorFieldset strong, .feedbackFieldset strong')[0];
        var divList = dojo.query('.feedbackMessage > div, .errorMessage > div', holder);
        var newHeight = dojo.marginBox(holder).h - dojo.marginBox(titleElement).h - 30;
        dojo.forEach(divList, function (divItem) {
            dojo.style(divItem, "height", newHeight + "px");
        });

        var message = dojo.query('.errorMessage, .feedbackMessage', holder);
        dojo.forEach(message, function (msg) {
            var closeBtn = dojo.query('.close', msg);
            dojo.forEach(closeBtn, function (btn) {
                dojo.connect(btn, "onclick", function (e) {
                    dojo.stopEvent(e);
                    dojo.style(msg, "display", "none");
                    dojo.removeClass(holder, "errorFieldset");
                    dojo.removeClass(holder, "feedbackFieldset");
                });
            });
        });
    });
    /* end of formMessage */








    /* mediaLightBox */
    /*
    var exampleButton = dojo.byId("lbButton");
    dojo.connect(exampleButton, "onclick", function(e){
    dojo.stopEvent(e);
    //loadContent(e.target.href);
    createUnderLayer(e.target.href);
		
    });
    dojo.connect(window, "resize", posLightBox);

    var viewport = dijit.getViewport();
    var documentBody = dojo.query('body')[0];
    var documentHeight = dojo.marginBox(documentBody).h;
    var underLayer = document.createElement('div');
    underLayer.id = "id_underLayer";
    var lightBox = document.createElement('div');
    lightBox.id = "id_lightBox";
    var closeBtn = document.createElement('a');
    closeBtn.id = "id_closeBtn";
    var loaderImage = document.createElement('img');
    loaderImage.id = "id_loaderImage";
    loaderImage.src = "/Sites/Conclusion/images/ajax-loader.gif";
    var mediaTitle = document.createElement('h1');
    mediaTitle.id = "id_mediaTitle";
    var mediaHolder = document.createElement('div');
    mediaHolder.id = "id_mediaHolder";
    var mediaMetaInfo = document.createElement('p');
    mediaMetaInfo.id = "id_mediaMetaInfo";
    var mediaDescription = document.createElement('p');
    mediaDescription.id = "id_mediaDescription";
	
    function createUnderLayer(source){
    //dojo.stopEvent(e);
    dojo.style(underLayer, "opacity", 0);
    dojo.style(loaderImage, "opacity", 1);
    documentBody.appendChild(underLayer);		
    dojo.connect(underLayer, "onclick", hideLightBox);
    posLightBox();
    showUnderLayer(source);
    }
	
    function createLightBox(data){
    documentBody.appendChild(lightBox);
    var lbSizes = dojo.marginBox(lightBox);
    dojo.style(lightBox, "top", "100px");
    dojo.style(lightBox, "left", ((viewport.w - lbSizes.w)/2)+"px");
		
    mediaTitle.innerHTML = data.media.title;
    mediaMetaInfo.innerHTML = data.media.metainfo;
    mediaDescription.innerHTML = data.media.description;
		
    lightBox.appendChild(closeBtn);
    lightBox.appendChild(mediaTitle);
    lightBox.appendChild(mediaHolder);
    lightBox.appendChild(mediaMetaInfo);
    lightBox.appendChild(mediaDescription);
		
    var so = new swfobject('/Sites/Conclusion/js/jwplayer/player.swf','id_player','640','360','9');
    so.addParam('allowfullscreen','true');
    so.addParam('allowscriptaccess','always');
    so.addParam('wmode','opaque');
    so.addVariable('file',data.media.source);
    so.write('id_mediaHolder');
		
    dojo.style(loaderImage, "opacity", 0);
    dojo.style(lightBox, "opacity", 0);
    showLightBox();
		
    dojo.connect(closeBtn, "onclick", hideLightBox);
    }
	
    function showUnderLayer(source){
    dojo.animateProperty({
    node:underLayer,
    properties: {
    opacity: { end: 0.95 }
    },
    duration: 250,
    onEnd: function(){underLayer.appendChild(loaderImage); loadContent(source);}
    }).play();
    }
	
    function hideUnderLayer(){
    //alert(deferred);
    //deferred.cancel();
    dojo.animateProperty({
    node:underLayer,
    properties: {
    opacity: { end: 0 }
    },
    duration: 250,
    onEnd: function(){documentBody.removeChild(underLayer);}
    }).play();
    }
	
    function showLightBox(){
    dojo.animateProperty({
    node:lightBox,
    properties: {
    opacity: { end: 1 }
    },
    duration: 500,
    onEnd: function(){}
    }).play();
    }
	
    function hideLightBox(e){
    dojo.stopEvent(e);
    dojo.animateProperty({
    node:lightBox,
    properties: {
    opacity: { end: 0 }
    },
    duration: 250,
    onEnd: function(){hideUnderLayer(); documentBody.removeChild(lightBox);}
    }).play();
    }
	
    function posLightBox(){
    viewport = dijit.getViewport();
    if((viewport.t+viewport.h) < documentHeight){
    //console.dir(viewport);
    dojo.style(underLayer, "height", (viewport.h) + "px");
    dojo.style(underLayer, "top", (viewport.t) + "px");
    }
    }
	
    function loadContent(source){
		
    //The parameters to pass to xhrGet, the url, how to handle it, and the callbacks.
    var xhrArgs = {
    url: source,
    handleAs: "json",
    load: function(data) {
    console.log('de json:');
    console.log(data.media.source);
    createLightBox(data);
    },
    error: function(error) {
    console.debug("An unexpected error occurred: " + error);
    }
    }
    var deferred = dojo.xhrGet(xhrArgs);
    //console.dir(deferred);
    }*/



    /*********************************************************************/
    dojo.declare("mediaLightBox", null, {
        viewport: null,
        documentBody: null,
        documentHeight: null,
        underLayer: null,
        lightBox: null,
        closeBtn: null,
        loaderImage: null,
        mediaTitle: null,
        mediaHolder: null,
        mediaMetaInfo: null,
        mediaDescription: null,
        ajaxCall: null,
        imageElement: null,
        maxImageWidth: 640,
        maxImageHeight: 480,
        navHolder: null,
        resizeLightBoxHandle: null,
        resizeUnderLayerHandle: null,

        constructor: function (element) {

            // initialize the basic properties
            this.viewport = dijit.getViewport();
            this.documentBody = dojo.query('body')[0];
            this.documentHeight = dojo.marginBox(this.documentBody).h;

            this.underLayer = document.createElement('div');
            this.underLayer.id = "id_underLayer";

            this.lightBox = document.createElement('div');
            this.lightBox.id = "id_lightBox";

            this.closeBtn = document.createElement('a');
            this.closeBtn.id = "id_closeBtn";

            this.loaderImage = document.createElement('img');
            this.loaderImage.id = "id_loaderImage";
            this.loaderImage.src = "/Sites/Conclusion/images/ajax-loader.gif";

            this.mediaTitle = document.createElement('h1');
            this.mediaTitle.id = "id_mediaTitle";

            this.mediaHolder = document.createElement('div');
            this.mediaHolder.id = "id_mediaHolder";

            this.mediaMetaInfo = document.createElement('p');
            this.mediaMetaInfo.id = "id_mediaMetaInfo";

            this.mediaDescription = document.createElement('p');
            this.mediaDescription.id = "id_mediaDescription";


            // attach the listeners
            dojo.connect(element, "onclick", dojo.hitch(this, function (e) {
                dojo.stopEvent(e);
                this._createUnderLayer(e.currentTarget);
            }));
        },
        _createUnderLayer: function (linkElement) {
            dojo.style(this.underLayer, "opacity", 0);
            dojo.style(this.loaderImage, "opacity", 1);
            this.documentBody.appendChild(this.underLayer);

            dojo.connect(this.underLayer, "onclick", this, this._hideLightBox);
            this._posUnderLayer();
            this._showUnderLayer(linkElement);
            this.resizeLightBoxHandle = dojo.connect(window, "resize", this, this._posLightBox);
            this.resizeUnderLayerHandle = dojo.connect(window, "resize", this, this._posUnderLayer);
        },
        _createLightBox: function (data) {
            this.documentBody.appendChild(this.lightBox);
            var lbSizes = dojo.marginBox(this.lightBox);
            dojo.style(this.lightBox, "top", "100px");
            dojo.style(this.lightBox, "left", ((this.viewport.w - lbSizes.w) / 2) + "px");

            this.mediaTitle.innerHTML = data.media.title;
            this.mediaMetaInfo.innerHTML = data.media.metainfo;
            this.mediaDescription.innerHTML = data.media.description;

            this.lightBox.appendChild(this.closeBtn);
            this.lightBox.appendChild(this.mediaTitle);
            this.lightBox.appendChild(this.mediaHolder);
            this.lightBox.appendChild(this.mediaMetaInfo);
            this.lightBox.appendChild(this.mediaDescription);

            if (data.media.type != "photo") {
                var flashHolder = document.createElement('div');
                flashHolder.id = "id_flashHolder";
                this.mediaHolder.appendChild(flashHolder);

                //new swfobject('/Sites/Conclusion/js/jwplayer/player.swf','id_mediaHolder','640','360','9');
                var flashvars = {};
                flashvars.height = "360";
                flashvars.width = "640";
                flashvars.file = data.media.source;
                if (data.media.type == "audio") {
                    flashvars.image = "/Sites/Conclusion/js/jwplayer/preview_audio.gif";
                }

                var params = {};
                params.allowfullscreen = "true";
                params.allowscriptaccess = "always";
                params.wmode = "opaque";

                var attributes = {};
                swfobject.embedSWF("/Sites/Conclusion/js/jwplayer/player.swf", "id_flashHolder", "640", "360", "9.0.0", "images/expressInstall.swf", flashvars, params, attributes);

                /*var so = swfobject.embedSWF("/Sites/Conclusion/js/jwplayer/player.swf", "id_flashHolder",'640','360','9', "images/expressInstall.swf", data.media.source);
                so.addParam('allowfullscreen','true');
                so.addParam('allowscriptaccess','always');
                so.addParam('wmode','opaque');
                so.addVariable('file',data.media.source);
                if(data.media.type == "audio"){
                so.addVariable('image',"/Sites/Conclusion/js/jwplayer/preview_audio.gif");
                }
                so.write('id_mediaHolder');*/

                dojo.style(this.loaderImage, "opacity", 0);
                this._showLightBox();
            }

            //set image properties
            else {
                var imageElement = document.createElement('img');
                imageElement.src = data.media.source;
                this.mediaHolder.appendChild(imageElement);
                //this.lightBox.insertBefore(this.imageElement, this.mediaMetaInfo);
                dojo.style(imageElement, "visibility", "hidden");

                dojo.connect(imageElement, "load", this, this._setImageSizes);
            }
            dojo.style(this.lightBox, "opacity", 0);
            dojo.connect(this.closeBtn, "onclick", this, this._hideLightBox);
        },
        _showUnderLayer: function (linkElement) {
            dojo.animateProperty({
                node: this.underLayer,
                properties: {
                    opacity: { end: 0.95 }
                },
                duration: 250,
                onEnd: dojo.hitch(this, function () {
                    this.underLayer.appendChild(this.loaderImage);
                    this._loadContent(linkElement);
                    //if we have to show the conclusion story lightbox...
                    if (linkElement.id == "theStory") {
                        this._showStory(linkElement);
                    }
                })
            }).play();
        },
        _hideUnderLayer: function () {
            dojo.animateProperty({
                node: this.underLayer,
                properties: {
                    opacity: { end: 0 }
                },
                duration: 300,
                onEnd: dojo.hitch(this, function () {
                    //if the underlayer is already in the DOM, then remove it
                    if (this.underLayer.parentNode != undefined) {
                        this.documentBody.removeChild(this.underLayer);
                    }
                    this.ajaxCall.cancel();
                    dojo.disconnect(this.resizeLightBoxHandle);
                    dojo.disconnect(this.resizeUnderLayerHandle);
                }
				)
            }).play();
        },
        _showLightBox: function () {
            this._posLightBox();
            this._posUnderLayer();
            dojo.animateProperty({
                node: this.lightBox,
                properties: {
                    opacity: { end: 1 }
                },
                duration: 500,
                onEnd: function () { }
            }).play();
        },
        _hideLightBox: function (e) {
            dojo.stopEvent(e);
            dojo.animateProperty({
                node: this.lightBox,
                properties: {
                    opacity: { end: 0 }
                },
                duration: 250,
                onEnd: dojo.hitch(this, function () {
                    this._hideUnderLayer();

                    //if the lightbox is already in the DOM, then remove it
                    if (this.lightBox.parentNode != undefined) {
                        this.documentBody.removeChild(this.lightBox);
                    }

                    //remove the navElements from the 'storyComponent'
                    if (this.navHolder.parentNode != undefined) {
                        this.lightBox.removeChild(this.navHolder);
                    }

                    //remove the image from the DOM
                    var imageElements = dojo.query('img', this.lightBox);
                    dojo.forEach(imageElements, function (imageElement) {
                        imageElement.parentNode.removeChild(imageElement);
                    });

                }
				)
            }).play();
        },
        _posUnderLayer: function () {
            this.viewport = dijit.getViewport();
            dojo.style(this.underLayer, "height", (this.viewport.h) + "px");
            /*dojo.style(this.underLayer, "top", "0px");
            if((this.viewport.t+this.viewport.h) < this.documentHeight){
            //set top of the underlayer
            dojo.style(this.underLayer, "top", (this.viewport.t) + "px");
            }*/
        },
        _posLightBox: function () {
            //reposition top of the lightbox
            dojo.style(this.lightBox, "top", ((this.viewport.h / 2) - (dojo.marginBox(this.lightBox).h / 2)) + "px");

            //reposition left of the lightbox
            dojo.style(this.lightBox, "left", ((this.viewport.w / 2) - (dojo.marginBox(this.lightBox).w / 2)) + "px");
        },
        _showStory: function (linkElement) {
            //create a lightbox...
            this.documentBody.appendChild(this.lightBox);
            var lbSizes = dojo.marginBox(this.lightBox);
            dojo.style(this.lightBox, "top", "0px");
            dojo.style(this.lightBox, "left", ((this.viewport.w - lbSizes.w) / 2) + "px");

            //set the title...
            this.mediaTitle.innerHTML = "Conclusion - More Than One <span>(The corporate story)</span>";
            this.lightBox.appendChild(this.mediaTitle);

            //insert the image in the lightbox...
            this.lightBox.appendChild(this.mediaHolder);
            this.imageElement = document.createElement('img');
            this.imageElement.src = linkElement.href;
            this.mediaHolder.appendChild(this.imageElement);
            dojo.connect(this.imageElement, "onclick", this, this._nextImage);
            dojo.style(this.imageElement, "cursor", "pointer");

            //add the closebutton
            this.lightBox.appendChild(this.closeBtn);
            dojo.connect(this.closeBtn, "onclick", this, this._hideLightBox);

            //add pagenavigation...
            this.navHolder = document.createElement('div');
            this.navHolder.className = "pageNavigation";
            this.navHolder.innerHTML = '<a href="/Sites/Conclusion/images/brochure/page01.jpg" class="rightPage active" id="id_navPage_01"><span>1</span></a><a href="/Sites/Conclusion/images/brochure/page02.jpg" class="leftPage" id="id_navPage_02"><span>2</span></a><a href="/Sites/Conclusion/images/brochure/page03.jpg" class="rightPage" id="id_navPage_03"><span>3</span></a><a href="/Sites/Conclusion/images/brochure/page04.jpg" class="leftPage" id="id_navPage_04"><span>4</span></a><a href="/Sites/Conclusion/images/brochure/page05.jpg" class="rightPage" id="id_navPage_05"><span>5</span></a><a href="/Sites/Conclusion/images/brochure/page06.jpg" class="leftPage" id="id_navPage_06"><span>6</span></a><a href="/Sites/Conclusion/images/brochure/page07.jpg" class="rightPage" id="id_navPage_07"><span>7</span></a><a href="/Sites/Conclusion/images/brochure/page08.jpg" class="leftPage" id="id_navPage_08"><span>8</span></a><a href="/Sites/Conclusion/images/brochure/page09.jpg" class="rightPage" id="id_navPage_09"><span>9</span></a><a href="/Sites/Conclusion/images/brochure/page10.jpg" class="leftPage" id="id_navPage_10"><span>10</span></a><a href="/Sites/Conclusion/images/brochure/page11.jpg" class="rightPage" id="id_navPage_11"><span>11</span></a><a href="/Sites/Conclusion/images/brochure/page12.jpg" class="leftPage" id="id_navPage_12"><span>12</span></a><a href="/Sites/Conclusion/images/brochure/page13.jpg" class="rightPage" id="id_navPage_13"><span>13</span></a><a href="/Sites/Conclusion/images/brochure/page14.jpg" class="leftPage" id="id_navPage_14"><span>14</span></a><a href="/Sites/Conclusion/images/brochure/page15.jpg" class="rightPage" id="id_navPage_15"><span>15</span></a><a href="/Sites/Conclusion/images/brochure/page16.jpg" class="leftPage" id="id_navPage_16"><span>16</span></a><a href="/Sites/Conclusion/images/brochure/page17.jpg" class="rightPage" id="id_navPage_17"><span>17</span></a><a href="/Sites/Conclusion/images/brochure/page18.jpg" class="leftPage" id="id_navPage_18"><span>18</span></a><a href="/Sites/Conclusion/images/brochure/page19.jpg" class="rightPage" id="id_navPage_19"><span>19</span></a><a href="/Sites/Conclusion/images/brochure/page20.jpg" class="leftPage" id="id_navPage_20"><span>20</span></a><a href="/Sites/Conclusion/images/brochure/page21.jpg" class="rightPage" id="id_navPage_21"><span>21</span></a><a href="/Sites/Conclusion/images/brochure/page22.jpg" class="leftPage" id="id_navPage_22"><span>22</span></a><a href="/Sites/Conclusion/images/brochure/page23.jpg" class="rightPage" id="id_navPage_23"><span>23</span></a><a href="/Sites/Conclusion/images/brochure/page24.jpg" class="leftPage" id="id_navPage_24"><span>24</span></a><a href="/Sites/Conclusion/images/brochure/page25.jpg" class="rightPage" id="id_navPage_25"><span>25</span></a><a href="/Sites/Conclusion/images/brochure/page26.jpg" class="leftPage" id="id_navPage_26"><span>26</span></a><a href="/Sites/Conclusion/images/brochure/page27.jpg" class="rightPage" id="id_navPage_27"><span>27</span></a><a href="/Sites/Conclusion/images/brochure/page28.jpg" class="leftPage" id="id_navPage_28"><span>28</span></a><a href="/Sites/Conclusion/images/brochure/page29.jpg" class="rightPage" id="id_navPage_29"><span>29</span></a><a href="/Sites/Conclusion/images/brochure/page30.jpg" class="leftPage" id="id_navPage_30"><span>30</span></a><a href="/Sites/Conclusion/images/brochure/page31.jpg" class="rightPage" id="id_navPage_31"><span>31</span></a><a href="/Sites/Conclusion/images/brochure/page32.jpg" class="leftPage" id="id_navPage_32"><span>32</span></a><a href="/Sites/Conclusion/images/brochure/page33.jpg" class="rightPage" id="id_navPage_33"><span>33</span></a><a href="/Sites/Conclusion/images/brochure/page34.jpg" class="leftPage" id="id_navPage_34"><span>34</span></a><a href="/Sites/Conclusion/images/brochure/page35.jpg" class="rightPage" id="id_navPage_35"><span>35</span></a><a href="/Sites/Conclusion/images/brochure/page36.jpg" class="leftPage" id="id_navPage_36"><span>36</span></a>';
            this.lightBox.appendChild(this.navHolder);

            //hide the lightbox
            dojo.style(this.loaderImage, "opacity", 0);
            dojo.style(this.lightBox, "opacity", 0);
            dojo.style(this.lightBox, "width", "700px");

            //fade in the lightbox!
            this._showLightBox();

            //click on the pageindator actions
            var pageIndicators = dojo.query('.leftPage, .rightPage');
            dojo.forEach(pageIndicators, dojo.hitch(this, function (pageIndicator) {
                dojo.connect(pageIndicator, "onclick", dojo.hitch(this, function (e) {
                    dojo.stopEvent(e);
                    this._nextImage(e.target.href);
                }));
            }));
        },
        _nextImage: function (newImageSource) {

            var maxCount = 37;

            var srcLength;
            var srcLocation;
            var srcCount;

            if (dojo.isString(newImageSource)) {
                //if the user clicked on a pageindicator...
                srcLength = newImageSource.length;
                srcLocation = newImageSource.slice(0, (srcLength - 4));
                srcCount = srcLocation.slice((srcLocation.length - 2), srcLocation.length);
            }
            else {
                //if the user clicked on the picture itself: check the photonumber
                srcLength = this.imageElement.src.length;
                srcLocation = this.imageElement.src.slice(0, (srcLength - 4));
                srcCount = srcLocation.slice((srcLocation.length - 2), srcLocation.length);
                srcCount++;
            }

            //if it's not the last one...
            if (srcCount < maxCount) {

                //fade out the current photo		
                dojo.animateProperty({
                    node: this.imageElement,
                    properties: {
                        opacity: { end: 0 }
                    },
                    duration: 150,
                    onEnd: function (element) {

                        //set the right img src for the next image...						
                        srcCount = "" + srcCount;
                        if (srcCount.length < 2) {
                            srcCount = "0" + srcCount;
                        }
                        element.src = srcLocation.slice(0, (srcLocation.length - 2)) + srcCount + ".jpg";

                        //set the right pageIndicator on active
                        var pageIndicators = dojo.query('.leftPage, .rightPage');
                        dojo.forEach(pageIndicators, function (pageIndicator) {
                            dojo.removeClass(pageIndicator, "active");
                        });
                        var nextIndicator = "id_navPage_" + srcCount;
                        var activeIndicator = dojo.byId(nextIndicator);
                        dojo.addClass(activeIndicator, "active");

                        //show the next image when it's loaded...
                        dojo.connect(element, "load", function (e) {
                            dojo.animateProperty({
                                node: e.target,
                                properties: {
                                    opacity: { end: 1 }
                                },
                                duration: 150
                            }).play();
                        });

                    }
                }).play();
            }
            /*
            //set the right img src for the next image...
            var srcLength = this.imageElement.src.length;
            var srcLocation = this.imageElement.src.slice(0,(srcLength-4));
            var srcCount = srcLocation.slice((srcLocation.length-2),srcLocation.length);
            srcCount++;
            srcCount = ""+srcCount;
            if(srcCount.length < 2){
            srcCount = "0"+srcCount;
            }
            this.imageElement.src = srcLocation.slice(0,(srcLocation.length-2))+srcCount+".jpg";
			
            //show the next image...
            dojo.animateProperty({
            node:this.imageElement,
            properties: {
            opacity: { end: 1 }
            },
            duration: 500
            }).play();
            */
        },
        _setImageSizes: function (e) {
            var imageElement = e.target;
            var imageSizes = dojo.marginBox(imageElement);

            //if the image width exeeds the maximum...
            if (imageSizes.w > imageSizes.h && imageSizes.w > this.maxImageWidth) {
                dojo.style(imageElement, "width", this.maxImageWidth + "px");
                var widthDivider = imageSizes.w / this.maxImageWidth;
                dojo.style(imageElement, "height", (imageSizes.h / widthDivider) + "px");
            }
            //if the image height exeeds the maximum...
            else if (imageSizes.h > imageSizes.w && imageSizes.h > this.maxImageHeight) {
                dojo.style(imageElement, "height", this.maxImageHeight + "px");
                var heightDivider = imageSizes.h / this.maxImageHeight;
                dojo.style(imageElement, "width", (imageSizes.w / heightDivider) + "px");
            }
            this._posLightBox();
            this._posUnderLayer();
            dojo.style(imageElement, "visibility", "visible");
            dojo.style(this.loaderImage, "opacity", 0);
            this._showLightBox();
        },
        _loadContent: function (linkElement) {
            //The parameters to pass to xhrGet, the url, how to handle it, and the callbacks.
            var xhrArgs = {
                url: linkElement.href,
                handleAs: "json",
                load: dojo.hitch(this, function (data) {
                    this._createLightBox(data);
                }),
                error: function (error) {
                    console.debug("An unexpected error occurred: " + error);
                }
            }
            this.ajaxCall = dojo.xhrGet(xhrArgs);
        }

    });
    var lightBoxLinks = dojo.query(".lightBoxLink");
    dojo.forEach(lightBoxLinks, function (lbLink) {
        new mediaLightBox(lbLink);
    });


    /***************************************************************************************************/


    /* end mediaLightBox */

    /* companyTicker */
    function companyTicker() {
        var documentBody = dojo.query('body')[0];
        dojo.addClass(documentBody, "tickerRuns");

        dojo.query(".tickerBase").forEach(function (elm) {
            var holder = dojo.query(">.tickerHolder", elm)[0];
            var content = dojo.query(">.tickerContent", holder)[0];
            var uls = dojo.query("ul", holder); //
            var length = 0;
            var width = dojo.coords(holder).w;
            var newLength = 0;
            var directionRight = true;

            dojo.query("a.forward").connect("onclick", function (e) {
                dojo.stopEvent(e);
                directionRight = false;
            });
            dojo.query("a.back").connect("onclick", function (e) {
                dojo.stopEvent(e);
                directionRight = true;
            });

            if (uls.length == 1) {
                var lis = dojo.query("li", uls[0]);

                dojo.forEach(lis, function (li) {
                    length += dojo.coords(li).w;
                });
                newLength = length;
                do {
                    uls[0].parentNode.appendChild(dojo.clone(uls[0]));
                    newLength += length;
                } while (newLength < 2 * width);
            }
            var currentPos = 0;
            window.setInterval(function (e) {
                if (directionRight) {
                    currentPos -= 1;
                    if (-currentPos >= (newLength - width)) {
                        currentPos += length;
                    }
                } else {
                    currentPos += 1;
                    if (currentPos > 0) {
                        currentPos -= length;
                    }
                }
                dojo.style(content, "marginLeft", currentPos + "px");
            }, 100);
        });
    }
    companyTicker();
    /* end of companyTicker */

    /* social menu */
    var socialMenu = dojo.query('.addthis_toolbox');
    dojo.forEach(socialMenu, function (menu) {
        var status = "closed";
        dojo.connect(menu, "onclick", function (e) {
            dojo.stopEvent(e);
            if (status == "closed") {
                dojo.animateProperty({
                    node: menu,
                    properties: {
                        height: { end: 250, units: "px" }
                    },
                    duration: 350,
                    onEnd: function () { status = "open"; }
                }).play();
            }
            else if (status == "open") {
                dojo.animateProperty({
                    node: menu,
                    properties: {
                        height: { end: 18, units: "px" }
                    },
                    duration: 350,
                    onEnd: function () { status = "closed"; }
                }).play();
            }
        });
    });
    /* end of social menu*/

    /* storyBtn */

    var storyBtn = dojo.query('.page .header #theStory');
    dojo.forEach(storyBtn, function (btn) {


        function showBtn() {
            dojo.animateProperty({
                node: btn,
                properties: {
                    height: { end: 14, units: "px" }
                },
                duration: 1250,
                onEnd: function () {
                    dojo.animateProperty({
                        node: btn,
                        properties: {
                            width: { end: 19, units: "px" }
                        },
                        duration: 1000
                    }).play();
                }
            }).play();
            //alert('henk');
        }
        setTimeout(dojo.hitch(btn, showBtn), 2000);

        dojo.connect(btn, "onmouseover", function (e) {
            dojo.animateProperty({
                node: btn,
                properties: {
                    width: { end: 166, units: "px" }
                },
                duration: 500
            }).play();
        });

        dojo.connect(btn, "onmouseout", function (e) {
            dojo.animateProperty({
                node: btn,
                properties: {
                    width: { end: 19, units: "px" }
                },
                duration: 500
            }).play();
        });
    });
    /* end of storyBtn */


    // Basket Builders//

    /* add class to active contact / vestiging */
    var activeContact = dojo.query('.contactNavigation li');
    dojo.forEach(activeContact, function (ctItem) {
        if (ctItem.id == ntb_int_CurrentContentID) {
            dojo.addClass(ctItem, "active");
        }
    });
    // Einde Basket Builders//

});

// Basket Builders//

function changeURL() {
    linkje = dojo.byId('year').value + '.aspx?year=' + dojo.byId('year').value
    location.href = linkje;
}
function EnterKeyPressed(url) {
    e = window.event

    if (e) {

        if (e.keyCode == 13) {
            location.href = url;
            return true;
        }
        return false;
    }
    return false;
}

function ValidateSearchBox(source, args) {
    alert(args);
    if (args.Value != "") {
        args.IsValid = args.Value.length > 2;
    }
    else {
        args.IsValid = false;
    }
}

// Einde Basket Builders//

