// (C) 2001 Glenn MacStravic.  Use if you want.  No guarantees, and at
// least bother to thank me. :) 
var bw = new lib_bwcheck();
var menuDoc = self.document;
var menuWin = self;
menuObj = "";
var moving1 = 0;
var moving2 = 0;
var menuLeft = 0;
MenusMade = false;
TextOnly = false;
MenuHeaderFont="Arial";
MenuHeaderFontSize="2";
MenuHeaderFontColor="#1F3A55";
MenuHeaderBackColor="#88BCF6";
MenuHeaderBackImage="";
MenuHeaderVAlign="MIDDLE";
MenuHeaderAlign="CENTER";
MenuHeaderBold=true;
MenuCellFont="Arial";
MenuCellFontSize="2";
MenuCellFontColor="#000000";
ContrastFontColor="#000000";
MenuCellBackColor="#FFFFFF";
MenuCellBackImage="";
MenuCellHighlightColor="#CCCCCC";
MenuCellHighlightImage="";
MenuCellVAlign="MIDDLE";
MenuCellAlign="CENTER";
CellSpacing=(bw.ns5)?0:1;
DefaultLinkTarget="_top";
YOffset=2;
XOffset=0;
FiddlyTop = 0;
var winY;
staticYOffset=YOffset;
MenuHeader="Patents";
MenuBackColor="#1F3A55";
MenuBackImage="";
StaticFlag=true;
MenuWidth=120;
StaticMode="smooth";
BarExposeBackColor="#275D9B";
BarExposeBackImage="";
BarExposeFont="Arial";
BarExposeFontSize="2";
BarExposeFontColor="#FFFFFF";
BarExposeText="Menu";
BarExposeBold = true;
BarExposeWidth=16;
var LayerList = new Array("TopLayer", "MainLayer");
ShiftAmount=10;
function RevealBar() {
  if (!TextOnly) {
    RevealBar2();
  }
}

function RevealBar2() {
  if (window.cancel) {
    cancel="";
  }
  if (window.moving2) {
    clearTimeout(moving2);
    moving2="";
  }
  if ((bw.ie && menuObj.pixelLeft<0) ||
      (bw.ns && (parseInt(menuObj.left)<0)) ) {
    if (bw.ie) {
      menuLeft = menuObj.pixelLeft;
    }
    else {
      menuLeft = parseInt(menuObj.left);
    }
    menuLeft += 5%MenuWidth;
    if (menuLeft > XOffset) {
      menuLeft = XOffset;
    }
    if (bw.ie) {
      menuObj.pixelLeft = menuLeft;
    }
    else if (bw.ns4) {
      menuObj.left = menuLeft;
    }
    else if (bw.ns5) {
      menuObj.left = menuLeft+"px";
    }
    moving1 = setTimeout('RevealBar2()', 5);
  }
  else {
    clearTimeout(moving1);
  }
}

function HideBar(newObj) {
  if (!TextOnly) {
    HideBar2();
  }
}

function HideBar2() {
  if (window.moving1) {
    clearTimeout(moving1);
  }
  if ((bw.ie && menuObj.pixelLeft>(-MenuWidth))||
      (bw.ns && (parseInt(menuObj.left)>(-MenuWidth))) ) {
    if (bw.ie) {
      menuObj.pixelLeft -= (5%MenuWidth);
    }
    else if (bw.ns4) {
      menuObj.left -= (5%MenuWidth);
    }
    else if (bw.ns5) {
      menuObj.left = parseInt(menuObj.left)-(5%MenuWidth)+"px";
    }
    moving2 = setTimeout('HideBar2()', 5);
  }
  else {
    clearTimeout(moving2);
  }
}

lastY = 0;
function makeStatic(mode) {
  var Step;
  if (bw.ie) {
    winY = parseInt(menuWin.document.body.scrollTop);
  }
  if (bw.ns) {
    winY = parseInt(menuWin.pageYOffset);
  }
  if (winY != lastY) {
    Step = .2 * (winY - lastY);
    if(Step > 0) {
      Step = Math.ceil(Step);
    }
    else {
      Step = Math.floor(Step);
    }
    if (bw.ie) {
      menuObj.pixelTop+=Step;
    }
    else if (bw.ns4) {
      menuObj.top+=Step;
    }
    else if (bw.ns5) {
      menuObj.top = parseInt(menuObj.top)+Step+"px";
    }
    lastY += Step;
  }
  setTimeout('makeStatic()', 3);
}

function Test(amount) {
}	

