/* 
JavaScript dropdown menu system 
developed by and copyright George Rose 2004
modifications by Peter Brooks FHOL 2005
This copy is licensed to FamilyHistoryOnline
*/

var txtSecureServer = "https://www.familyhistoryonline.net"		// Address of secure server
var txtServer = "http://www.familyhistoryonline.net"			// Address of Standard server
// STYLE OPTIONS
var lPos = "40px"               			// distance of first menu item from left of page
var lPos2 = "10px"              			// distance of menu bar from left of page
var tPos = "87px"      					// menu distance from top of page
var hPos = "15px"               			// height of menu
var hPos2 = "4px"               			// height of band under menu was
var wPos = "90px"       					// width of a menu item
var spacing = "10px"            			// spacing between menu items
var wPos2 = "690px"             			// width of menu container
var menuBG = "#fff"             			// menu background colour
var menuBG2 = "#fff"            			// menu background colour of each top level item (provides contrast)
var menuBGimg = ""              			// menu background image (over-rides colour)
var filter = "alpha(opacity=100); -moz-opacity:1;" // filter for sub-menus
var txtColorTop = "#000"       			// menu text color
var txtColorSub = "#000"       			// sub-menu text colour
var txtColorSub2 = "#216fdc"    			// sub-menu highlight text colour
var txtPadding = "10px"         			// padding on left of menu text
var txtPadding2 = "2px"         			// padding on left of submenu text
var txtPaddingLeft = "5px"      			// padding on left of menu text
var txtPaddingRight = "5px"     			// padding on right of menu text
var bg = "#fff"                 			// background of sub-menu items
var bgChange =  "#eee"          			// highlight background of sub-menu items
var border = "2px #000000 solid" 			// border of menu
var borderStyle = "none solid solid solid" // border layout of main menu items
var borderSub = "2px #000000 solid" 		// border of sub-menu
var deviderSub = "1px #000000 solid" 		// devier of each sub-menu
var font = "arial, helvetica, sans-serif;" 	// font style
var fontS = "13px"              			// font size
var fontW = "600"               			// font weight
var showArrow = false 	        			// true to show the dropdown arrow, false to not show it
var menuAlign = "right"         			// right, center or left to align menu items
// var subAlign = "right"          			// right, center or left to align sub menu items
var neaten = true					// true prevents rightmost submenu spillover 
var fixedwidth = true					// true uses wPos as width

// psuedo multi-dimensional array
function submenu(menu, title, href, javascript, picture, align) {
	this.menu = menu
	this.title = title
	this.href = href
	this.javascript = javascript
	this.picture = picture
	this.align = align
}

// TOP LEVEL LINKS
menus = Array()

menus[0] = new submenu(0, "Help", "", "", "", "center")
menus[1] = new submenu(0, "Databases", "", "", "", "center")
menus[2] = new submenu(0, "News", "", "", "", "center")
menus[3] = new submenu(0, "About us", "", "", "", "center")


submenus = Array()
// SUBMENU LINKS

submenus[0] = new submenu(0, "Frequently asked questions (FAQs)", txtServer + "/general/fmpfaq.shtml", "", "", "left")
submenus[1] = new submenu(0, "Contact Us", txtServer + "/email/contactus.html", "", "", "left")


submenus[2] = new submenu(1, "Databases", txtServer + "/database/index.shtml", "", "", "left")
submenus[3] = new submenu(1, "Formats", txtServer + "/database/formats.shtml", "", "", "left")

submenus[4] = new submenu(2, "Latest news", txtServer + "/general/motd.shtml", "", "", "left")
submenus[5] = new submenu(2, "News archive", txtServer + "/general/archive_news.shtml", "", "", "left")


submenus[6] = new submenu(3, "Who we are", txtServer + "/general/aboutus.shtml", "", "", "right")
submenus[7] = new submenu(3, "Privacy", txtServer + "/general/privacy.shtml", "", "", "right")
submenus[8] = new submenu(3, "Copyright", txtServer + "/general/copyright.shtml", "", "", "right")
submenus[9] = new submenu(3, "Terms and Conditions", txtServer + "/general/terms.shtml", "", "", "right")
submenus[10] = new submenu(3, "Contact us", txtServer + "/email/contactus.html", "", "", "right")

subsubmenus = Array()
// SUB-SUBMENU LINKS
//subsubmenus[0] = new submenu(4, "Example sub sub meu", "sublink_1.php")


/* *** EVERYTHING BELOW HERE CAN BE IGNORED *** */

var tPos2 = (parseInt(tPos) + parseInt(hPos) + parseInt(hPos2) + parseInt(border) + parseInt(borderSub) + 2) + "px" 
var page = ""
var longests = Array()
isOver = false
mt = null
curr_show = null

function replaceSpace(value) {
	while (value.indexOf(" ") != -1) {
		value = value.replace(" ","&nbsp;")
	}
	return value
}

