if (document.all)    {n=0;ie=1;ns6=0;fShow="visible";fHide="hidden";}
if (document.getElementById&&!document.all)    {n=0;ie=0;ns6=1;fShow="visible";fHide="hidden";}
if (document.layers) {n=1;ie=0;ns6=0;fShow="show";fHide="hide";}

//Top Nav bar script v2- http://www.dynamicdrive.com/dynamicindex1/sm/index.htm

opr6=ie&&navigator.userAgent.indexOf("Opera")!=-1

window.onerror=new Function("return true")
////////////////////////////////////////////////////////////////////////////
// Function Menu()                                                        //
////////////////////////////////////////////////////////////////////////////

function Menu()
{
	this.bgColor     = "white";
	if (ie||ns6) this.menuFont = "bold 12px Arial";
	if (n)  this.menuFont = "bold 12px Verdana";
	this.fontColor   = "black";

	this.getInvert = getInvert;
	this.addItem    = addItem;
	this.addSubItem = addSubItem;
	this.showMenu   = showMenu;
	this.mainPaneBorder = 0;
	this.subMenuPaneBorder = 0;

	this.subMenuPaneWidth = 55;

	lastMenu = null;
	
	rightY = 0;
	leftY = 0;
	rightX = 0;
	leftX = 0;

	HTMLstr = "";
	HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
	HTMLstr += "\n";
	if (ie||ns6) HTMLstr += "<div id='MainTable' style='position:relative;top:0'>\n";
	HTMLstr += "<table width='100%' bgcolor='"+this.bgColor+"' cellpadding='0' cellspacing='0' border='"+this.mainPaneBorder+"'>\n";
	HTMLstr += "<tr>";
	HTMLstr += '<td border = 0 class="menuBar" width="99%"  ><a href="index.html"> <img src= "gifs/meganFlaxPhotography.gif" border="0"></a></td>';
	if (n) HTMLstr += "<td> ";
	HTMLstr += "<!-- MAIN MENU STARTS -->\n";
	HTMLstr += "<!-- MAIN_MENU -->\n";
	HTMLstr += "<!-- MAIN MENU ENDS -->\n";
	if (n) HTMLstr += "</td>";
	HTMLstr += "</tr>\</table>\n";
	HTMLstr += "\n";
	HTMLstr += "<!-- SUB MENU STARTS -->\n";
	HTMLstr += "<!-- SUB_MENU -->\n";
	HTMLstr += "<!-- SUB MENU ENDS -->\n";
	HTMLstr += "\n";
	if (ie||ns6) HTMLstr+= "</div>\n";
//	if (n)  HTMLstr+= "</layer>\n";
	HTMLstr += "<!-- MENU PANE DECALARATION ENDS -->\n";
}

function getStandard( inButtonName )
{
	eval('document.' + inButtonName +'.src = "gifs/' + inButtonName + '_s.gif"');
}

function getInvert( inButtonName )
{	
	eval('document.' + inButtonName +'.src = "gifs/' + inButtonName + '_i.gif"');
}
function addItem(idItem, inButtonName, hint, location, altLocation, target)
{
	var Lookup = "<!-- ITEM "+idItem+" -->";
	if (HTMLstr.indexOf(Lookup) != -1)
	{
		alert(idParent + " already exist");
		return;
	}
	var MENUitem = "";
	MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
	if (n)
	{
		MENUitem += "<ilayer name="+idItem+" class=menuBarCell>";
		MENUitem += "<a href='.' ";
		if (target != null)
			MENUitem += "target='"+target+"' ";
		MENUitem += "class=menuBar onmouseover=\"displaySubMenu('"+idItem+"'); getInvert('" + inButtonName + "')\" onclick=\"return false;\">";
		MENUitem += "inButtonName";
		MENUitem += "</a>";
		MENUitem += "</ilayer>";
	}
	if (ie||ns6)
	{
		MENUitem += "<td class=menuBar>\n";
		MENUitem += "<div id='"+idItem+"' >\n";//style='position:relative;'>\n";
		MENUitem += '<a ';

		if (target != null)
			MENUitem += "target='"+target+"' ";
		MENUitem += "class=menuBar ";
		if (hint != null)
			MENUitem += "title='"+hint+"' ";
		if (location != null)
		{
			MENUitem += "href='"+location+"' ";
			MENUitem += 'onmouseover="hideAll()" ';
		}
		else
		{
			if (altLocation != null)
				MENUitem += "href='"+altLocation+"' ";
			else
				MENUitem += "href='.' ";
			MENUitem += 'onMouseOver="getInvert(\'' + inButtonName + '\');  displaySubMenu(\''+idItem+'\')" ';
			MENUitem += 'onMouseOut="getStandard(\'' + inButtonName + '\')"';
		}
		MENUitem += '><img name="' + inButtonName + '" border="0" src="gifs/' + inButtonName + '_s.gif\"</a></div></td>';
	}
	MENUitem += "<!-- END OF ITEM "+idItem+" -->\n\n";
	MENUitem += "<!-- MAIN_MENU -->\n";

	HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);
}

