<!--
/* (CC) 2007 Eden Design
/* <documentation about="ABOUT Content.js" type="GENERAL">
	<summary>Rabobank Special Products javascript file
		Structure of this file:
		1. Implementation of namespace:
			- Content
		2. Definition global variables
		3. Functions
		4. Call: Lib.addEvent(window, "load", Content.init); start js application
	</summary>
	<namespace>Content</namespace>
</documentation> */
var Content = {};

/* <documentation about="Global variables" type="global variables">
	<summary></summary>
	<namespace>Content</namespace>
</documentation> */
Content.currentInfoBoxLink = null;
Content.infoBoxLinkIsClicked = false;

/* <documentation about="Content.init" type="init function">
	<summary>This function containes all calls made to functions used within Content application.
		It is initialized on page load (Lib.addEvent(window, "load", Content.init);).
	</summary>
	<namespace>Content</namespace>
</documentation> */
Content.init = function (){
	Lib.debug = true;	//set to false to suppress errors
	try {
		Lib.setPageIsStyled();
		Content.addFoldingTabs();
		Content.addInfoBoxes()
		Lib.styleDropdowns();
		Default.addProductAction();
		Content.addCheckMarksToggle();
	}
	catch (ex){ Lib.errHandler(ex); }
}

/* <documentation about="Content.addCheckMarksToggle" type="specific function">
	<summary>Adds onclick class change to checkmark links</summary>
</documentation> */
Content.addCheckMarksToggle = function () {

	var CheckMarkLinks = Lib.getElementsByClassName("checkbox", "a");

	for(var i=0; i<CheckMarkLinks.length;i++) {

		CheckMarkLinks[i].onclick = function() {
			if (this.className.indexOf("unchecked") != -1) {
				this.className = this.className.replace(" unchecked","");
				onChecked(this.name, true);
			}
			else {
				this.className = this.className += " unchecked";
				onChecked(this.name, false);
			}
			return false;
		}
	}
}

/* <documentation about="Content.addFoldingTabs" type="specific function">
	<summary>Adds folding tab functionality</summary>
</documentation> */
Content.addFoldingTabs = function () {
	var toggleTab = function (hyperlink) {
		if(hyperlink.tabContent.className == "tabcontent") {
			hyperlink.tabContent.className = "tabcontent hide";
			hyperlink.tab.className = "tab";
		}
		else  {
			hyperlink.tabContent.className = "tabcontent";
			hyperlink.tab.className = "tab open";
		}
	}

	var tabs = Lib.getElementsByClassName("tab", "div");

	for(var i=0; i<tabs.length;i++) {
		var span = tabs[i].getElementsByTagName("span")[0];

		var hyperlink = document.createElement("a");
		hyperlink.href="#";
		hyperlink.innerHTML = span.innerHTML;
		hyperlink.tab = tabs[i];
		hyperlink.tabContent = Lib.getNextElement(tabs[i]);
		hyperlink.onclick = function () { toggleTab(this);return false; };
		Lib.eventCache.add(hyperlink, "onclick", function () { toggleTab(this);return false; }, false);

		tabs[i].removeChild(span);  			//remove span
		tabs[i].appendChild(hyperlink);			//add link
	}
}

/* <documentation about="Content.addInfoBoxes" type="specific function">
	<summary>Adds info box ('i') functionality</summary>
</documentation> */
Content.addInfoBoxes = function () {
	var toggleInfoBox = function (hyperlink) {
		if(!Content.currentInfoBoxLink) {
			Content.infoBoxLinkIsClicked = true;
			Content.currentInfoBoxLink = hyperlink;

			Content.currentInfoBoxLink.className = "info active";

			var body = document.getElementsByTagName("body")[0];
			var container = document.getElementById("container");
			var infoBox = Lib.getNextElement(hyperlink);
			infoBox.className = "infoBox";
			infoBox.id = "currentInfoBox";
			body.insertBefore(infoBox, container);

			var position = Lib.findElementPosition(hyperlink);
			infoBox.style.left = (position[0] + 12) + "px";
			infoBox.style.top = position[1] + "px";
		}
		else {  removeInfoBox();  }
	}

	var removeInfoBox = function () {
		var currentInfoBox = document.getElementById("currentInfoBox");
		currentInfoBox.id = "";
		currentInfoBox.className =  "infoBox hide";
		Content.currentInfoBoxLink.className = "info";
		Content.currentInfoBoxLink.parentNode.appendChild(currentInfoBox);
		Content.currentInfoBoxLink = null;
	}

	var documentClick = function() {
		if(Content.currentInfoBoxLink && !Content.infoBoxLinkIsClicked) { removeInfoBox(); }
		Content.infoBoxLinkIsClicked = false;
	}

	var infoLinks = Lib.getElementsByClassName("info", "a");

	for(var i=0; i<infoLinks.length;i++) {
		infoLinks[i].onclick = function () { toggleInfoBox(this); return false;  };
		Lib.eventCache.add(infoLinks[i], "onclick", function () { toggleInfoBox(this); return false;  }, false);
	}

	Lib.addEvent (document, "click", documentClick);
	Lib.eventCache.add(document, "onclick", documentClick, 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);
-->

