var theImgName;
var theImgURL;

var currentParent;
var currentMenu;
var menuToHide;
var fadestep;
var cleared = true;
var browserdetect;
var detect = navigator.userAgent.toLowerCase();
var thestring;
var numPages = 5 // TOTAL NUMBER OF PAGES

function getUserAgent() {
	return navigator.appMinorVersion.toLowerCase();
}

function Pos(thisitem)
{
	if(typeof(thisitem) != 'object') {thisitem = document.getElementById(thisitem);}
	var ww = thisitem.offsetWidth, hh = thisitem.offsetHeight;
	for (var xx = 4,yy = 0; thisitem != null; xx += thisitem.offsetLeft,yy += thisitem.offsetTop,thisitem = thisitem.offsetParent);
	return {Left:xx, Top:yy, Right:xx + ww, Bottom:yy + hh}
}

function ShowMenu(thisitem, menu)
{
	cleared = false
	currentParent = thisitem;
	currentParent.className=currentParent.className=='nav1'?'nav1hi':'nav2hi';
	if(typeof(menu) != 'object')
		{menu = document.getElementById(menu);}
	if(currentMenu == menu)
		{
			if (!cleared) clearInterval(fadestep);
			currentMenu = null;
		}
	else if(currentMenu != null)
		{
			InstantHide(currentMenu);
			if (!cleared) clearInterval(fadestep);
			currentMenu = null;
		}
	currentMenu = menu;
	//browserdetect=menu.filters? "ie" : typeof(menu.style.MozOpacity) == "string" ? "mz" : ""
	//if (browserdetect == "ie"){try{menu.filters.alpha.opacity;}catch(e){browserdetect="";}}
	
	
	if (checkMyBrowser() == "Internet Explorer"){
 		if ((getUserAgent() == 0 || getUserAgent() == null) && checkMyBrowserVer() != "7.0") {
		currentMenu.style.top = (Pos(currentParent).Bottom-74) + 'px';
		} else {
			currentMenu.style.top = Pos(currentParent).Bottom + 'px';
		}
	} else if (checkMyBrowser() == "Firefox"){
		currentMenu.style.MozOpacity = 1;
	} else if( checkMyBrowser() == "Safari") {
		currentMenu.style.top = (Pos(currentParent).Bottom-15) + 'px';
	} else {
		currentMenu.style.top = Pos(currentParent).Bottom + 'px';
	}

	currentMenu.style.display = 'block';
}

function HoldMenu(){
	ShowMenu(currentParent, currentMenu);
	MM_swapImage(this.theImgName,'',this.theImgURL,1);
}

function HideMenu(hideMenu)
{
	MM_swapImgRestore();
	if(typeof(hideMenu) != 'object')
		{hideMenu = document.getElementById(hideMenu);}
	if(this.menuToHide != hideMenu && this.menuToHide != null)
		{InstantHide(this.menuToHide);}
	this.menuToHide = hideMenu;
	FadeMenu();
	currentParent.className=currentParent.className=='nav1hi'?'nav1':'nav2';
}

function FadeMenu()
{
	fadestep=setInterval("FadeLevel()",25)
}

function FadeLevel()
{
	if (browserdetect == "ie"){
		this.menuToHide.filters.alpha.opacity-=2;
		if (this.menuToHide.filters.alpha.opacity == 0){
			InstantHide(this.menuToHide);this.menuToHide = null;
		}
		}
	else if (browserdetect == "mz"){
		this.menuToHide.style.MozOpacity-=.1;
		if (this.menuToHide.style.MozOpacity == 0.0){
			InstantHide(this.menuToHide);this.menuToHide = null;
		}
		}
	else
		{this.menuToHide.style.display = 'none';}
}

function InstantHide(iHideMenu) {
	clearInterval(fadestep);
	cleared=true
	iHideMenu.style.display = 'none';
}