function addSubItem(idParent, inButtonName, hint, location)
{
	var MENUitem = "";
	Lookup = "<!-- ITEM "+idParent+" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		alert(idParent + " not found");
		return;
	}
	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		if (n)
		{
			MENUitem += "\n";
			MENUitem += "<layer id='"+idParent+"submenu' visibility=hide bgcolor='"+this.bgColor+"'>\n";
			MENUitem += "<table border='"+this.subMenuPaneBorder+"' width="+this.subMenuPaneWidth+">\n";
			MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			MENUitem += "</table>\n";
			MENUitem += "</layer>\n";
			MENUitem += "\n";
		}
		if (ie||ns6)
		{
			MENUitem += "\n";
			MENUitem += "<div id='"+idParent+"submenu' onmouseout=operahide() style='border: 0px; padding: 0px; margin: 0px; position:absolute; visibility: hidden; z-index:100; width: "+this.subMenuPaneWidth+";  top: -300;'>\n"; 
			MENUitem += "<table class=menuItemTable width="+this.subMenuPaneWidth+">\n";
			MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			MENUitem += "</table>\n";
			MENUitem += "</div>\n";
			MENUitem += "\n";
		}
		MENUitem += "<!-- SUB_MENU -->\n";
		HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", MENUitem);
	}

	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
	if (n)  MENUitem = "<tr><td class=menuItemCell><a class=menuItem title='"+hint+"' href='"+location+"'>"+inButtonName+"</a><br></td></tr>\n";
	if (ie||ns6) 
	{
		MENUitem = '';
		MENUitem += '<tr>';
		MENUitem += '<td class=menuItemCell>';
		MENUitem += '<a ';
		MENUitem += 'class=menuItem ';
		MENUitem += 'title="' + hint + '" ';
		MENUitem += 'href="' + location + '" ';
		MENUitem += 'onMouseOver="getInvert(\'' + inButtonName + '\')"';
		MENUitem += 'onMouseOut="getStandard(\'' + inButtonName + '\')"';

		MENUitem += ' > <img name="' + inButtonName + '"  src="gifs/' + inButtonName + '_s.gif" border="0"></a></td></tr>\n'; 
		
		}
	MENUitem += Lookup;
	HTMLstr = HTMLstr.replace(Lookup, MENUitem);

}

function showMenu()
{
	document.writeln(HTMLstr);
}