function rollMe(value) {
	if (unrollMe()) {
		if (document.getElementById("submenu" + value)) {
			document.getElementById("submenu" + value).style.display = 'block'
		}
		for (x = 0; x < menus.length; x++) {
			if (document.getElementById("submenu" + x) && x != value) {
				document.getElementById("submenu" + x).style.display = 'none'
			}
		}
		curr_show = value
	}
}
function unrollMe() {
	for (x = 0; x < menus.length; x++) {
		if (document.getElementById("submenu" + x)) {
			document.getElementById("submenu" + x).style.display = 'none'
		}
	}
	for (x = 0; x < submenus.length; x++) {
		if (document.getElementById("subsubmenu" + x)) {
			document.getElementById("subsubmenu" + x).style.visibility = 'hidden'
		}
	}
	return true
}
function rollMeSub(value) {
	if (document.getElementById("subsubmenu" + value)) {
		document.getElementById("subsubmenu" + value).style.visibility = 'visible'
	}
}
function unrollMeSub() {
	for (x = 0; x < submenus.length; x++) {
		if (document.getElementById("subsubmenu" + x)) {
			document.getElementById("subsubmenu" + x).style.visibility = 'hidden'
		}
	}
}

function doSubSub(y) {
	thisPage = ""
	thistPos = parseInt(tPos2) + (parseInt(fontS) * (y+2)) + "px"
	thisCount = 0
	thisLongest = 0
	
	for (z = 0; z < subsubmenus.length; z++) {
		if (subsubmenus[z].menu == y) {
			style = (thisCount != 0) ? " border-top:" + borderSub + ";" : "" ;
			thisTitle = replaceSpace(subsubmenus[z].title)
			onClickEvent = (subsubmenus[z].javascript) ? subsubmenus[z].javascript : "location.href='" + subsubmenus[z].href + "'" ;
			thisPage += "<tr><td style='" + style + " text-align:" + subAlign + "; cursor:pointer; font-family:" + font + "; font-size:" + fontS + "; font-weight:" + fontW + "; color:" + txtColorSub + "; padding-right:" + txtPaddingRight + ";' onMouseOver='this.style.backgroundColor=\"" + bgChange + "\";this.style.color=\"" + txtColorSub2 + "\"' onMouseOut='this.style.backgroundColor=\"" + bg + "\";this.style.color=\"" + txtColorSub + "\"' onClick=\"" + onClickEvent + "\" title='" + subsubmenus[z].title + "'>"	
			if (subsubmenus[z].picture && subAlign == "right")	{
				thisPage += thisTitle + "&nbsp;&nbsp;<img border='0' src='" + subsubmenus[z].picture + "'>"
			} else if (subsubmenus[z].picture) {
				thisPage += "<img border='0' src='" + subsubmenus[z].picture + "'>&nbsp;&nbsp;" + thisTitle
			} else {
				thisPage += thisTitle
			}
			thisPage += "</td></tr>"
			thisCount++
			if (subsubmenus[z].title.length > thisLongest) {
				thisLongest = subsubmenus[z].title.length
			}
		}
	}
	thisOffset = 5
	thiswPos2 = (parseInt(fontS) - Math.round(thisLongest/thisOffset)) * thisLongest
	page += "<div id='subsubmenu" + y + "' style='position:absolute; visibility:hidden; background-color:" + bg + "; border:" + borderSub + "; top:" + thistPos + "; left:" + lPos + "; width:" + thiswPos2 + "px; z-index:20; filter:" + filter + "; cursor:pointer;' onMouseOver='clearTimeout(mt)' onMouseOut='mt = setTimeout(\"unrollMe()\",1000)'><table width='100%' cellspacing='0'>" + thisPage + "</table></div>\n\n";
}

document.write("<div style='position:absolute; top:" + tPos + "; width:" + wPos2 + "; left:" + lPos2 + "; height:" + (parseInt(hPos) + parseInt(hPos2)) + "px; background-color:" + menuBG + "; background-image:url(" + menuBGimg + ");'>&nbsp;</div>")

if (parseInt(hPos2) > 0) {
	document.write("<div style='position:absolute; top:" + tPos + "; width:" + wPos2 + "; left:" + lPos2 + "; height:" + hPos2 + "; background-color:" + menuBG + "; background-image:url(" + menuBGimg + ");'><img src='/static/bullet12.gif' border='0' style='height:1px;'></div>")
}

/* BEGIN MENU SECTION */

