// Last modification: 4/26/2008
//
// Javascript copyright 2003-2008 by Jeff Krause.  All rights reserved.
// Licensed to Erin Mahoney.
//
// pageUrl is set to name of including file, such as "index.html" or "links.html"
//
// Make sure we are not in some other web sites window (such as ccNow)
//
var fWriteTrailer = false;

function mainPage(url, name, fTrailer, icon, description, fNew) {
	var title = null;
	if (fNew == null) fNew = false;
	rgPages[nrgPages] = new pageRecord(url, name, title, icon, description,fNew);
	if (fTrailer) defineTrailerMenu(name,url);
	nrgPages++;
	nrgPagesInMenu = nrgPages;
	}

function defineSubMenu(w,x,y,_args) {
	var iArgsStart = 3;
	var sArgs = 5;
	var args = defineSubMenu.arguments;
	var nargs = args.length;
	var iPageCurrent = nrgPages-1;
	var p = rgPages[iPageCurrent];
	for (var i = (iArgsStart + sArgs - 1); i < nargs; i += sArgs) {
		var name		= args[i-4];
		var url			= args[i-3];
		var fTrailer	= args[i-2];
		var description	= args[i-1];
		var fNew		= args[i-0];
		p.rgSubMenu[p.nrgSubMenu] = new subMenuRecord(name,url,description,fNew);
		if (fTrailer) defineTrailerMenu(name,url);
		p.nrgSubMenu++;
		}
	rgPages[iPageCurrent].xOffsetSubMenu = x;
	rgPages[iPageCurrent].yOffsetSubMenu = y;
	rgPages[iPageCurrent].subMenuDiv = sm_initSubMenuDivStyle(w);
	}

function defineTrailerMenu(name, url) {
	for (var i = 0; i < nrgMenu_trailer; i++) if (rgMenu_trailer[i].name == name) return;
	rgMenu_trailer[nrgMenu_trailer++] = new trailerMenuType(name,url);
	if ((nrgMenu_trailer == 1) || (!fSortTrailer)) return;
	var a = nrgMenu_trailer - 1;
	var b = nrgMenu_trailer - 2;
	while (b >= 0) {
		if (rgMenu_trailer[a].name < rgMenu_trailer[b].name) {
			var t = rgMenu_trailer[a];
			rgMenu_trailer[a] = rgMenu_trailer[b];
			rgMenu_trailer[b] = t;
			}
		a--;
		b--;
		}
	}

function pageRecord(url,name,title,icon,description,fNew) {
	this.members = 'link,name,icon,description,fNew,iPage,wMenu,display,iMenu,xOffsetSubMenu,yOffsetSubMenu,wSubMenu,subMenuDiv,rgSubMenu,nrgSubMenu';
	this.link = (url == null ? null : homePrefix + url);
	this.name = name;
	this.icon = icon;
	this.description = description;
	this.fNew = fNew;
	this.iPage = nrgPages;				// menu identifier (handle) associated with each link page
	this.wMenu = null;					// (set later) width of the <TD> for a menu item
	this.display = name;				// text to be displayed if (fImages == false)
//	this.img							// image to be displayed if (fImages == true)
//	this.img_hl							// mouseOver version of image
	this.iMenu = '1';					// identifier to distinguish menu class names
	this.xOffsetSubMenu;				// how far [x] from the top left of the <TD> or <IMG> of menu item to show sub menu
	this.yOffsetSubMenu;				// how far [y] from the top left of the <TD> or <IMG> of menu item to show sub menu
	this.wSubMenu = 144;
	this.subMenuDiv = null;				// ID of <DIV> enclosing subMenu for this menu item
	this.rgSubMenu = new Array();
	this.nrgSubMenu = 0;
	}

function subMenuRecord(name,url,description,fNew) {
	this.members = 'name,description,fNew,display,link';
	this.name = name;					// text to be displayed if (fImages == false)
	this.display = name;				// text to be displayed if (fImages == false)
	this.link = (url == null ? null : homePrefix + url);		// page to goto when clicked
	this.description = description;
	this.fNew = fNew;
//	this.img							// image to be displayed if (fImages == true)
//	this.img_hl							// mouseOver version of image
	}

