// JavaScript Document

//UTILITY FUNCTIONS
function getStyle(el,styleProp)
//gets specified style property for an elem
{
	var x = document.getElementById(el);
	if (x.currentStyle)  {
		var y = x.currentStyle[styleProp];}
	else if (window.getComputedStyle)  {
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp); }
	return y;
}

function browserWidthHeight(type) {
//returns width or height of browser window
		d=document;xMax=0;yMax=0;
		if(d.getElementById){
	 if(d.documentElement&&d.documentElement.clientHeight){
	  xMax=d.documentElement.clientWidth;
	  yMax=d.documentElement.clientHeight;
	 }else{
	  xMax=(d.all)?d.body.clientWidth:window.innerWidth;
	  yMax=(d.all)?d.body.clientHeight:window.innerHeight;
	 }
	}else if(d.layers){
	 xMax=window.innerWidth;
	 yMax=window.innerHeight;
	}
	
	if(type=='width') {return xMax;}
	else if (type=='height') {return yMax;}
}


//USED FOR MENU ROLLOVERS IN TOP MENU
var selTopMenu;  //indicates number of selected top menu item

function getBackgroundPos(el)  {
//workaround with bug in getting background position in IE
var browserName=navigator.appName; 
	if (browserName=="Microsoft Internet Explorer")
		{var y = getStyle(el,'backgroundPositionX') + ' ' + getStyle(el,'backgroundPositionY');}
	else
		{var y = getStyle(el,'background-position');}
	return y;
}

function topmenu_mouseover(menuname)  {
//mouseover for top menu
	var bckgpos = getBackgroundPos(menuname);
	if (bckgpos == '0px 12px') {selTopMenu=menuname;} //selected menu element so no rollover needed
	else {document.getElementById(menuname).style.backgroundPosition='0px 12px';}  //moves underline to where it's visible
}

function topmenu_mouseout(menuname){
//mouseout for top menu
	if (menuname!=selTopMenu) {
		document.getElementById(menuname).style.backgroundPosition='0px 31px'; //moves underline to where it's hidden
	}		
}


//USED FOR BLOCK ROLLOVERS FOR THREE BLOCKS ON HOME PAGE
function home_mouseover(img) {
	//mouseover for blocks
	var imgid = document.getElementById(img);
	var imgrollover = '../assets/home_'+img+'_rollover.jpg';
	imgid.src = imgrollover;
}
function home_mouseout(img) {
//mouseout for blocks 
	var imgid = document.getElementById(img);
	var imgrollover = '../assets/home_'+img+'.png';
	imgid.src = imgrollover;
}


//USED FOR SUBMENUS ON FOUNDATION.AS AND FUNDING
var selSubMenu; //indicates number of selected sub menu item

function mouseoversubmenu(menutype,menuno) {
//mouseover for submenu
	var menuelement = document.getElementById(menutype+menuno);
	var imgrollover = '../assets/' + menutype +menuno + '_rollover.jpg';
	menuelement.src = imgrollover;
}
function mouseoutsubmenu(menutype,menuno) {
//mouseout for submenu (not doesn't mouseout if menu item a 'selected' one
	if (menuno!=selSubMenu) {
		var menuelement = document.getElementById(menutype+menuno);
		var imgnormal = '../assets/' + menutype +menuno + '.png';
		menuelement.src = imgnormal;
	}
}

function selectSubMenu(menutype,menuno) {
//user clicks on a submenu item
	selectMenuElement(menutype,menuno); 
	selectMenuContent(menutype,menuno);
	setFooterTop('block1');
}

function selectMenuElement(menutype,menuno) {
//select the menu item by mouseovering it and mouseouting all other elements
	selSubMenu = menuno;
	var noMenuItems = eval('arr' + menutype + 'Content.length');
	for (var i = 1; i <(noMenuItems + 1); i++ ) {
		if (i==menuno) {mouseoversubmenu(menutype,menuno)}
		else {mouseoutsubmenu(menutype,i);}		
	}
	selSubMenu = menuno; //reset menu selection
}

function selectMenuContent(menutype,menuno) {
//fill container with content for selected sub menu item
	var container = document.getElementById('submenucontent');
	var content = eval('arr' + menutype + 'Content['+(menuno -1)+']');
	container.innerHTML = content;
}

//USED TO MOVE FOOTER TO BOTTOM OF BROWSER PAGE WHILE NOT OBSTRUCTING PAGE CONTENT
function setFooterTop(el) {
//move footer to bottom of page but make sure it clears next lowest page element
	var minTop = getBottomElement(el) + 20 //make sure footer clears the previous element by 20 pixels
	var browserHeight = browserWidthHeight('height');
	var footerTop = (browserHeight -35);
	if (footerTop<minTop) {footerTop=minTop;}
	var footer = document.getElementById('t_footer');
	footer.style.visibility='hidden';
	footer.style.top = footerTop +'px';
	footer.style.visibility='visible';
}

function getBottomElement(el) {
//get bottom of specified element in pixels
	var elmt = document.getElementById(el);
	var elmtTop = getStyle(el,'top');
	var elmtHeight = elmt.offsetHeight;
	var elmtBottom = parseInt(elmtTop) + parseInt(elmtHeight);
	return elmtBottom;
}




