<!--
/* <documentation about="ABOUT js/default.js" type="GENERAL">
	<summary>This file is specific javascript file for UCB Internet site. 
		
		Structure of this file:         
		1. 
		2.
		3. 
		4. 
	</summary>
	<namespace>UCBNeupro</namespace>
</documentation> */
UCBNeupro = {};

/* <documentation about="UCBNeupro.init" type="init function">
	<summary>This function containes all calls made to functions used within UCB website.
		It is initialized on page load (Lib.addEvent(window, "load", UCBNeupro.init);).	
	</summary>
	<namespace>UCBNeupro</namespace>
</documentation> */
UCBNeupro.init = function() {
	try {
		Lib.debug = true; 
		
		UCBNeupro.addButtonHovers();		
		
		UCBNeupro.addUtilities();
		UCBNeupro.initUtilities();
		

		
		UCBNeupro.addMenuTabHovers();
		UCBNeupro.addTableRowHovers();
		UCBNeupro.addListItemHovers();
		
		Lib.addDefaultTextAttribute(document.getElementById("site-search"));
		Lib.inputAutoClear(document.getElementById("site-search"));
		
		/* <documentation about="UCBNeupro.resizeUtilScreen" type="FUNCTION CALL">
			<summary>Calling Lib.addEvent: Add UCBNeupro.resizeUtilScreen as eventhandler on window resize event</summary>
		</documentation> */
		Lib.addEvent(window, "resize", UCBNeupro.resizeUtilScreen);
		Lib.eventCache.add(window, "resize", UCBNeupro.resizeUtilScreen, false); 
		
	}
	catch (ex){ Lib.errHandler(ex); }

}

/* <documentation about="UCBNeupro.addUtitlities" type="specific function">
	<summary>This function adds functionality to the utilitymenu</summary>
	<namespace>UCBNeupro</namespace>
</documentation> */
UCBNeupro.addUtilities = function(){
	// semi-opaque screen covers site when utility menus are activated:
	var d = document.createElement('div');
	d.id = "utility-screen";
	document.getElementById("header").appendChild(d);
	var fr = document.createElement('iframe');
	fr.id = 'utility-iframe';
	document.getElementById("header").appendChild(fr);
	
	// text-resize functionality:

	var textResize = Lib.getElementsByClassName("text-resize","li",document.getElementById("header"))[0];
	var textResizeLink = textResize.getElementsByTagName("a")[0];
	var textResizeBlock = Lib.getElementsByClassName("text-resize-block")[0];
	//textResizeBlock.bigResLeft = "350px";
	//textResizeBlock.smallResLeft = "250px";
	textResizeLink.onclick = function(){UCBNeupro.showUtility(textResizeBlock); return false; };
	Lib.eventCache.add(textResizeLink, "onclick", function(){UCBNeupro.showUtility(Lib.getElementsByClassName("text-resize-block")[0]); return false;}, false); 	
	
	var resizeClose = Lib.getElementsByClassName("close","a",textResizeBlock)[0];
	resizeClose.onclick = function(){ UCBNeupro.hideUtility(textResizeBlock); return false; };
	Lib.eventCache.add(resizeClose, "onclick",function(){ UCBNeupro.hideUtility(textResizeBlock); return false; }, false);
	
		//add resize functionality on links
		var resizeLinks = textResizeBlock.getElementsByTagName("a");
		
		//get fontsize for active link
		var fontSize = Lib.getCookie("fontsize");
		if(!fontSize) { fontSize = "medium"; }
		
		for(var i=0; i<resizeLinks.length; i++) {
			if(resizeLinks[i].className == "close") { continue; } //don not use close link
			
			if(resizeLinks[i].id == fontSize + "Font") { resizeLinks[i].className = "active"; }	//set active link on page load
			
			resizeLinks[i].allResizeLinks = resizeLinks;		//take all links with link; to be used in doResizeFont
			resizeLinks[i].textResizeBlock = textResizeBlock;	//take text resize block with link; to be used in doResizeFont
			
			//add doResizeFont on link click event 
			resizeLinks[i].onclick = function() { UCBNeupro.doResizeFont(this); return false; };
			Lib.eventCache.add(resizeLinks[i], "onclick", function() { UCBNeupro.doResizeFont(this); return false; }, false); 
		}
	
	
}

