﻿///
var currMenu;

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else {  // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}  
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}  

if(!inChild(document.getElementById('leftNav')) && !inDropDown())
{
 dropdownmenuOut();
}


//document.Show.MouseX.value = tempX;
//document.Show.MouseY.value = tempY;
return true;
}

//Generic mouseover event
function hover(obj)
{
 obj.style.color="#888888"
 obj.style.backgroundColor="#FFFFFF"
}

//Generic mouseout event
function leave(obj)
{
 obj.style.color="#FFFFFF"
 obj.style.backgroundColor="#888888"
}


function dropdownmenuOver(obj)
{
 dropdownmenuOut();
 var controlIndex=parseInt(obj.id.substring(5));
 var coords=findPos(obj);
 buildMenu(controlIndex,obj,coords);
 hover(obj);
}

function dropdownmenuOut()
{
 if(currMenu != undefined)
 {
  document.body.removeChild(currMenu);
  currMenu=undefined;
 }
}

function buildMenu(cIndex,obj,coords)
{

 switch(cIndex)
 {
  case 0:
     currMenu=buildAboutUs(coords,obj.offsetWidth);
     document.body.appendChild(currMenu);
   break;

  case 1:
     currMenu=buildCatering(coords,obj.offsetWidth);
     document.body.appendChild(currMenu);
   break;

  case 2:
     currMenu=buildDirections(coords,obj.offsetWidth);
     document.body.appendChild(currMenu);
   break;

  case 3:
     currMenu=buildMenus(coords,obj.offsetWidth);
     document.body.appendChild(currMenu);
   break;

  case 4:
   break;

 }
}

function buildAboutUs(coords,offsetWidth)
{
 var menu=document.createElement("DIV");
 var left=coords[0]+offsetWidth + "px";
 var top=coords[1] + "px";

 menu.style.zIndex=2;
 menu.style.position="absolute";
 menu.style.left=left;
 menu.style.top=top;
 menu.style.backgroundColor="#888888";
 var theHTML="<div id='menu'>"
 theHTML+="<div class='menuTop'  onmouseover='hover(this)' onmouseout='leave(this)' onclick=\"window.frames[0].location='History.aspx'; dropdownmenuOut();\">History of Rick's Cafe</div>";
 theHTML+="<div class='menuBottom'  onmouseover='hover(this)' onmouseout='leave(this)' onclick=\"window.frames[0].location='Reviews.aspx'; dropdownmenuOut();\">Our Reviews</div>";
 theHTML+="</div>";
 menu.innerHTML=theHTML;
 return menu;
}


function buildCatering(coords,offsetWidth)
{
 var menu=document.createElement("DIV");
 var left=coords[0]+offsetWidth + "px";
 var top=coords[1] + "px";

 menu.style.zIndex=2;
 menu.style.position="absolute";
 menu.style.left=left;
 menu.style.top=top;

 //menu.style.width="150px";
 menu.style.backgroundColor="#888888";
 var theHTML="<div id='menu'>"
 theHTML+="<div class='menuTop'  onmouseover='hover(this)' onmouseout='leave(this)' onclick=\"window.frames[0].location='Catering.aspx?TypeId=1'; dropdownmenuOut();\">Rick's Cafe Caters</div>";
 theHTML+="<div class='menuLink'  onmouseover='hover(this)' onmouseout='leave(this)' onclick=\"window.frames[0].location='Menu.aspx?TypeId=17'; dropdownmenuOut();\">Catering Menu</div>";
 theHTML+="<div class='menuBottom'  onmouseover='hover(this)' onmouseout='leave(this)' onclick=\"window.frames[0].location='Catering.aspx?TypeId=2'; dropdownmenuOut();\">Catering Policies</div>";
 theHTML+="</div>";
 menu.innerHTML=theHTML;
 return menu;
}


function buildDirections(coords,offsetWidth)
{
 var menu=document.createElement("DIV");
 var left=coords[0]+offsetWidth + "px";
 var top=coords[1] + "px";

 menu.style.zIndex=2;
 menu.style.position="absolute";
 menu.style.left=left;
 menu.style.top=top;
 //menu.style.width="150px";
 menu.style.backgroundColor="#888888";
 var theHTML="<div id='menu'>"
 theHTML+="<div class='menuTop'  onmouseover='hover(this)' onmouseout='leave(this)' onclick=\"window.frames[0].location='Location.html'; dropdownmenuOut();\">Our Location</div>";
 theHTML+="<div class='menuBottom'  onmouseover='hover(this)' onmouseout='leave(this)' onclick=\"window.frames[0].location='Events.aspx'; dropdownmenuOut();\">Events in Chagrin Falls</div>";
 theHTML+="</div>";
 menu.innerHTML=theHTML;
 return menu;
}


function buildMenus(coords,offsetWidth)
{
 var menu=document.createElement("DIV");
 var left=coords[0]+offsetWidth + "px";
 var top=coords[1] + "px";

 menu.style.zIndex=2;
 menu.style.position="absolute";
 menu.style.left=left;
 menu.style.top=top;
 //menu.style.width="150px";
 menu.style.backgroundColor="#888888";
 var theHTML="<div id='menu'>"
 theHTML+="<div class='menuTop'  onmouseover='hover(this)' onmouseout='leave(this)' onclick=\"window.frames[0].location='Menu.aspx?TypeId=3'; dropdownmenuOut();\">Dinner Menu</div>";
 theHTML+="<div class='menuLink'  onmouseover='hover(this)' onmouseout='leave(this)' onclick=\"window.frames[0].location='Menu.aspx?TypeId=2'; dropdownmenuOut();\">Lunch Menu</div>";
 ///theHTML+="<div class='menuBottom'  onmouseover='hover(this)' onmouseout='leave(this)' onclick=\"window.frames[0].location='Menu.aspx?TypeId=1'; dropdownmenuOut();\">Breakfast Menu</div>";
 theHTML+="</div>";
 menu.innerHTML=theHTML;
 return menu;
}


function findPos(obj)
{
 var curleft = curtop = 0;
 if (obj.offsetParent)
 {
  curleft = obj.offsetLeft
  curtop = obj.offsetTop
  while (obj = obj.offsetParent)
  {
   curleft += obj.offsetLeft
   curtop += obj.offsetTop
  }
 }
 return [curleft,curtop];
}


function inChild(obj)
{
 var children = obj.childNodes;
 var iCntr;
 for(iCntr=0; iCntr < children.length; iCntr++)
 {
  var child=children[iCntr];
  if(child.className == "menuButton")
  {
   var currPos=findPos(child);
   
   if(tempX >= currPos[0] && tempX <= currPos[0]+ child.offsetWidth 
   && tempY >= currPos[1] && tempY <= currPos[1]+ child.offsetHeight)
   {
    return true;
   }
  }
 }
 return false;
}

function inDropDown()
{
 if(currMenu != undefined)
 {
   var currPos=findPos(currMenu);
   if(tempX >= currPos[0] && tempX <= currPos[0]+ currMenu.offsetWidth 
   && tempY >= currPos[1] && tempY <= currPos[1]+ currMenu.offsetHeight)
   {
    return true;
   }
 }
 return false;
}