////////////////////////////////////////////////////////////////////////////
// Private declaration
function displaySubMenu(idMainMenu)
{
	//hideAll();
	var menu;
	var submenu;
	if (n)
	{

		submenu = document.layers[idMainMenu+"submenu"];
		if (lastMenu != null && lastMenu != submenu) hideAll();
		submenu.left = document.layers[idMainMenu].pageX + 2;
		submenu.top  = document.layers[idMainMenu].pageY + 25;
		submenu.visibility = fShow;

		leftX  = document.layers[idMainMenu+"submenu"].left;
		rightX = leftX + document.layers[idMainMenu+"submenu"].clip.width;
		leftY  = document.layers[idMainMenu+"submenu"].top+
			document.layers[idMainMenu+"submenu"].clip.height;
		rightY = leftY;
//		document.write(rightY);
	} 
	else if (ie||ns6) 
	{
		menu = ie? eval(idMainMenu) : document.getElementById(idMainMenu);
		//document.write("menu = " +eval(idMainMenu));
		submenu = ie? eval(idMainMenu+"submenu.style") : document.getElementById(idMainMenu+"submenu").style;

		submenu.left = calculateSumOffset(menu, 'offsetLeft') + 2;
		submenu.top  = menu.style.top+25;
		submenu.visibility = fShow;
		if (lastMenu != null && lastMenu != submenu) hideAll();

		leftX  = ie? document.all[idMainMenu+"submenu"].style.posLeft : parseInt(document.getElementById(idMainMenu+"submenu").style.left);
		rightX = ie? leftX + document.all[idMainMenu+"submenu"].offsetWidth : leftX+(document.getElementById(idMainMenu+"submenu").offsetWidth);
//document.write("offsetWidth = " + document.getElementById(idMainMenu+"submenu").offsetWidth);
//document.write("<BR>offsetWidth = " + document.all[idMainMenu+"submenu"].offsetWidth );
//document.write(document.getElementById(idMainMenu+"submenu").offsetHeight);
		leftY  = ie? document.all[idMainMenu+"submenu"].style.posTop+document.all[idMainMenu+"submenu"].offsetHeight : 
			parseInt(document.getElementById(idMainMenu+"submenu").style.top)+document.getElementById(idMainMenu+"submenu").offsetHeight;
		rightY = leftY;
		//document.write('what the hex' + document.getElementById(idMainMenu+"submenu").offsetHeight);

//		document.writeln("what the hex");
	//	document.write("rightx = " + rightX +" leftX = " + leftX+ "<BR>");
	}
	lastMenu = submenu;
}

function hideAll()
{
	if (lastMenu != null) {lastMenu.visibility = fHide;lastMenu.left = 0;}
}

function calculateSumOffset(idItem, offsetName)
{
	var totalOffset = 0;
	var item = eval('idItem');
	do
	{
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	} while (item != null);
	return totalOffset;
}

function updateIt(e)
{
	if (ie&&!opr6)
	{
		var x = window.event.clientX;
		var y = window.event.clientY;
//			

		if (x > rightX || x < leftX)
		{
		//	document.write("x " + x+ " rightx "+rightX + " leftx " +leftX);
		 	hideAll();
		 }
		else if (y > rightY) 
		{
			hideAll();
	//		document.write('rightY = ' + rightY + ' y= ' +y);
			}
	}
	if (n||ns6)
	{
		var x = e.pageX;
		var y = e.pageY;
//		document.write('rightY = ' + rightY + ' y= ' +y);
		if (x > rightX || x < leftX)
		{
		//	document.write("x " + x+ " rightx "+rightX + " leftx " +leftX);
			hideAll();
			}
		
		else if (y > rightY) 
		{
			//		document.write('rightY = ' + rightY + ' y= ' +y);

			hideAll();
		
		}
	}
}

function operahide()
{
	if (opr6)
	{
		if (!MainTable.contains(event.toElement))
		hideAll()
	}
}

if (ie||ns6)
{
	document.body.onclick=hideAll;
	document.body.onscroll=hideAll;
	document.body.onmousemove=updateIt;
}
if (document.layers)
{
	window.captureEvents(Event.MOUSEMOVE);
	window.captureEvents(Event.CLICK);
	window.onmousemove=updateIt;
	window.onclick=hideAll;
}


	 function showToolbar()
        {
            // usage of the menu class from menu.js:
            // menu.addItem(id, gif, hint, location, alternativeLocation);
            // menu.addSubItem(idParent, text, hint, location);

            menu = new Menu();
            menu.addItem( "Home", "home", "Home", null, "index.html");
            menu.addItem( "Portfolio", "portfolio", "Portfolio", null, "children.html" );
            	menu.addSubItem( "Portfolio", "montreal", "Montreal", "montreal.html" );
            	menu.addSubItem( "Portfolio", "children", "Children", "children.html" );
			menu.addItem( "Contact", "contact", "Contact", null, "mailto:megan@meganflax.com" );
            menu.showMenu();
        }