/* <documentation about="UCBNeupro.showUtitlity" type="specific function">
	<summary>This function shows the chosen utility</summary>
	<namespace>UCBNeupro</namespace>
	<param type="string" descr="Block that you want to be shown">utilityBlock</param>
</documentation> */
UCBNeupro.showUtility = function(utilityBlock){
	UCBNeupro.solveIE7SitemapBug();
	var calculatedLeftPos = (Lib.getWindowWidth()-utilityBlock.offsetWidth)/2;
	if(calculatedLeftPos<20) calculatedLeftPos = 20;

	var calculatedTopPos = (Lib.getWindowHeight()-utilityBlock.offsetHeight)/2;
	if(calculatedTopPos<20) calculatedTopPos = 20;
	utilityBlock.style.left = calculatedLeftPos + "px";
	utilityBlock.style.top = calculatedTopPos + "px";
	Lib.showElements(document.getElementById("utility-screen"), document.getElementById("utility-iframe")); 
	UCBNeupro.resizeUtilScreen();
}

/* <documentation about="UCBNeupro.hideUtitlity" type="specific function">
	<summary>This function hides the chosen utility</summary>
	<namespace>UCBNeupro</namespace>
	<param type="string" descr="Block that you want to be hidden">utilityBlock</param>
</documentation> */
UCBNeupro.hideUtility = function(utilityBlock){
	UCBNeupro.solveIE7SitemapBug();
	utilityBlock.style.left = "-999em";
	Lib.hideElements(document.getElementById("utility-screen"), document.getElementById("utility-iframe")); 
}


/* <documentation about="UCBNeupro.initUtilities" type="specific function">
	<summary>This function adds functionality to utility items so the "phone" utitility is returned to its default state</summary>
	<namespace>UCBNeupro</namespace>
</documentation> */
UCBNeupro.initUtilities = function() {
	var phoneListItem = Lib.getElementsByClassName("phone","li",document.getElementById("header"))[0];
	var phoneLink = phoneListItem.getElementsByTagName("a")[0];
	phoneLink.className = "active";
	var utilitiesList = Lib.getElementsByClassName("utilities","ul",document.getElementById("header"))[0];
	var utilitiesItems = utilitiesList.getElementsByTagName("a");
	for(var i=0; i<utilitiesItems.length; i++){
		if(utilitiesItems[i].parentNode.className.indexOf("phone")<0){
			utilitiesItems[i].phoneLink = phoneLink;
			utilitiesItems[i].onmouseover = function(){
				this.phoneLink.className = "inactive";
			}
			Lib.eventCache.add(utilitiesItems[i], "onmouseover",function(){ this.phoneLink.className = "inactive"; }, false);	
			utilitiesItems[i].onmouseout = function(){
				this.phoneLink.className = "active";
			}
			Lib.eventCache.add(utilitiesItems[i], "onmouseout",function(){ this.phoneLink.className = ""; }, false);	
			
		}
	}
}


/* <documentation about="UCBNeupro.solveIEySitemapBug" type="specific function">
	<summary>This function solves bug in IE7: relative position of ul.sitemap; interferes with text-resize-block</summary>
	<namespace>UCBNeupro</namespace>
</documentation> */
UCBNeupro.solveIE7SitemapBug = function () {
	if(Lib.getBodyId() != "sitemapPage" || !Lib.ie7) { return; }
	
	var ulSitemap = Lib.getElementsByClassName("sitemap", "ul")[0];
	
	if(ulSitemap.className=="sitemap") { ulSitemap.className = "sitemap static"; }
	else { ulSitemap.className = "sitemap"; }
}

