

/* ----------- FONTSIZE ------------ */

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) {
      	a.disabled = false;
	  }
    }
  }
  //pressButton(title);
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) {
    	return a.getAttribute("title");
    }
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  } else {
  	expires = "";
  }
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

/*
// Load this in the cssmenu.js file instead
window.onload = function(e) {
 if (document.getElementById) {
    var cookie = readCookie("style");
    var title = cookie ? cookie : getPreferredStyleSheet();
    setActiveStyleSheet(title);
    }
}
*/


window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}




/*

=================================================================================================
>> EASYMENU - XHTML/CSS/DHTML Semantically correct drop down menu 
=================================================================================================
Author: 	Sam Hampton-Smith
Site: 		http://www.hampton-smith.com

Description:	This script takes a nested set of <ul>s and turns it into a fully functional
		DHTML menu. All that is required is the correct use of class names, and
		the application of some CSS. For the latest version of this script, go to
		http://www.easymenu.co.uk
		
Use:		Use of this code is free for all non-commercial applications. If you would like to 
		use the code on a commercial website, a link back to http://www.easymenu.co.uk is 
		required. You are free to make alterations to the code as required.
		

Copyright:	This script is copyright 2004-2005 hampton-smith limited. All rights reserved.


--------------------------------------------------------------------------------------------------
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
--------------------------------------------------------------------------------------------------
Credits: 	Inspiration/Code borrowed from Dave Lindquist (http://www.gazingus.org)
		Menu hide functionality was aided by some code I found on http://www.jessett.com/
		Konqueror functionality was aided by some code Scott Wehrenberg emailed over
--------------------------------------------------------------------------------------------------
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
--------------------------------------------------------------------------------------------------

==================================================================================================
>> REVISION HISTORY
==================================================================================================
Date		Version		Changes/Bug Fixes/New functionality added
--------------------------------------------------------------------------------------------------
10/01/2005	1.01		Fixed known issue where hovering over a sub-menu, then returning to 
				its parent menu not via the "starter" item on that menu, where the 
				new item moused over is a "starter" caused the two sub-menus 
				to overlay each other until a further movement of the mouse. 
				Fixed known issue where returning to parent menu via a non-"starter"
				menu item on the parent menu would not hide the child menu
08/01/2005	1.00		First full release of easymenu.
				Stylesheets now loaded in through JavaScript to improve accessibility.
01/12/2004	0.9		Base code inherited from client project
				Added suggestion from Scott Wehrenberg enabling Konqueror functionality
--------------------------------------------------------------------------------------------------



*/
	// Load up the stylesheet for the menus. This code is here rather than in the html
	// document to allow for non-javascript browsers to render a seperately styled non-
	// interactive list rather than the DHTML menu