function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() {
  MM_swapImgRestore();
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function rollButton (imgName,imgURL,myMenu,myParent) {
	this.theImgName = imgName;
	this.theImgURL = imgURL;
	MM_swapImage(imgName,'',imgURL,1);
	if (myMenu) {
		//document.getElementById(myMenu).style.display = "block";
		ShowMenu(myParent, myMenu);
	}
}

function menuCheck (menuID) {
	if (checkMyBrowser()=="Internet Explorer") {
		document.getElementById("dropMenu"+menuID).className = "menuDrop"+menuID+"IE";
	} else {
		document.getElementById("dropMenu"+menuID).className = "menuDrop"+menuID+"MZ";
	}
}

function setMenuOnMouseOver (menuID) {
	document.getElementById("dropMenu"+menuID).onmouseover = function () { 
	HoldMenu(); 
	}
}

function setMenuOnMouseOut (menuID) {
	document.getElementById("dropMenu"+menuID).onmouseout = function () { 
	HideMenu('dropMenu'+menuID);
	}
}

function setTopMenuOnMouseOut (menuID) {
	document.getElementById("topMenu"+menuID).onmouseout = function () { 
	HideMenu('dropMenu'+menuID);
	}
}


function replaceImage(imgNr) {
	var myImageURL = "menu_images/ncnb_menu3_0"+(imgNr+3)+".gif";
	if (document.images[ 'menu'+imgNr ]) {
	document.images[ 'menu'+imgNr ].src  = myImageURL;
	//document.getElementById("menu"+imgNr).src = myImageURL;
	}
}

function checkOS() {
  if(navigator.userAgent.indexOf('IRIX') != -1)
    { var OpSys = "Irix"; }
  else if((navigator.userAgent.indexOf('Win') != -1) &&
  (navigator.userAgent.indexOf('95') != -1))
    { var OpSys = "Windows95"; }
  else if(navigator.userAgent.indexOf('Win') != -1)
    { var OpSys = "Windows3.1 or NT"; }
  else if(navigator.userAgent.indexOf('Mac') != -1)
    { var OpSys = "Macintosh"; }
  else { var OpSys = "other"; }
  return OpSys;
}


function checkMyBrowser() {
	var OS,browser,version,total,thestring;
	
	if (checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser = "Safari"
	else if (checkIt('omniweb')) browser = "OmniWeb"
	else if (checkIt('opera')) browser = "Opera"
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab"
        else if (checkIt('msie')) browser = "Internet Explorer"
        else if (checkIt('firefox')) browser = "Firefox"
	else if (!checkIt('compatible'))
	{
		browser = "Netscape Navigator"
		version = this.detect.charAt(8);
	}
	else browser = "An unknown browser";
		
	if (!version) version = this.detect.charAt(place + this.thestring.length);
	
	if (!OS)
	{
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = "an unknown operating system";
	}
	return browser;
}

function checkMyBrowserVer() {
        var OS,browser,version,total,thestring;

        if (checkIt('konqueror'))
        {
                browser = "Konqueror";
                OS = "Linux";
        }
        else if (checkIt('safari')) browser = "Safari"
        else if (checkIt('omniweb')) browser = "OmniWeb"
        else if (checkIt('opera')) browser = "Opera"
        else if (checkIt('webtv')) browser = "WebTV";
        else if (checkIt('icab')) browser = "iCab"
        else if (checkIt('msie')) {
                browser = "Internet Explorer";
                version = this.detect.substring(place + this.thestring.length,
                                                this.detect.indexOf(';', place))
;
        }
        else if (checkIt('firefox')) {
                browser = "Firefox";
                version = this.detect.substring(place + this.thestring.length,
                                                this.detect.length);

        }
        else if (!checkIt('compatible'))
        {
                browser = "Netscape Navigator"
                version = this.detect.charAt(8);
        }
        else browser = "An unknown browser";

        if (!version) version = this.detect.charAt(place + this.thestring.length
);

        if (!OS)
        {
                if (checkIt('linux')) OS = "Linux";
                else if (checkIt('x11')) OS = "Unix";
                else if (checkIt('mac')) OS = "Mac"
                else if (checkIt('win')) OS = "Windows"
                else OS = "an unknown operating system";
        }
        return version;
}

function checkIt(string)
{
	place = this.detect.indexOf(string) + 1;
	this.thestring = string;
	return place;
}

// Expand Collapse block function
// Source:
// http://support.internetconnection.net/CODE_LIBRARY/Javascript_Collapse_Expand.shtml

//this switches expand collapse icons
function filter(imagename,objectsrc){
	if (document.images){
		document.images[imagename].src=objectsrc;
	}
}

//show OR hide funtion depends on if element is shown or hidden
function shoh(id) { 

	if (!document.imgout) {
		document.imgout = new Image;
		document.imgout.src = "/images/blockexpand.gif";
	}
	if (!document.imgin) {
		document.imgin = new Image;
		document.imgin.src = "/images/blockcollapse.gif";
	}

	
	if (document.getElementById) { // DOM3 = IE5, NS6
		if (document.getElementById(id).style.display == "none"){
			document.getElementById(id).style.display = 'block';
			filter(("img"+id),document.imgin.src);			
		} else {
			filter(("img"+id),document.imgout.src);
			document.getElementById(id).style.display = 'none';			
		}	
	} else { 
		if (document.layers) {	
			if (document.id.display == "none"){
				document.id.display = 'block';
				filter(("img"+id),document.imgin.src);		
			} else {
				filter(("img"+id),document.imgout.src);
				document.id.display = 'none';
			}
		} else {
			if (document.all.id.style.visibility == "none"){
				document.all.id.style.display = 'block';
			} else {
				filter(("img"+id),document.imgout.src);
				document.all.id.style.display = 'none';
			}
		}
	}
}