/* <documentation about="UCBNeupro.resizeUtilScreen" type="specific function">
	<summary>This function resizes the utility screen when window is resized</summary>
	<namespace>UCBNeupro</namespace>
</documentation> */
UCBNeupro.resizeUtilScreen = function(){
	var allContainerHeight = document.getElementById("all-container").offsetHeight;
	if(document.getElementById("utility-screen")) {
		document.getElementById("utility-screen").style.height = allContainerHeight + "px";
		document.getElementById("utility-iframe").style.height = allContainerHeight + "px";
	}
}

/* <documentation about="UCBNeupro.addButtonHovers" type="specific function">
	<summary>This function adds the rollover functionality to submit-buttons</summary>
	<namespace>UCBNeupro</namespace>
</documentation> */
UCBNeupro.addButtonHovers = function(){
	var allButtons = Lib.getElementsByClassName("button");
	for(var i=0; i<allButtons.length; i++){
		if(allButtons[i].type == "image"){
			allButtons[i].onmouseover = function(){
				this.src = this.src.replace(".gif","-ro.gif");
			}
			Lib.eventCache.add(allButtons[i], "onmouseover",function(){ this.src = this.src.replace(".gif","-ro.gif"); }, false);	
			allButtons[i].onmouseout = function(){
				this.src = this.src.replace("-ro.gif",".gif");
			}
			Lib.eventCache.add(allButtons[i], "onmouseout",function(){ this.src = this.src.replace("-ro.gif",".gif"); }, false);	
		}
		if(allButtons[i].type == "submit"){
			allButtons[i].originalClass = allButtons[i].className;
			allButtons[i].onmouseover = function(){
				this.className = this.className+" hover";
			}
			Lib.eventCache.add(allButtons[i], "onmouseover",function(){ this.className = this.className+" hover"; }, false);	
			allButtons[i].onmouseout = function(){
				this.className = this.originalClass;
			}
			Lib.eventCache.add(allButtons[i], "onmouseout",function(){ this.className = this.originalClass; }, false);	
		}
	}
}

/* <documentation about="UCBNeupro.addMenuTabHovers" type="specific function">
	<summary>This function adds rollover behaviour to menu tabs</summary>
	<namespace>UCBNeupro</namespace>
</documentation> */
UCBNeupro.addMenuTabHovers = function(){
	var menuArr = new Array;
	if (!Lib.getElementsByClassName("menu")) { return; }
	var menuTabs = Lib.getElementsByClassName("menu");
	for(var i=0; i<menuTabs.length; i++){
		var menuListItems = menuTabs[i].getElementsByTagName("LI");
		for(var j=0; j<menuListItems.length; j++) {
			if (menuListItems[j].className != "current") {
				menuArr[menuArr.length] = new menuTab(this,menuListItems[j]);
			}
		}
	}
}
menuTab = function(addMenuTabHovers, listitem) {
	this.addMenuTabHovers = addMenuTabHovers;
	this.listitem = listitem;
	this.listitem.menuTab = this;
	this.listitem.onmouseover = function() {
		this.className = "active";
		return false;
	}
	this.listitem.onmouseout = function() {
		this.className = "";
		return false;
	}
}