function trailerMenuType(name, url) {
	this.members = 'name,display,link';
	this.name = name;
	this.display = name;
	this.link = url;
	}

function preLoadImage(image) {
	rgPreLoad[nrgPreLoad] = new Image();
	rgPreLoad[nrgPreLoad].src = image;
	nrgPreLoad++;
	}

function checkBrowser() {
	if (navigator.appName == "Microsoft Internet Explorer") {
		for (var i = 0; i < navigator.appVersion.length; i++) {
			var t = navigator.appVersion.substr(i,4);
			if (t == "MSIE") {
				fBrowser_IE6 = (parseInt(navigator.appVersion.substr(i+4)) >= 6);
				return;
				}
			}
		}
	else if (navigator.appName == 'Netscape') fBrowser_NS6 = (parseFloat(navigator.appVersion) >= 5);
	}

function showData() {
	var html = 'Page Info:';
	for (var i = 0; i < nrgPages; i++) {
		if (i == iPage) html += '<b>';
		html += '<br>&nbsp;&nbsp;&nbsp;&nbsp;';
		if (i < 10) html += '0';
		html += i + ' ' + rgPages[i].name + ', ' + rgPages[i].link;
		if (i == iPage) html += '</b>';
		}
	html += '<hr>';
	document.writeln(html);
	}

function writeHeader(hTitle,hSubtitle) {
	if (typeof hTitle != 'string') hTitle = null;
	if (typeof hSubtitle != 'string') hSubtitle = null;
	var w = Math.floor((100-nrgPagesInMenu-1) / nrgPagesInMenu);
//alert(w + ',' + nrgPagesInMenu);
	for (var i = 0; i < nrgPagesInMenu; i++) rgPages[i].wMenu = w + '%';
	var html = '<table class=header_table width="100%" height=160 border=0 cellpadding=0 cellspacing=0>';
	html += '<tr><td height=100 align=right valign=top>';
	html += '<p class=header_infoText>' + clib_emailLink(em_eName,'erinmahoney','com','erinmahoney.com inquiry','header_infoText');
	html += '<p class=header_infoText>+1 (408) 761-1303';
	html += '<br><img src="smblank.gif" width=850 height=1 border=0>';
//	html += '<p class=header_infoText>&copy;' + thisYear;

	html += '</td></tr>';
	html += '<tr><td valign=top>';
	html += sm_writeMenus(null, nrgPagesInMenu, rgPages, -1, false, 'b_headerTableMenu', 'b_headerTdMenu', 'b_headerLinksMenu', 'b_headerLinksMenuHL', 'b_headerLinksMenuNoHL');
	if (hTitle != null) {
		html += '<p class=header_title>' + hTitle;
		if (hSubtitle != null) html += '<br><span class=header_subtitle>' + hSubtitle + '</span>';
		html += '</p>';
		}
	html += '</td></tr>';
	html += '</table>\n';
	var clTable = 'b_headerTableSubMenuText';
	var clTd = 'b_headerTdSubMenu';
	var clLinks = 'b_headerLinksSubMenu';
	var clLinksHL = 'b_headerLinksSubMenuHL';
	html += sm_initSubMenuDivs(rgPages,nrgPagesInMenu,false, clTable,clTd,clLinks,clLinksHL,null);
	document.writeln(html);
	}

function writeTrailer() {
	var html = '';
	if (fWriteTrailer && (nrgMenu_trailer > 0)) {
		html += '<table class="b_trailertable" align=center width="95%" border=0 cellpadding=0 cellspacing=0><tr>';
		var tdW = Math.floor(100/nrgMenu_trailer);
		for (var i = 0; i < nrgMenu_trailer; i++) {
			var t = rgMenu_trailer[i];
			html += '<td width="' + tdW + '%" align=center>';
			var aId = clib_newElementId();
			html += '<a id=' + aId + ' class=b_trailerlinks ';
			html += 'onmouseover="' + "clib_changeClass('" + aId + "','b_trailerlinksHL')" + '" ';
			html += 'onmouseout="' + "clib_changeClass('" + aId + "','b_trailerlinks')" + '" ';
			html += 'href="' + t.link + '">' + t.display + '</a>';
			html += '</td>';
			}
		html += '</tr></table>';
		}
	clib_innerHTML('div_trailer',html);
	}

