

function TSDynamicMenu(iname) {
	this.bgcolor = "004000";
	this.fgcolor = "FFFF00";
	this.lnkcolor = "FFFF00";
	this.lnkdeco = "none";
	this.hovcolor = "FFFF00";
	this.hovbkg = "004000";
	this.fontSize = ["9pt", "8pt"];
	this.fontFamily = "Verdana, sans-serif";
	this.orientation = "horizontal";
	this.name = (iname) ? iname : "tsdynnav";   // make sure it is unique??

	this.items = [];                						// array of TSDynamicMenuItem
	
	var uagent = navigator.userAgent;
	var ihw = (uagent.toLowerCase().indexOf('iphone')> -1) ? true : false;
	ihw = (uagent.toLowerCase().indexOf('ipod')> -1) ? true : ihw;
	ihw = (uagent.toLowerCase().indexOf('ipad')> -1) ? true : ihw;
	ihw = (uagent.toLowerCase().indexOf('blackberry')> -1) ? true : ihw;
	ihw = (uagent.toLowerCase().indexOf('android')> -1) ? true : ihw;
	ihw = (uagent.toLowerCase().indexOf('palm')> -1) ? true : ihw;
	//ihw = (uagent.toLowerCase().indexOf('xxx')> -1) ? true : ihw;
	
	this.isHandheld = ihw;
	if (ihw) {
		this.lnkdeco = "underline";
		this.hovcolor = "00FFFF";
	}
	
	this.build = function () {
		if (this.orientation == "horizontal") {
			var outHTML = (this.isHandheld) ? this.putHHStyle() : this.putStyle();
			outHTML += '<center><table id="' + this.name + '" border="0" cellpadding="0" cellspacing="0"><tr>'

			for (var idx=0; idx<this.items.length; idx++) {
				outHTML += '<td align="center">';
				outHTML += (this.isHandheld) ? '' : '<ul>';
				outHTML += this.items[idx].build();
				outHTML += (this.isHandheld) ? '' : '</ul>';
				outHTML += '</td>';
			}
			outHTML += '</tr>        </table></center>';
		} else {
			// vertical logic
			outhtml = "NOT YET DEFINED";
		}
		return outHTML;
	}

	this.putStyle = function() {
		var outHTML = "<style>"

		outHTML += '#' + this.name + ' a {        text-decoration: ' + this.lnkdeco + '; color: ' + this.lnkcolor + '; }';

		outHTML += '#' + this.name + ', #' + this.name + ' ul {font-size: ' + this.fontSize[0] + '; font-family: ' + this.fontFamily + ';' +
		' list-style: none; margin-left: 1em; width: 15em; padding: 0;}';

		outHTML += '#' + this.name + ' li {width: 15em; padding: 2px; margin-bottom: 11px; line-height: 1.5em; position: relative; ' +
		'background: #' + this.bgcolor + '; color: #' + this.fgcolor + ';}';

		outHTML += '#' + this.name + ' li li {font-size: ' + this.fontSize[1] + '; width: 11.3em; margin: 0;         padding: 4px; line-height: 1.2;' +
		' border-bottom: 1pt silver solid; }';

		outHTML += '#' + this.name + ', #' + this.name + '  ul { }';

		outHTML += '#' + this.name + ' li:hover, #' + this.name + ' li.ieHover {cursor: pointer; color: #' + this.hovcolor + ';' +
		' background: #' + this.hovbkg + '; }';

		outHTML += '#' + this.name + ' li ul, #' + this.name + ' li:hover ul ul, #' + this.name + ' li:hover ul ul ul, ' +
		'#' + this.name + ' li:hover ul ul ul ul, #' + this.name + ' li.ieHover ul ul, #' + this.name + ' li.ieHover ul ul ul, ' +
		'#' + this.name + ' li.ieHover ul ul ul ul {position: absolute; left: -999em; top: 0px; }';

		outHTML += '#' + this.name + ' #' + this.name + ' li:hover ul, #' + this.name + ' ul li:hover ul, #' + this.name + ' ul ul li:hover ul, ' +
		'#' + this.name + ' ul ul ul li:hover ul, #' + this.name + ' li.ieHover ul, #' + this.name + ' ul li.ieHover ul, ' +
		'#' + this.name + ' ul ul li.ieHover ul, #' + this.name + ' ul ul ul li.ieHover ul ' +
		'{ left: 0.5em; top: 1.8em; }';

		/*                outHTML += '#' + this.name + ' '
		****/
		outHTML += "</style>";
		return outHTML;
	}
	
	this.putHHStyle = function() {
		var outHTML = "<style>"

		outHTML += '#' + this.name + ' a { text-decoration: ' + this.lnkdeco + '; color: ' + this.lnkcolor + '; }';

		outHTML += '#' + this.name + ' a:hover { cursor: pointer; color: #' + this.hovcolor + ';}';

		outHTML += '#' + this.name + ' td { width:180px; vertical-align:top; background: #' + this.bgcolor + '; color: #' + this.fgcolor + ';' +
		' font-size: ' + this.fontSize[0] + '; font-family: ' + this.fontFamily + '; line-height: 160%;}';

		outHTML += "</style>";
		return outHTML;
	}
};