function ShiftDown(amount) {
  var obj;
  if (LayerList) {
    if (bw.ie) {
      for (i =0; i < LayerList.length; i++) {
	obj = findObj(LayerList[i], menuDoc);
	if (obj) {
	  if (LayerList[i].indexOf("Fiddly") >- 1) {
	    obj.style.pixelTop -= amount;
	  }
	  else {
	    obj.style.pixelTop += amount;
	  }
	}
      }
    }
    else if (bw.ns4) {
      menuObj.top -= 4;
      for (i =0; i < LayerList.length; i++) {
	obj = findObj(LayerList[i], menuDoc);
	if (obj) {
	  if (LayerList[i].indexOf("Fiddly") >- 1) {
	    obj.top -= amount
	  }
	  else {
	    obj.top += amount;
	  }
	}
      }
    }
    else if (bw.ns5) {
      for (i =0; i < LayerList.length; i++) {
	obj = findObj(LayerList[i], menuDoc);
	if (obj) {
	  if (LayerList[i].indexOf("Fiddly") >- 1) {
	    obj.style.top = (parseInt(obj.top)-amount)+"px";
	  }
	  else {
	    obj.style.top = (parseInt(obj.top)+amount)+"px";
	  }
	}
      }
    }
  }
}

function CoverBottom() {
  var obj;
  obj = findObj("FiddlyLayer", menuDoc);
  if (obj) {
    if (obj.style) {
      obj = obj.style;
    }
    obj.top = FiddlyTop;
  }
}
  

function InitializeMenuBar(MenuFrame, retry) {
  if (!MenuFrame) {
    menuDoc = self.document;
  }
  else {
    menuDoc = MenuFrame.document;
  }
  if (!menuDoc) {
    if (confirm('There was a problem loading this page.  Please hit OK to reload')) { self.document.location.reload();};
    return;
  }
//	alert(TextOnly);
  if (self.document.location.search == "?TextOnly") {
    TextOnly = true;
    MenuWidth = 0;
  }
  if (TextOnly) {
    menuObj = findObj('TextMenuBar', menuDoc);
  }
  else {
    menuObj = findObj('MenuBar', menuDoc);
  }
  if (!menuObj) {
    if (confirm('There was a problem loading this page.  Please hit OK to reload')) { self.document.location.reload();};
    return;
  }
  if (menuObj.style) {
    menuObj = menuObj.style;
  }
  if (bw.ie) {
    if (!TextOnly) {
      menuObj.pixelLeft = parseInt(menuObj.pixelLeft)-MenuWidth;
    }
    menuObj.visibility = "visible";
  }
  else if (bw.ns5) {
    if (!TextOnly) {
      menuObj.left = parseInt(menuObj.left)-MenuWidth+"px";
    }
    menuObj.visibility = "visible";
  }    
  else if (bw.ns4) {
    if (!TextOnly) {
      menuObj.left = -MenuWidth;
    }
    menuObj.visibility = "show";
  }
  if ((bw.ie||bw.ns) && ((StaticFlag==true)&&StaticMode)) {
    if (MenuFrame) {
      menuWin = MenuFrame;
    }
    if (!TextOnly) {
      makeStatic();
    }
  }
  if (!MenuFrame) {
//    StartPatents();
//    EndPatents();
  }
  if (TextOnly) {
    ShiftDown(ShiftAmount);
  }
  else {
    if (bw.ns4) {
      LayerList = new Array("LeftFiddlyLayer", "RightFiddlyLayer");
      CoverBottom();
    }
  }
}

function MenuHighlight(On) {
  if (On == 1) {
    bgColor = MenuCellHighlightColor;
  }
  else {
    bgcolor = MenuCellBackColor;
  }
}

function MakeMenuItem(newText, href, target, LocalTextOnly) {
  if (!target) {
    target=DefaultLinkTarget;
  }
  if (!LocalTextOnly) {
    menuDoc.write('<TR>');
  }
  menuDoc.write('<TD CLASS="MenuLink" BGCOLOR="'+MenuCellBackColor+'" BACKGROUND="'+MenuCellBackImage+'" onMouseOver="bgColor=\''+MenuCellHighlightColor+'\';return true;" onMouseOut="bgColor=\''+MenuCellBackColor+'\';return true;"><ILAYER CLASS="MenuLink"><LAYER CLASS="MenuLink" onMouseOver="bgColor=\''+MenuCellHighlightColor+'\';return true;" onMouseOut="bgColor=\''+MenuCellBackColor+'\';return true;" WIDTH="100%">&nbsp;<A HREF="'+href);
  if (LocalTextOnly) {
    menuDoc.write('?TextOnly');
  }
  menuDoc.write('" TARGET="'+target+'" CLASS="MenuLink"><FONT FACE="'+MenuCellFont+'" Size="'+MenuCellFontSize+'" COLOR="'+MenuCellFontColor+'"><SPAN CLASS="MenuLink">'+newText+'</SPAN></FONT></A></LAYER></ILAYER></TD>');
  if (!LocalTextOnly) {
    menuDoc.write('</TR>');
  }
}