//	document.write("<link rel='stylesheet' href='cssmenu.css' type='text/css' />");

	var currentMenu = null;
	var lastMenuStarter = null;
	var mytimer = null;
	var timerOn = false;
	var opera = window.opera ? true : false;

	if (!document.getElementById)
		document.getElementById = function() { return null; }

	function initialiseDummy(dummy, root) {
		dummy.onmouseover = function() {
			containingMenu = this.parentNode.parentNode;
			for (var x=0;x<containingMenu.childNodes.length;x++) {
				if (containingMenu.childNodes[x].nodeName.toUpperCase()=="LI") {
					if (containingMenu.childNodes[x].getElementsByTagName("ul").length>0) {
						containingMenu.childNodes[x].getElementsByTagName("UL").item(0).style.visibility = 'hidden';
					}
				}
			}
		}
		dummy.onfocus = function() {
			dummy.onmouseover();
		}
	}
	
	function initialiseMenu(menu, starter, root) {
		var leftstarter = false;
	
		if (menu == null || starter == null) return;
			currentMenu = menu;
	
		starter.onmouseover = function() {
			if (currentMenu) {
				if (this.parentNode.parentNode!=currentMenu) {
					currentMenu.style.visibility = "hidden";
					hideAllMenus(currentMenu, root);

				}
				if (this.parentNode.parentNode==root) {
					while (currentMenu.parentNode.parentNode!=root) {
						currentMenu.parentNode.parentNode.style.visibility = "hidden";
						currentMenu = currentMenu.parentNode.parentNode;
					}
				}
				currentMenu = null;
				this.showMenu();
	        	}
		}
	
		menu.onmouseover = function() {
			if (currentMenu) {
				currentMenu = null;
				this.showMenu();
	        	}
		}	
	
		starter.showMenu = function() {
			if (!opera) {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + "px";
					menu.style.top = this.offsetTop + this.offsetHeight + "px";
					if (menu.offsetWidth < this.offsetWidth) menu.style.width = this.offsetWidth;
				}
				else {
				 	menu.style.left = this.offsetLeft + this.offsetWidth + "px";
				 	menu.style.top = this.offsetTop + "px";
				}
			}
			else {
				var rootOffset = root.offsetLeft;
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft - rootOffset + "px";
					menu.style.width = this.offsetWidth;
					menu.style.top = this.offsetHeight + "px";
				}
				else {
				 	menu.style.left = this.offsetWidth - rootOffset + "px";
				 	menu.style.top = this.offsetTop + "px"; //menu.style.top - menu.style.offsetHeight + "px";
				}

			}
			menu.style.visibility = "visible";
			currentMenu = menu;
		}

		starter.onfocus	 = function() {
			starter.onmouseover();
		}
	
		menu.onfocus	 = function() {
//			currentMenu.style.visibility="hidden";
		}

		menu.showMenu = function() {
			menu.style.visibility = "visible";
			currentMenu = menu;
			stopTime();
		}

		menu.hideMenu = function()  {
			if (!timerOn) {
				mytimer = setInterval("killMenu('" + this.id + "', '" + root.id + "');", 2000);
				timerOn = true;
				for (var x=0;x<menu.childNodes.length;x++) {
					if (menu.childNodes[x].nodeName=="LI") {
						if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
							menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
							menuItem.style.visibility = "hidden";
						}
					}
				}
			}
		}

		menu.onmouseout = function(event) {
			this.hideMenu();
		}
		menu.onblur = function() {
			this.hideMenu();
		}
		starter.onmouseout = function() {
			for (var x=0;x<menu.childNodes.length;x++) {
				if (menu.childNodes[x].nodeName=="LI") {
					if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
						menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
						menuItem.style.visibility = "hidden";
					}
				}
			}
			menu.style.visibility = "hidden";
		}
}
	function killMenu(menu, root) {
		var menu = document.getElementById(menu);
		var root = document.getElementById(root);
		menu.style.visibility = "hidden";
		for (var x=0;x<menu.childNodes.length;x++) {
			if (menu.childNodes[x].nodeName=="LI") {
				if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
					menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
					menuItem.style.visibility = "hidden";
				}
			}
		}
		while (menu.parentNode.parentNode!=root) {
			menu.parentNode.parentNode.style.visibility = "hidden";
			menu = menu.parentNode.parentNode;
		}
		stopTime();
	}
	function stopTime() {
		if (mytimer) {
		 	 clearInterval(mytimer);
			 mytimer = null;
			 timerOn = false;
		}
	} 


window.onload = function() {
		var root = document.getElementById("menuList");
		var rootOffset = root.offsetLeft;
		getMenus(root, root);
/* 
----------------
Fontsize.js loader 
*/
		 if (document.getElementById) {
			var cookie = readCookie("style");
			var title = cookie ? cookie : getPreferredStyleSheet();
			setActiveStyleSheet(title);
			}

	}








function getMenus(elementItem, root) {
	var selectedItem;
	var menuStarter;
	var menuItem;
	for (var x=0;x<elementItem.childNodes.length;x++) {
		if (elementItem.childNodes[x].nodeName.toUpperCase()=="LI") {
			if (elementItem.childNodes[x].getElementsByTagName("ul").length>0) {
				menuStarter = elementItem.childNodes[x].getElementsByTagName("A").item(0);
				menuItem = elementItem.childNodes[x].getElementsByTagName("UL").item(0);
				getMenus(menuItem, root);
				initialiseMenu(menuItem, menuStarter, root);
			}
			else {
// DMK eliminate script error for IE
//				initialiseDummy(elementItem.childNodes[x].getElementsByTagName("A").item(0), root);
			}
		}
	}
}
function hideAllMenus(elementItem, root) {
	for (var x=0;x<elementItem.childNodes.length;x++) {
		if (elementItem.childNodes[x].nodeName.toUpperCase()=="LI") {
			if (elementItem.childNodes[x].getElementsByTagName("ul").length>0) {
				elementItem.childNodes[x].getElementsByTagName("UL").item(0).style.visibility = 'hidden';
				hideAllMenus(elementItem.childNodes[x].getElementsByTagName("UL").item(0), root);
			}
		}
	}
}