/* <documentation about="UCBNeupro.addTablRowHovers" type="specific function">
	<summary>This function adds rollover functionality to tablerows</summary>
	<namespace>UCBNeupro</namespace>
</documentation> */
UCBNeupro.addTableRowHovers = function(){
	var hoverTableRow = function(currentLink){
		var currentRow = currentLink.parentRow;
		if(currentRow.className.indexOf("hovered")<0){
			currentRow.className = "hovered";
		} else {
			currentRow.className = "";
		}
	}
		
	var agendaTables = Lib.getElementsByClassName("agenda-table");
	
	for(var i=0; i<agendaTables.length; i++){
		var agendaRows = agendaTables[i].getElementsByTagName("tr");
		for(var n=0; n<agendaRows.length; n++){
			var rowLinks = agendaRows[n].getElementsByTagName("a");
			for(var q=0; q<rowLinks.length; q++){
				if(rowLinks[q].getElementsByTagName("span")[0] && rowLinks[q].getElementsByTagName("span")[0].className == "title"){
					rowLinks[q].parentRow = agendaRows[n];
					rowLinks[q].onmouseover = function(){
						hoverTableRow(this);
					}
					Lib.eventCache.add(rowLinks[q], "onmouseover", function () {  hoverTableRow(this); }, false);	
					rowLinks[q].onmouseout = function(){
						hoverTableRow(this);
					}
					Lib.eventCache.add(rowLinks[q], "onmouseout", function () {  hoverTableRow(this); }, false);	
				}
			}
		}
	}
}
/* <documentation about="UCBNeupro.addListItemHovers" type="specific function">
	<summary>This function adds rollover functionality to list items</summary>
	<namespace>UCBNeupro</namespace>
</documentation> */
UCBNeupro.addListItemHovers = function(){
	var hoverLists = new Array("overview-list");
	
	for(var i=0; i<hoverLists.length; i++){
		var currentLists = Lib.getElementsByClassName(hoverLists[i],"ul",document.getElementById("page-content"));	
		for(var n=0; n<currentLists.length; n++){
			var currentItems = currentLists[n].getElementsByTagName("li");
			for(var q=0; q<currentItems.length; q++){
				var currentLink = currentItems[q].getElementsByTagName("a")[0];
				currentLink.parentListItem = currentItems[q];
				currentLink.onmouseover = function(){
					this.parentListItem.className = "hovered";
				}
				Lib.eventCache.add(currentLink, "onmouseover", function () { this.parentListItem.className = "hovered"; }, false);	
				currentLink.onmouseout = function(){
					this.parentListItem.className = "";
				}
				Lib.eventCache.add(currentLink, "onmouseout", function () { this.parentListItem.className = ""; }, false);	
			}
		}
		
	}
}

/* <documentation about="UCBNeupro.doResizeFont" type="specific function">
	<summary>This function is executed when a visitor clicks a "resize font" hyperlink</summary>
	<namespace>UCBNeupro</namespace>
	<param type="object" descr="Hyperlink object">hyperlink</param>
</documentation> */
UCBNeupro.doResizeFont = function (hyperlink) {
	try {
		//reset active link
		for(var i=0; i<hyperlink.allResizeLinks.length; i++) {
			if(hyperlink.allResizeLinks[i].className != "close") { hyperlink.allResizeLinks[i].className = ""; }
		}
		
		UCBNeupro.setFontSize(hyperlink.parentNode.className, true);		//resize font
		hyperlink.className = "active";//set active link
		
		//UCBNeupro.hideUtility(hyperlink.textResizeBlock);				//hide utility block	
	} catch (ex){ Lib.errHandler(ex); }
}


/* <documentation about="UCBNeupro.setFontSize" type="specific function">
	<summary>This function adds a new stylesheet to the page and if removeStylesheets=true, all font-resize stylesheets are removed</summary>
	<namespace>UCBNeupro</namespace>
	<param type="string" descr="Indicates if font is smallest, small, medium, large or largest">status</param>
	<param type="bool descr="if true, all font-resize stylesheets are removed">removeStylesheets</param></strong>
</documentation> */
UCBNeupro.setFontSize = function (status, removeStylesheets) {
	try {
		if(!status || status.length==0) { status="medium"; }
		
		//remove all stylesheets for font size
		if(removeStylesheets) { 
			Lib.removeStyleSheet("smallest-size.css");
			Lib.removeStyleSheet("small-size.css");
			Lib.removeStyleSheet("medium-size.css");
			Lib.removeStyleSheet("large-size.css");
			Lib.removeStyleSheet("largest-size.css");
		}
		
		Lib.addStyleSheet("../static/css/" + status + "-size.css"); //add resize stylesheet
		
		Lib.setCookie("fontsize", status)
	} catch (ex){ Lib.errHandler(ex); }
}