function MakeMenuHeader(newText, top) {
  menuDoc.write('<TR><TD ');
  if (MenuHeaderBackColor.length > 0) {
    menuDoc.write('BGCOLOR="'+MenuHeaderBackColor+'" ');
  }
  if (MenuHeaderBackImage.length > 0) {
    menuDoc.write('BACKGROUND="'+MenuHeaderBackImage+'" ');
  }
  menuDoc.write('WIDTH="'+(MenuWidth-BarExposeWidth-CellSpacing)+'" STYLE="background-color: '+MenuHeaderBackColor+'; background-image: '+MenuHeaderBackImage+';">&nbsp;<FONT FACE="'+MenuHeaderFont+'" SIZE="'+MenuHeaderFontSize+'" COLOR="'+MenuHeaderFontColor+'">');
  if (MenuHeaderBold == true) {
    menuDoc.write('<b>');
  }
  menuDoc.write(newText);
  if (MenuHeaderBold == true) {
    menuDoc.write('</b>');
  }
  menuDoc.write('</font></td></tr>')
}

function ResetMenu() {
  // Stoo-pid NS4 can't hack the menu unless the page is reloaded at
  // least once. This'll be an infinite loop if there are problems, of
  // course.  
//  self.document.location.reload(false);
	// T thin kI've fixed this
}