function TSDynamicMenuItem(iparent, iurl, ilabel, inewwin) {
	this.parent = iparent;
	this.url = iurl;
	this.label = ilabel
	this.newwin = (inewwin) ? inewwin : false;

	this.subitems = new Array();                // Array of TSDynamicMenuItem;

	this.build = function() {
		if (this.parent.orientation == "horizontal") {
			var outHTML = "";
			if (document.all) {
				outHTML += (this.parent.isHandheld) ? '' : '<li onmouseout=this.className=\"\"; onmouseover=this.className=\"ieHover\">';
			} else {
				outHTML += (this.parent.isHandheld) ? '' : '<li>';
			}
			outHTML += (this.url == "") ? '' : (this.newwin) ? '<a href="' + this.url + '" target="_new">' : '<a href="' + this.url + '">';
			outHTML += this.label;
			outHTML += (this.url != "") ? '</a>' : '';
			if (this.subitems.length > 0) {
				outHTML += (this.parent.isHandheld) ? '<br/>' : '<ul>';
				for(var sidx=0; sidx< this.subitems.length; sidx++) {
					try {
						outHTML += this.subitems[sidx].build();
					} catch(err) {
						alert("ERROR: " + err + "\nprocessing [" + this.label + "] subitem [" + sidx + "]")
					}
				}
				outHTML += (this.parent.isHandheld) ? '' : '</ul>';
			}
			outHTML += (this.parent.isHandheld) ? '<br/>' : '</li>'
		} else {
			// vertical logic here...
		}
		return outHTML;
	}
}

var ofestMenu = new TSDynamicMenu();

var wrkitem = new TSDynamicMenuItem(ofestMenu, "http://www.germaniasociety.com/site2007/main.html","Home");
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/history.html", "History of Club"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/mission.html", "Mission Statement"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/photos.html","Photos Of Club"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/crest.html","Our Crest"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/president.html","President of the Club"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/echos.html","Echo Newsletter"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/contacts.html","Germania Contacts"));
ofestMenu.items.push(wrkitem);


var wrkitem = new TSDynamicMenuItem(ofestMenu, "", "Major Events" );
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/oktoberfest2011/oktoberfest11.html", "Oktoberfest"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/christkindlmarkt/christkindlmarkt.html", "Christkindlmarkt"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/volksmarch.html", "Volksmarch"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/flyers/volksmarch_prereg_hunters_walk.pdf", "Volksmarch Registration Form"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/karneval.html", "Karneval Section"));
ofestMenu.items.push(wrkitem);

var wrkitem = new TSDynamicMenuItem(ofestMenu, "", "Rentals and Directions");
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/directions.html", "Directions to Germania Park"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/rentals/klubhaus.html", "Club House Rentals"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/rentals/pavillion.html", "Pavilion Rentals"));
ofestMenu.items.push(wrkitem);

var wrkitem = new TSDynamicMenuItem(ofestMenu, "","Calendars and Membership");
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/event.html", "Germania Events"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/meeting.html", "Meeting Schedule"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/jagdhorn.html","Jagdhorn Appearance Schedule"));
wrkitem.subitems.push(new TSDynamicMenuItem(ofestMenu, "/site2007/membership.html","Membership Information"));
ofestMenu.items.push(wrkitem);

var wrkitem = new TSDynamicMenuItem(ofestMenu, "/site2007/links.html","Links");
ofestMenu.items.push(wrkitem);


document.write(ofestMenu.build());