/*
	PureDOM explorer 3.0
	written by Christian Heilmann (http://icant.co.uk)
	Please refer to the pde homepage for updates: http://www.onlinetools.org/tools/puredom/
	Free for non-commercial use. Changes welcome, but no distribution without 
	the consent of the author.
*/
pde={
	// CSS classes
	pdeClass:'menu_colorcode',
	hideClass:'hide',
	showClass:'show',
	parentClass:'parent',
	currentClass:'current',
	iconClass:'pdeIcon',
	// images added to the parent links
	openImage:'/includes/minus.gif',
	closedImage:'/includes/plus.gif',
	openMessage:'close section',
	closedMessage:'open section',
	// boolean to make the parent link collapse the section or not 
	linkParent:false,
	init:function(){
		pde.createClone();
		if(!document.getElementById || !document.createTextNode){return;}
		var uls=document.getElementsByTagName('ul');
		for(var i=0;i<uls.length;i++){
		var inneruls,parentLI;
			if(!pde.cssjs('check',uls[i],pde.pdeClass)){continue;}
			var inneruls=uls[i].getElementsByTagName('ul');
			for(var j=0;j<inneruls.length;j++){
				parentLI=inneruls[j].parentNode;
				if(parentLI.getElementsByTagName('strong')[0]){
					pde.cssjs('add',parentLI,pde.currentClass);
					continue;
				}
				pde.cssjs('add',parentLI,pde.parentClass);
				parentLI.insertBefore(pde.clone.cloneNode(true),parentLI.firstChild);
				pde.cssjs('add',inneruls[j],pde.hideClass);
				pde.addEvent(parentLI.getElementsByTagName('a')[0],'click',pde.showhide,false);
				parentLI.getElementsByTagName('a')[0].onclick=function(){return false;} // Safari hack
				if(pde.linkParent){
					pde.addEvent(parentLI.getElementsByTagName('a')[1],'click',pde.showhide,false);
					parentLI.getElementsByTagName('a')[1].onclick=function(){return false;} // Safari hack
				}
			}
		}
	},
	showhide:function(e){
		var image,message;
		var elm=pde.getTarget(e);
		var ul=elm.parentNode.getElementsByTagName('ul')[0];
		var img=elm.parentNode.getElementsByTagName('img')[0];
		if(pde.cssjs('check',ul,pde.hideClass)){
			message=pde.openMessage;
			image=pde.openImage;
			pde.cssjs('remove',elm.parentNode.getElementsByTagName('ul')[0],pde.hideClass);
			pde.cssjs('add',elm.parentNode.getElementsByTagName('ul')[0],pde.showClass);
		} else {
			message=pde.closedMessage;
			image=pde.closedImage;
			pde.cssjs('remove',elm.parentNode.getElementsByTagName('ul')[0],pde.showClass);
			pde.cssjs('add',elm.parentNode.getElementsByTagName('ul')[0],pde.hideClass);
		}
		img.setAttribute('src',image);
		img.setAttribute('alt',message);
		img.setAttribute('title',message);
		pde.cancelClick(e);
	},
	createClone:function(){
		pde.clone=document.createElement('a');
		pde.clone.setAttribute('href','#');
		pde.clone.appendChild(document.createElement('img'));
		pde.clone.getElementsByTagName('img')[0].src=pde.closedImage;
		pde.clone.getElementsByTagName('img')[0].alt=pde.closedMessage;
		pde.clone.getElementsByTagName('img')[0].title=pde.closedMessage;
	},
/* helper methods */
	getTarget:function(e){
		var target = window.event ? window.event.srcElement : e ? e.target : null;
		if (!target){return false;}
		if (target.nodeName.toLowerCase() != 'a'){target = target.parentNode;}
		return target;
	},
	cancelClick:function(e){
		if (window.event){
			window.event.cancelBubble = true;
			window.event.returnValue = false;
			return;
		}
		if (e){
			e.stopPropagation();
			e.preventDefault();
		}
	},
	addEvent: function(elm, evType, fn, useCapture){
		if (elm.addEventListener) 
		{
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}
	},
	cssjs:function(a,o,c1,c2){
		switch (a){
			case 'swap':
				o.className=!pde.cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			break;
			case 'add':
				if(!pde.cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
			case 'remove':
				var rep=o.className.match(' '+c1)?' '+c1:c1;
				o.className=o.className.replace(rep,'');
			break;
			case 'check':
				return new RegExp("(^|\s)" + c1 + "(\s|$)").test(o.className)
			break;
		}
	}
}
 pde.addEvent(window, 'load', pde.init, false);