function MakeMenu(newDoc) {
  InternalMakeMenu(newDoc, true);
  InternalMakeMenu(newDoc, false);
}
function InternalMakeMenu(newDoc, LocalTextOnly) {
  if (newDoc) {
    menuDoc = newDoc;
  }
  if (!menuDoc) {
    if (confirm('There was a problem loading this page.  Please hit OK to reload')) { self.document.location.reload();};
    return;
  }
  var tempBar = "";
  if (bw.ie||bw.ns5) {
    menuDoc.write('<DIV ID=');
    if (LocalTextOnly) {
      menuDoc.write('"TextMenuBar" NAME="TextMenuBar"');
    }
    else {
      menuDoc.write('"MenuBar" NAME="MenuBar"');
    }
    menuDoc.write('style="visibility: hidden; position: absolute;');
    if (LocalTextOnly) {
      menuDoc.write('z-index: 205;top: 0; left: '+XOffset+'; background-color: '+MenuBackColor+'; background-image: url('+MenuBackImage+');" BGCOLOR="'+MenuBackColor+'">');
    }
    else {
      menuDoc.write('z-index: 200; top: '+YOffset+'; left: 0; width: 1; background-color: '+MenuBackColor+'; background-image: url('+MenuBackImage+');" onMouseOver="RevealBar();" onMouseOut="HideBar()">');
    }
  }
  else if (bw.ns4) {
    menuDoc.write('<LAYER visibility="hide"');
    menuDoc.write('" top="'+YOffset+'" ');
    if (LocalTextOnly) {
      menuDoc.write('NAME="TextMenuBar" ID="TextMenuBar" ');
    }
    else {
      menuDoc.write('NAME="MenuBar" ID="MenuBar" ');
    }
    if (!LocalTextOnly) {
      if (MenuBackColor.length > 0) {
	menuDoc.write('BGCOLOR="'+MenuBackColor+'" ');
      }
      if (MenuBackImage.length > 0) {
	menuDoc.write('BACKGROUND="'+MenuBackImage+'" ');
      }
    }
    menuDoc.write('LEFT='+XOffset+' z-index=');

    if (!LocalTextOnly) {
      menuDoc.write('200 onMouseOver="RevealBar()" onMouseOut="HideBar()">');
    }
    else {
      menuDoc.write('210">');
    }
  }
  if (!LocalTextOnly) {
    for (i=0; i < BarExposeText.length; i++) {
      tempBar+=BarExposeText.substring(i, i+1)+"<BR>";
    }
  }
  menuDoc.write('<TABLE BORDER=0 CELLSPACING='+CellSpacing+' CELLPADDING='+(LocalTextOnly*2)+' ');
	
  if (!LocalTextOnly) {
    menuDoc.write('WIDTH="'+(MenuWidth+CellSpacing+BarExposeWidth)+'" ');
  }
  if (MenuBackColor.length > 0) {
    menuDoc.write('BGCOLOR="'+MenuBackColor+'" ');
  }
  if (MenuBackImage.length > 0) {
    menuDoc.write('BACKGROUND="'+MenuBackImage+'" ');
  }
  menuDoc.write('>');
  if (!LocalTextOnly) {
    menuDoc.write('<TR><TD ');
    if (MenuHeaderBackColor.length > 0) {
      menuDoc.write('BGCOLOR="'+MenuHeaderBackColor+'" ');
    }
    if (MenuHeaderBackImage.length > 0) {
      menuDoc.write('BACKGROUND="'+MenuHeaderBackImage+'" ');
    }
    menuDoc.write('WIDTH="'+MenuWidth+'" +ALIGN="'+MenuHeaderAlign+'" VALIGN="'+MenuHeaderVAlign+'">&nbsp;<FONT FACE="'+MenuHeaderFont+'" SIZE="'+MenuHeaderFontSize+'" COLOR="'+MenuHeaderFontColor+'">');
    if (MenuHeaderBold == true) {
      menuDoc.write('<b>');
    }
    menuDoc.write(MenuHeader);
    if (MenuHeaderBold == true) {
      menuDoc.write('</b>');
    }
    menuDoc.write('</FONT></TD><TD ALIGN="CENTER" VALIGN="TOP" ROWSPAN="100" WIDTH="'+BarExposeWidth+'"');
    if (BarExposeBackColor.length > 0) {
      menuDoc.write(' BGCOLOR="'+BarExposeBackColor+'" ');
    }
    if (BarExposeBackImage.length > 0) {
      menuDoc.write(' BACKGROUND="'+BarExposeBackImage+'" ');
    }
    menuDoc.write('STYLE="background-color: '+BarExposeBackColor+'; background-image: '+BarExposeBackImage+';"><FONT FACE="'+BarExposeFont+'" SIZE="'+BarExposeFontSize+'" COLOR="'+BarExposeFontColor+'"><BR>');
    if (BarExposeBold == true) {
      menuDoc.write('<B>');
    }
    menuDoc.write(tempBar);
    if (BarExposeBold == true) {
      menuDoc.write('</B>');
    }
    menuDoc.write('</FONT></TD></tr>');
  }

  MakeMenuItem('Home', 'http://www.patentoftheweek.com/index.html', '', LocalTextOnly);

  MakeMenuItem('1996-Now',  'http://www.patentoftheweek.com/1996-Now/index.html', '', LocalTextOnly);
  MakeMenuItem('1956-1995', 'http://www.patentoftheweek.com/1956-1995/index.html', '', LocalTextOnly);
  MakeMenuItem('1917-1955', 'http://www.patentoftheweek.com/1917-1955/index.html', '', LocalTextOnly);
  MakeMenuItem('1866-1916', 'http://www.patentoftheweek.com/1866-1916/index.html', '', LocalTextOnly);
  MakeMenuItem('1790-1865', 'http://www.patentoftheweek.com/1790-1865/index.html', '', LocalTextOnly);
  MakeMenuItem('Flight', 'http://www.patentoftheweek.com/flight/index.html', '', LocalTextOnly);
  MakeMenuItem('Historical', 'http://www.patentoftheweek.com/historical/index.html', '', LocalTextOnly);
  if (!LocalTextOnly) {
    MakeMenuHeader('Links');
    MakeMenuItem('Author', 'http://www.macstravic.com', '_blank');
  }
  if (LocalTextOnly) {
    menuDoc.write('</TR></TABLE>');
  }
  else {
    menuDoc.write('<TR><TD ');
    if (MenuHeaderBackImage.length > 0) {
      menuDoc.write('BACKGROUND="'+MenuHeaderBackImage+'" ');
    }
    if (MenuHeaderBackColor.length > 0) {
      menuDoc.write('BGCOLOR="'+MenuHeaderBackColor+'" ');
    }
    menuDoc.write('><FONT SIZE="0" face="Arial">&nbsp;</FONT></TD></TR></TABLE>');
  }
  if (LocalTextOnly) {
    menuDoc.write('</SPAN>');
  }
  if (bw.ie||bw.ns5) {
    menuDoc.write('</DIV>');
  }
  else if (bw.ns4) {
    menuDoc.write('</LAYER>');
  }
  MenusMade = true;
}

function MakeMenuLink(newDoc, LocalTextOnly) {
  if ((menuDoc.location.search) && (menuDoc.location.search.length > 0) && (menuDoc.location.search == "?TextOnly")) {
    alert('1');
    menuDoc.write('<A CLASS="NoHighlight" HREF="index.html">Sliding Menu Version</A>')
  }
  else {
    alert('2');
    menuDoc.write('Is the menu not appearing in the upper left corner?<BR><A CLASS="NoHighlight" HREF="index.html?TextOnly">click here</A>');
  }
}