for (x = 0; x < menus.length; x++) {
	hasSub = false
	for (y = 0; y < submenus.length; y++) {
		if (submenus[y].menu == x) {
			hasSub = true
			break
		}
	}

	if (fixedwidth) {
		thiswPos=wPos;
	} else {
		thisOffset = (menus[x].title.length > 11) ? 3.8 : 4 ;
		thiswPos = (parseInt(fontS) - Math.round(menus[x].title.length/thisOffset)) * menus[x].title.length + "px";
	}
	thisTitle = replaceSpace(menus[x].title)

	thisBorder = borderStyle
	document.write("<div style='position:absolute; top:" + tPos + "; width:" + thiswPos + "; left:" + lPos + "; background-color:" + menuBG2 + "; border:" + border + "; border-style:" + thisBorder + ";' title='" + menus[x].title + "' onMouseOver='clearTimeout(mt); if (unrollMe()) { rollMe(" + x + ") }' onMouseOut='mt = setTimeout(\"unrollMe()\",250)'>")

	// to fixIE5 - but we don't need top level links for this version
	// onClickEvent = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) < 6) ? "location.href='" + menus[x].href + "'": "#" ;

	cursorType = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) < 6) ? "cursor:hand;" : "cursor:pointer;" ;

	document.write("<table border='0' style='" + cursorType + " background-color:" + menuBG2 + "; background-image:url(" + menuBGimg + ");' cellspacing='0' cellpadding='0' width='100%'><tr><td valign='bottom' style='text-align:" + menus[x].align + "; padding-left:" + txtPaddingLeft + "; padding-right:" + txtPaddingRight + "; font-family:" + font + "; font-size:" + fontS + "; font-weight:" + fontW + "; height:" + hPos + "; color:" + txtColorTop + ";'>")
	if (menus[x].picture)	{
		document.write("<img border='0' src='" + menus[x].picture + "'>&nbsp;&nbsp;")
	}
	document.write(thisTitle)
	if (hasSub && showArrow)	{
		document.write("&nbsp;&nbsp;<img border='0' src='arrow.gif'>")
	}
	document.write("</td></tr>")

	document.write("</table></div>")


/* BEGIN SUBMENU SECTION */

	if (hasSub) {

		document.write("<div id='submenu" + x + "' style='position:absolute;" + cursorType + " background-color:" + bg + "; padding-left:" + txtPadding2 + "; border:" + borderSub + "; top:" + tPos2 + "; left:" + parseInt(lPos) + "px; z-index:20; display:none; filter:" + filter + ";' onMouseOver='clearTimeout(mt)' onMouseOut='mt = setTimeout(\"unrollMe()\",1000)'><table width='100%' cellspacing='0'>")
		count = 0
		longest = 0
		for (y = 0; y < submenus.length; y++) {
			hasSub2 = false
			for (z = 0; z < subsubmenus.length; z++) {
				if (subsubmenus[z].menu == y) {
					hasSub2 = true
					break
				}
			}
			if (submenus[y].menu == x) {
				style = (count != 0) ? " border-top:" + deviderSub + ";" : "" ;
				thisTitle = replaceSpace(submenus[y].title)
				onClickEvent = (submenus[y].javascript) ? submenus[y].javascript : "location.href='" + submenus[y].href + "'" ;
				onMouseOverEvent = (hasSub2) ? "; rollMeSub(\"" + y + "\")" : "; unrollMeSub()" ;

				document.write("<tr onMouseOver='this.style.backgroundColor=\"" + bgChange + "\";this.style.color=\"" + txtColorSub2 + "\"" + onMouseOverEvent + "' onMouseOut='this.style.backgroundColor=\"" + bg + "\";this.style.color=\"" + txtColorSub + "\"' onClick=\"" + onClickEvent + "\" title='" + submenus[y].title + "'><td style='" + style + " text-align:" + submenus[y].align + "; cursor:pointer; font-family:" + font + "; font-size:" + fontS + "; font-weight:" + fontW + "; color:" + txtColorSub + "; margin-right:" + txtPaddingRight + ";'>")
				if (submenus[y].picture && submenus[y].align == "right")	{
					document.write(thisTitle + "&nbsp;&nbsp;<img border='0' src='" + submenus[y].picture + "'>")
				} else if (submenus[y].picture) {
					document.write("<img border='0' src='" + submenus[y].picture + "'>&nbsp;&nbsp;" + thisTitle)
				} else {
					document.write(thisTitle)
				}
					
				document.write("</td><td style='width:5px;'>&nbsp;</td></tr>")
				count++
				if (submenus[y].title.length > longest) {
					longest = submenus[y].title.length
				}
			
				if (hasSub2) {
					doSubSub(y)
				}
			}	
		}
		document.write("</table></div>\n\n")
		document.getElementById('submenu' + x).style.width = (longest * parseInt(9)) + "px"
		
		// prevent rightmost submenu spillover 
		if (x==menus.length-1) {
		    if (neaten) {
				document.getElementById('submenu' + x).style.left = ((parseInt(lPos) + parseInt(wPos)) - (longest * parseInt(9))) + "px"
			}
		}
		
		longests[x] = longest
	}
	lPos = parseInt(thiswPos) + parseInt(lPos) + parseInt(spacing) + "px"
}


document.write(page)
for (x = 0; x < subsubmenus.length; x++) {
	thisMenu = subsubmenus[x].menu 
	thisWidth = longests[submenus[subsubmenus[x].menu].menu]
	document.getElementById("subsubmenu" + thisMenu).style.left = parseInt(document.getElementById("submenu" + submenus[subsubmenus[x].menu].menu).style.left) + parseInt(document.getElementById("submenu" + submenus[subsubmenus[x].menu].menu).style.width) + parseInt(spacing) + "px"

}