/* <documentation about="UCBNeupro.addSitemapFunctionality" type="specific function">
	<summary>This function adds a folding out functionality to sitemap</summary>
	<namespace>UCBNeupro</namespace>
</documentation> */
UCBNeupro.addSitemapFunctionality = function (){
	try {
		if(Lib.getBodyId() != "sitemapPage") { return; }
		
		//private function: to show/hide sub
		var toggleSitemapSub = function (hyperlink) {
			var li = hyperlink.parentNode.parentNode;
			
			if (li.className == "active") { location.href=hyperlink.href; }
			else {   
				resetSitemapSubs();
				
				li.className = "active";
				var strong = document.createElement("strong");
				strong.innerHTML = hyperlink.innerHTML; 
				hyperlink.innerHTML = ""; 
				hyperlink.appendChild(strong);
				
				var subList = li.getElementsByTagName("ul")[0];
				var currentH2 = li.getElementsByTagName("h2")[0];
				var currentFirstLevelHeigth = currentH2.parentHeight;
				
				// check if height of chosen firstlevel-item has changed; Text could be resized so height of 1st level items has to be re-calculated;

				if(currentH2.currentHeight != currentH2.offsetHeight){
					currentFirstLevelHeigth = firstLevelHeight();
					currentH2.currentHeight = currentH2.offsetHeight;
					currentH2.parentHeight = currentFirstLevelHeigth;
				}
				
				if(currentFirstLevelHeigth < subList.offsetHeight) {
					li.parentNode.style.height = subList.offsetHeight/10 + 4 + "em";
				}
				else { li.parentNode.style.height= "auto"; }
			}					
		}
		
		//private function: to hide sub
		var resetSitemapSubs = function () {
			var activeListItems = Lib.getElementsByClassName("active", "li", ulSitemap);
			for(var i=0; i<activeListItems.length; i++) {
				activeListItems[i].className = "";
				
				var strong = activeListItems[i].getElementsByTagName("strong")[0];
				var hyperlink = strong.parentNode;
				hyperlink.innerHTML = strong.innerHTML;
			}
		}
		
		//private function: to calculate height of 1st level navigation
		var firstLevelHeight = function(){
			var ulSitemap = Lib.getElementsByClassName("sitemap", "ul")[0];
			var firstLevelItems = ulSitemap.getElementsByTagName("h2");
			var currentHeight = 0;
			for(var n=0; n<firstLevelItems.length; n++) {
				currentHeight += firstLevelItems[n].offsetHeight;
			}
			return currentHeight;
		}
		
		var ulSitemap = Lib.getElementsByClassName("sitemap", "ul")[0];
		var h2s = ulSitemap.getElementsByTagName("h2");
		var firstLevelCurrentHeight = firstLevelHeight();
		
		for(var i=0; i<h2s.length; i++) {
			var hyperlink = h2s[i].getElementsByTagName("a")[0];
			h2s[i].currentHeight = h2s[i].offsetHeight;
			h2s[i].parentHeight = firstLevelCurrentHeight;
			
			if(i==0) { toggleSitemapSub(hyperlink); }
			
			hyperlink.onclick = function () {  toggleSitemapSub(this); return false; };
			Lib.eventCache.add(hyperlink, "onclick", function () {  toggleSitemapSub(this); return false; }, false);				
		}
	} catch (ex){ Lib.errHandler(ex); }
}


/* <documentation about="Lib.addStyleSheet('../static/themes/neupro/css/js-enabled-styles.css')" type="FUNCTION CALL">
	<summary>Add javascript style sheet to hide folds outs</summary>
</documentation> */
Lib.addStyleSheet("../static/themes/neupro/css/js-enabled-styles.css");

/* <documentation about="setFontSize" type="FUNCTION CALL">
	<summary>Set font size at initailisation of page</summary>
</documentation> */
UCBNeupro.setFontSize(Lib.getCookie("fontsize"), false);

/* <documentation about="setFontSize" type="FUNCTION CALL">
	<summary>Set font size at initailisation of page</summary>
</documentation> */
UCBNeupro.setFontSize(Lib.getCookie("fontsize"), false);

/* <documentation about="UCBNeupro.init" type="FUNCTION CALL">
	<summary>Calling Lib.addEvent: Add UCBNeupro.init as eventhandler on window onload event</summary>
</documentation> */
Lib.addEvent(window, "load", UCBNeupro.init);
Lib.eventCache.add(window, "load", UCBNeupro.init, false); 	

-->