if (window != top) top.location.href = location.href;

var gray = '#555555';
var erinRed = '#D82C38';
var em_eName = 'sales';
var em_eMail = em_eName + '@' + 'erinmahoney' + '.' + 'com';
var em_phone = '408/761-1303';
var em_address = '601 Van Ness Ave, #E3-122';
var em_cityStateZip = 'San Francisco, CA&nbsp; 94102';
var todayDate = new Date();
var thisYear = todayDate.getFullYear();
var fBrowser_IE6 = false;
var fBrowser_NS6 = false;
var rgPages = new Array(); clibdb_register('rgPages');
var nrgPages = 0;
var nrgPagesInMenu;
var iPage = null;
var rgMenu_trailer = new Array();
var nrgMenu_trailer = 0;
var fSortTrailer = false;
var rgPreLoad = new Array();
var nrgPreLoad = 0;
if (eval('typeof homePrefix') == 'undefined') var homePrefix = '';
var fLocal = ((document.location + '~').substr(0,5) == 'file:');		// force to be string and see if its "file:..."

var emLogoClick = (clib_fLocal ? ' style="cursor:help;" onclick="top.location.href=' + "'http://erinmahoney.com/" + clib_pageUrl + "';" + '"' : '');

checkBrowser();
clib_preLoadImages('blank.gif','logos/logo.jpg','smblank.gif');

//
// menuItems displayed at top of every page
//
mainPage('home.html', 'Home', true, null, 'Home page...');
mainPage(null, 'About', true, 'buttons/about_icon.jpg', 'About Erin Mahoney');
	defineSubMenu(144,0,0
		,'Erin Mahoney','erin.html',false, null, false
		,'Photo Gallery','gallery.html',false, null, false
		,'News & Reviews','news.html',true, null, false
//		,'Public Relations','press.html',true, null, false
		);
		
mainPage(null, 'Purchase', true, 'buttons/sales_icon.jpg', 'How to buy');
	defineSubMenu(144, 0, 0
		,'Retail Stores','retail.html',false, null, false
		,'Weddings','weddings.html',true, null, true
//		,'Wholesale','wholesale.html',false, null, false
		,'Events','events.html',true,null,false
		,'Mailing List','signup.html',false, null, false
		);

// mainPage('events.html', 'Events', true, 'buttons/events_icon.jpg', 'Upcoming events');

mainPage('links.html',	'Links', true, 'buttons/links_icon.jpg', 'Links');

//
// figure out which page we are included in
//
for (var i = 0; i < nrgPages; i++) if ((rgPages[i].link == pageUrl) && (rgPages[i].name == pageTitle)) iPage = i;
// if page is not defined above make a special entry for it
if (iPage==null) {
	rgPages[nrgPages] = new pageRecord(pageUrl, pageTitle);
	iPage = nrgPages;
	nrgPages++;
	} 
	
setTimeout('sm_enableMenus()',100);

//
// Generate links for index.html
//
function generateLinks() {
	var html = '<table><tr>\n';
	for (var i = 0; i < nrgPages; i++) {
		var p = rgPages[i];
		html += '<td><a href="' + p.link + '">' + p.display + '</a></td>' + String.fromCharCode(13,10);
		for (var j = 0; j < p.nrgSubMenu; j++) {
			var sp = p.rgSubMenu[j];
			html += '<td><a href="' + sp.link + '">' + sp.display + '</a></td>' + String.fromCharCode(13,10);
			}
		}
	html += '</tr></table>\n';
	window.clipboardData.setData("Text", html);
	}

if (clib_fLocal) {
	if (typeof clibdb_dump == 'undefined') clib_writeln('<scri' + 'pt language="JavaScript" type="text/javascript" src="clib_debug.js"></sc' + 'ript>');
	if (typeof clibp_newPassCode == 'undefined') clib_writeln('<scri' + 'pt language="JavaScript" type="text/javascript" src="clib_passcodes.js"></sc' + 'ript>');
	}

