<!--
/* <documentation about="Content.js" type="GENERAL">
	<summary>This file is specific javascript file for the content pages
		Structure of this file:
		1. Implementation of namespace Content
		2. Definition global variables
		3. Content.init: start javascript app
		4. Specific functions
	</summary>
	<namespace>Content</namespace>
</documentation> */
var Content = {};

/* <documentation about="Global variables" type="Global variables">
	<summary></summary>
	<namespace>Content</namespace>
</documentation> */

/* <documentation about="Content.init" type="init function">
	<summary>This function containes all calls made to functions used within Content.
		It is initialized on page load (Lib.addEvent(window, "load", Content.init);).
	</summary>
	<namespace>Content</namespace>
</documentation> */
Content.init = function() {
	//used for debugging - set to true in debugging mode
	Lib.debug = true;
	try {
		Lib.setPageIsStyled();

		Lib.addMainNavigationFoldOut();

		//add clearing text input fields on focus
		Lib.addDefaultTextAttribute("searchKeyword");
		Lib.inputAutoClear();

		//Lib.addResizingLinks(); removed for Dansserver

		Content.alignSlides();

		Content.addFaqFoldOuts();

        Content.subSubNavigation();

        if (Lib.ie6) {
            Content.leftAlignSite();
            Content.alignSponsors();
        }
	}
	catch (ex){ Lib.errHandler(ex); }
}

/* <documentation about="Content.reInit" type="reInit function">
	<summary>This function containes calls made to functions used on page resize.
	</summary>
	<namespace>Content</namespace>
</documentation> */
Content.reInit = function() {
	//used for debugging - set to true in debugging mode
	Lib.debug = true;
	try {
        if (Lib.ie6) {
            Content.leftAlignSite();
            Content.alignSponsors();
        }
	}
	catch (ex){ Lib.errHandler(ex); }
}

/* <documentation about="Content.scroll" type="scroll function">
	<summary>This function containes calls made to functions used when page is scrolled.
	</summary>
	<namespace>Content</namespace>
</documentation> */
Content.scroll = function() {
	//used for debugging - set to true in debugging mode
	Lib.debug = true;
	try {
        if (Lib.ie6) {
            Content.alignSponsors();
        }
	}
	catch (ex){ Lib.errHandler(ex); }
}

/* <documentation about="Content.leftAlignSite" type="specific  function    ie6only">
	<summary>Centres page until browser is wider than 1160 px, then page remains left aligned</summary>
	<namespace>Content</namespace>
</documentation> */
Content.leftAlignSite = function () {
    var winWidth = Lib.getWindowWidth();
    if (winWidth > 1160) {
        document.getElementById("allContainer").style.marginLeft = 100 + "px";
    }
    else {
        document.getElementById("allContainer").style.marginLeft = "auto";
    }
}

/* <documentation about="Content.alignSponsors" type="specific  function    ie6only">
	<summary></summary>
	<namespace>Content</namespace>
</documentation> */
Content.alignSponsors = function () {
    var winHeight = Lib.getWindowHeight();
    var winScroll = Lib.getScrollY();
    document.getElementById("sponsors").style.position = "absolute";
    document.getElementById("sponsors").style.top = (winHeight + winScroll) - 80 + "px";
}

/* <documentation about="Content.alignSlides" type="specific  function">
	<summary>Aligns slides in page "persbericht"</summary>
	<namespace>Content</namespace>
</documentation> */
Content.alignSlides = function () {
    var imgs = Lib.getElementsByClassName("slide-image", "img");
    for (var i=0;i<imgs.length;i++) {
		var imgHeights = imgs[i].offsetHeight;
		var imgContainerheight = imgs[i].parentNode.offsetHeight; // get img container (slide) height
		var marginTop = (imgContainerheight -imgHeights)/2;// calculate the margin-top needed
		imgs[i].style.marginTop = marginTop+'px'; // set margin-top on images
   }
}


