//------------------ Start of menu code Global variables --------------------------
MN_level   = 0
MN_id      = 0 
MN_kill    = false
needEnd    = false	
sliderSpeed	= 5 // Px per cycle 
cycleTime   = 30
inMotion    = false
MN_exObj    = 0 
sliderObj  = null
//Event      = null	
try{
servicesJS()
crossBrowserJS()
} 
catch(e){alert("menuMaker - services.js and crossBrowser.js must be linked ")}
finally{}
//------------------------------- Menu Start --------------------------------------------------------------
function menuStart(orien,   // 1 - Orientation - Vertical,HorizontalUp,HorizontalDown
                   style,   // 2 - Qualifies class
				   topImage
				   )
{  
needEnd = false
MN_id += 1
MN_name = "Menu"+MN_id
MN_level +=1
MN_topId = 0
MN_subEntryId = 0
MN_onView = null
MN_vert  = false
MN_style = style
MN_orien = orien+""
MN_orien = MN_orien.toLowerCase() 
MN_kill  = false
if (MN_orien.substr(0,8) == "vertical"){MN_vert = true}
out = ""
out += "<table cellspacing=0 cellpadding=0><TR>" 
if (topImage)
{ 
if    (MN_orien == "vertical"){out += "<TR>"}
out+= "<TD><img src="+topImage+">"
} 
document.write(out)      //******************************************88
} 
//------------------------------ Top Menu ----------------------------------------
function menuTop(txt,
                 url,
				 target,
				 title,
				 topImage
				 )
{ 
if (needEnd)
	{
	endSub()
	needEnd=false 
	document.write("<\/Div menuTop end>") //************************************88
	}
MN_topId ++	
MN_firstSub = true
var out=""
if (url+"" == "undefined"){url="javascript:"}
if (MN_vert){out += "<TR>"}	
out     += "<TD valign=top>"
topId    = MN_name+"_top_"+MN_topId
out     += "\n<A id="+topId
out     += " class=menuTop_"+MN_style+" href="+url+" onmouseover='MN_mouseOverTop(this)'"
if (target != "" && target+"" != "undefined"){out += " target="+target}
if (title+"" != "undefined")
{
out += " title="+title
} 
out += " onmouseout='MN_mouseOutOfTop()'"
out += ">"
out +=txt+"</\A>" 
document.write(out)    //***************************************
topObj  = document.getElementById(topId)
MN_exObj = 0
} 
//----------------------------- Sub Menu entries------------------------------------------
function menuSub(txt,
                 url,
				 target,
				 title
				 )
{
var out = ""
if (MN_firstSub)
{  
//------------------- Container -------------------------
	MN_firstSub = false	
	out +="\n<div id=slideContainer"
	out +=" style='background-color:;display:none;position:absolute;top:0;overflow:hidden;height:0' onmouseout='MN_mouseOutOfContainer()'>"	 
//-------------------------------- Slider --------------------
	out +="\n<div id=slider"
	out +=" style='background-color:;position:relative;top;overflow:hidden'"
	out += "onmouseout=MN_mouseOutOfSlider()" 
    out += " orien="+MN_orien
	out += ">"
} 
//--------------------------- Sub Menu entries -----------------------
	out += "\n<A class=menuSub_"+MN_style+" href="+url
	out += " style={position:relative;top:0}" 
	if (target != "" && target+"" != "undefined"){out += " target="+target}
	if (title+"" != "undefined")
		{
		out += " title="+title
		}
	   out += ">"
	out += txt+"</\A>" 
	document.write(out)  //****************************
	document.close()
//------------------------------------------------------- 
	sliderLimit = 4
	sliderInc   = sliderSpeed
//-------------------------------------------------------
	MN_subEntryId ++
	needEnd       = true
}
//-------------------------------------------------------------------------
function endSub()
{ 
MN_firstSub = true
var out = "<\/div slider endsub>" 
document.write(out)   //*****************************************
}
//------------------------------------------------------------------------
function menuEnd(bottomImage)
{ 
MN_firstSub = true
var out = ""
if (needEnd){endSub();needEnd=false}
if (bottomImage+"" != "undefined")
{ 
 if (MN_orien == "vertical"){out += "<TR>"}
 out += "<TD><img src="+bottomImage+">"
} 
out += "<\/Table>"
document.write(out)
} 
//----------------------------------------------------------------------------------------
//----------------------- Start Execute ----------------------------------------------- 
//--------------------------------------------------------------------
function MN_mouseOutOfContainer(e)
{ 
Event = CB_getEvent(arguments.callee.caller.arguments[0]) 
}
//----------------------------------------------------------------------
function MN_mouseOutOfSlider(e)
{ 
Event = CB_getEvent(arguments.callee.caller.arguments[0]) 
checkRectangle(Event)
}
//-------------------------------------------------------------------------	
function checkRectangle(E)
{ 
var mouseX = E.pageX
if (mouseX < 0){return}
//var mouseY = E.clientY+windowInfo().scrollTop	
var mouseY = E.pageY
var left  = getOffsetLeft(sliderObj)+2
var right = left+sliderObj.offsetWidth-20
var top   = getOffsetTop(sliderObj)+2 
//alert("Top="+top+" My="+mouseY+" Scrll="+document.body.scrollTop)
var bottom = top+sliderObj.offsetHeight-15
if (MN_orien == "horizontalup"){bottom +=8;top +=2}
if (MN_orien == "horizontaldown"){bottom-=2;top-=10}
if (MN_orien == "vertical"){left -= 5,right-=2}
if (!inRectangle(left,right,top,bottom,mouseX,mouseY)){MN_hide("Chckrec")} 
//alert("Left "+left+" Right "+right+" Top "+top+" Bottom "+bottom+" MX "+mouseX+" MY "+mouseY)
}
//---------------------------------------------------- 
function MN_hide(from)
{  
//alert("Hide "+from)
switch(MN_orien)
{ 
case "horizontalup":sliderObj.style.top   = subMenuHeight 
                    break;
case "horizontaldown":sliderObj.style.top = -subMenuHeight 
                    break;
case "vertical":    sliderObj.style.left  = entryWidth 
                    break;
}  
try{
containerObj.style.display = "none" 
sliderObj.style.display    = "none" 
}
catch(e){}
finally{}
inMotion = false
}
//-----------------------------------------------------------------------
function inRectangle(left,right,top,bottom,x,y)
{  	
 //alert("Inrec L="+left+" R="+right+" T="+top+" B="+bottom+" x="+x+" y="+y)
 switch(true)
  {
  case  x <= left:
  case  x >= right:
  case  y <= top:
  case  y >= bottom:
             return false
			 break; 
  default: return true
 }
} 
//----------------------------------------------------------------------
function MN_Init(topObj)
{
MN_orien = "horizontalup"
MN_id    = 1 
try{
var  O    = document.getElementById(topObj.id +"_orien")
MN_orien  = O.value.toLowerCase() 
} 
catch(e){}
finally{}
}
//----------------------------------------------------------------
function MN_mouseOverTop(topObj)
{ 
if (inMotion){return} 
MN_Init(topObj)	
containerObj    = findNextSibling(topObj) 
if (containerObj+"" == "null"){return false}  
if (containerObj.tagName.toLowerCase() != "div"){return false} 
sliderObj       = getFirstChild(containerObj)
var AObj        = getFirstChild(sliderObj)
//alert("MenuMaker AObj nodeType =_"+AObj.nodeName+"_ sliderObj="+sliderObj.nodeType) 
if (!AObj)
{  
alert("There is an error in the menu definition\nMaybe no link for submenu item")
return
} 
topHeight       = parseInt(getCurrentStyle(topObj,"height","1"))
entryHeight     = parseInt(getCurrentStyle(AObj,"height","2"))
entryWidth      = parseInt(getCurrentStyle(AObj,"width","3"))
ANumber         = sliderObj.childNodes.length 
subMenuHeight   = entryHeight*ANumber+10 
if (isNaN(subMenuHeight))
{ 
alert("Entry Height or Width has not been defined")
return
}
if (sliderObj+""  == "null") return 
sliderLimit       =  0
//----------------------------------------------
if (MN_orien == "vertical")
{ 
	sliderObj.style.top     = "0px" 
	sliderObj.style.height  = subMenuHeight+"px"
	containerObj.style.left = getOffsetLeft(topObj)+topObj.offsetWidth	
	containerObj.style.top  = getOffsetTop(topObj)
	containerObj.style.height = subMenuHeight+"px"
	sliderObj.style.left    = -entryWidth
} 
//-------------------------------------------------	
if (MN_orien == "horizontalup")
{ 
	containerObj.style.left = getOffsetLeft(topObj) 
	containerObj.style.top  = getOffsetTop(topObj)-subMenuHeight+"px"
	containerObj.style.height = subMenuHeight+"px"
	sliderObj.style.left    = "0px"
	sliderObj.style.top     = subMenuHeight+"px"
} 
//----------------------------------------------
if (MN_orien == "horizontaldown")
{ 
	containerObj.style.left   = getOffsetLeft(topObj) 
	//alert("Menumaker left "+containerObj.style.left)
	containerObj.style.top    = getOffsetTop(topObj)+topHeight+"px"
    containerObj.style.height = subMenuHeight+"px"
	sliderObj.style.left      = "0px"
	sliderObj.style.top       = - subMenuHeight+"px"
}	
    containerObj.style.display  = "block"
//containerObj.style.borderWidth = 1            //**************************************8* 
//containerObj.style.borderStyle = "dotted"    //****************************************
//sliderObj.style.borderWidth = 1            //**************************************8* 
//sliderObj.style.borderStyle = "dotted"    //**************************************** 
//sliderObj.style.borderColor = "red" 

sliderObj.style.display        = "block"    
MN_showMenu()  
}  
//----------------------------------------------------------------------
function MN_mouseOutOfTop()
{ 
Event = CB_getEvent(arguments.callee.caller.arguments[0]) 
if (inMotion){MN_kill = true} 
if (sliderObj+"" == "null"){return}
checkRectangle(Event)
}   
//------------------------------------------------------
function getOffsetTop(O)
{
//var v = O.offsetTop	
var v  = 0
var P  = O 
while (P != null)
 {
 v += P.offsetTop
 P  = P.offsetParent
 }
 return v
}
//------------------------------------------------------
function getOffsetLeft(O)
{ 
//var v = O.offsetLeft 
var v = 0
var P = O 
while (P != null)
 {	
 v  += P.offsetLeft
 P  = P.offsetParent 
 } 
 return v
} 
//------------------------------------------------------------------------------- 
function MN_scheduleDown()
{  
  if (parseInt(sliderObj.style.top) <= sliderLimit  && !MN_kill)
  {	
  sliderObj.style.top  = parseInt(sliderObj.style.top)+sliderSpeed+"px" 
  //alert("Top "+sliderObj.style.top+" Left="+sliderObj.style.left)
  MN_timer             = setTimeout(MN_scheduleDown,cycleTime); 
  cycleCount ++
  }	
  else
  { 
  //alert("Down - Out Top=" + parseInt(sliderObj.style.top)+" limit="+sliderLimit+"  cycleCount = "+cycleCount+" Speed="+sliderSpeed)
  sliderObj.style.top  = "0px"
  inMotion = false
  MN_kill  = false 
  }
} 
//------------------------------------------------------------------------------- 
function MN_scheduleUp()
{   
  //alert("SceduleUp 1 Top=" + sliderObj.style.top+"  Lim="+sliderLimit+"  Speed="+sliderSpeed+" subheight="+subMenuHeight)
  if (parseInt(sliderObj.style.top) >= sliderLimit && !MN_kill)
  {	 
  sliderObj.style.top  = parseInt(sliderObj.style.top)-sliderSpeed+"px" 
  MN_timer             = setTimeout(MN_scheduleUp,cycleTime); 
  cycleCount ++
  }	
  else
  {
  //alert("SceduleUp Out Top="+sliderObj.style.top+"  cycleCount = "+cycleCount)	 
  sliderObj.style.top  = "0px"
  inMotion = false
  MN_kill  = false
  }
} 
//------------------------------------------------------------------------------- 
function MN_scheduleOut()
{  
  if (parseInt(sliderObj.style.left) <= sliderLimit  && !MN_kill)
  {	 
  sliderObj.style.left = parseInt(sliderObj.style.left)+sliderSpeed+"px" 
  MN_timer             = setTimeout(MN_scheduleOut,cycleTime); 
  }	
  else
  {	
  sliderObj.style.left  = 0
  inMotion = false
  MN_kill  = false
  }
}     
//------------------------------------------------------------------------------
function MN_showMenu()
{ 
if (inMotion){return}
inMotion    = true
cycleCount  = 0	
switch(MN_orien)
	{
	case "horizontaldown" :MN_scheduleDown();break
	case "horizontalup"   :MN_scheduleUp();break
	case "vertical"       :MN_scheduleOut();break 
	default:alert("MenuMaker2.js Invalid orien - "+MN_orien)
	}
if (MN_kill){MN_hide()}	
}
//---------- End of menu code------------------------------------------------------------