/* <documentation about="Content.addFaqFoldOuts" type="specific  function">
	<summary>Adds folding out panels to faq</summary>
	<namespace>Content</namespace>
</documentation> */
Content.addFaqFoldOuts = function () {
	var spans = Lib.getElementsByClassName("fold-out", "span");

	for (var i=0;i<spans.length;i++) {
		var hyperlink = document.createElement("a");
		hyperlink.href="#";
		hyperlink.innerHTML = spans[i].innerHTML;

		hyperlink.onclick = function () { toggleSummary(this); return false;  };
		Lib.eventCache.add(hyperlink, "onclick", function () { toggleSummary(this); return false; }, false);

		spans[i].parentNode.insertBefore(hyperlink, spans[i]);
		spans[i].parentNode.removeChild(spans[i]);
   	}
   	/* <documentation about="toggleSummary" type="private function in functionContent.addFaqFoldOuts">
		<summary>Toggles panels in faq</summary>
		<namespace>Content</namespace>
	</documentation> */
	var toggleSummary = function (hyperlink) {
		try {
			var summary = Lib.getNextElement(hyperlink);
			if(summary && summary.className == "summary") {
				summary.className = "summary hide";
				hyperlink.parentNode.className = "";
			}
			else if (summary && summary.className == "summary hide") {
				summary.className = "summary";
				hyperlink.parentNode.className = "open";
			}
		} catch (ex){ Lib.errHandler(ex); }
	}

}

/* <documentation about="Content.subSubNavigation" type="specific  function">
	<summary>Adds functionality to menu on detailPage template</summary>
	<namespace>Content</namespace>
</documentation> */
Content.subSubNavigation =  function() {
    var subArr = new Array;
	var subDivs = Lib.getElementsByClassName("subSubNavigation", "div");
    for (var j=0; j<subDivs.length; j++) {
        // link controlling visibility of subSubNavigation
        this.theLink = subDivs[j].parentNode.firstChild;
        // subSubNav
        this.ssNav = subDivs[j];
        subArr[subArr.length] = new subSubNav(this, this.theLink, this.ssNav, subDivs);
    }
}
var paneltimer;
subSubNav = function (subSubNavigation, theLink, ssNav, subDivs) {
    this.subSubNavigation = subSubNavigation;
    this.theLink = theLink;
    this.ssNav = ssNav;
    this.subDivs = subDivs;
    this.theLink.subSubNav = this;
    this.theLink.onclick = function () {
        clearTimeout(paneltimer);
        this.subSubNav.closeAll();
        this.subSubNav.toggleNav();
        return false;
    }
    this.theLink.onmouseover = function () {
        clearTimeout(paneltimer);
    }
    this.theLink.onmouseout = function () {
        var th = this;
		paneltimer = setTimeout(function() {th.subSubNav.closeAll();}, 800);
    }
    this.ssNav.subSubNav = this;
    this.ssNav.onmouseover = function () {
        clearTimeout(paneltimer);
    }
    this.ssNav.onmouseout = function () {
        var th = this;
		paneltimer = setTimeout(function() {th.subSubNav.closeAll();}, 800);
    }
}
subSubNav.prototype.closeAll = function () {
    for (var k=0; k<this.subDivs.length; k++) {
        this.subDivs[k].style.display = "none";
    }
}
subSubNav.prototype.toggleNav = function () {
    if (this.ssNav.style.display != "block") {
        this.ssNav.style.display = "block";
    }
}

/* <documentation about="Lib.addStyleSheet('./styles/javascript.css')" type="FUNCTION CALL">
	<summary>Add javascript style sheet for javascript specific styles</summary>
</documentation> */
Lib.addStyleSheet("./styles/javascript.css");

/* <documentation about="setFontSize" type="FUNCTION CALL">
	<summary>Set font size at initailisation of page</summary>
</documentation> */
if(Lib.getCookie("fontsize")) { Lib.setFontSize(Lib.getCookie("fontsize"), false);};

/* <documentation about="Content.init" type="FUNCTION CALL">
	<summary>Calling Lib.addEvent: Add Content.init as eventhandler on window onload event</summary>
</documentation> */
Lib.addEvent(window, "load", Content.init);
Lib.eventCache.add(window, "load", Content.init, false);

/* <documentation about="Content.reInit" type="FUNCTION CALL">
	<summary>Calling Lib.addEvent: Add Content.reInit as eventhandler on window onresize event</summary>
</documentation> */
Lib.addEvent(window, "resize", Content.reInit);
Lib.eventCache.add(window, "resize", Content.reInit, false);

/* <documentation about="Content.scroll" type="FUNCTION CALL">
	<summary>Calling Lib.addEvent: Add Content.scroll as eventhandler on window scroll event</summary>
</documentation> */
Lib.addEvent(window, "scroll", Content.scroll);
Lib.eventCache.add(window, "scroll", Content.scroll, false);

//-->
