//Delcom Menu JavaScript Functions

var TimeOut         = 300;
var currentLayer    = null;
var currentitem     = null;
var currentLayerNum = 0;
var noClose         = 0;
var closeTimer      = null;

function mopen(n) {
  var l  = document.getElementById("menu"+n);
  var mm = document.getElementById("mmenu"+n);

  if(l) {
    mcancelclosetime();
    l.style.visibility='visible';
    if(currentLayer && (currentLayerNum != n))
      currentLayer.style.visibility='hidden';
    currentLayer = l;
    currentitem = mm;
    currentLayerNum = n;
  } else if(currentLayer) {
    currentLayer.style.visibility='hidden';
    currentLayerNum = 0;
    currentitem = null;
    currentLayer = null;
 	}
}

function mclosetime() {
  closeTimer = window.setTimeout(mclose, TimeOut);
}

function mcancelclosetime() {
  if(closeTimer) {
    window.clearTimeout(closeTimer);
    closeTimer = null;
  }
}

function mclose() {
  if(currentLayer && noClose!=1)   {
    currentLayer.style.visibility='hidden';
    currentLayerNum = 0;
    currentLayer = null;
    currentitem = null;
  } else {
    noClose = 0;
  }
  currentLayer = null;
  currentitem = null;
}






// ------------------------------------------------------------------------ //
// Get left posiiton - Used by ImagePopUp
// ------------------------------------------------------------------------ //
function getElementLeftPos(elm) 
{
    var x = 0;

    //set x to elm’s offsetLeft
    x = elm.offsetLeft;

    //set elm to its offsetParent
    elm = elm.offsetParent;

    //use while loop to check if elm is null
    // if not then add current elm’s offsetLeft to x
    //offsetTop to y and set elm to its offsetParent

    while(elm != null)
    {
        x = parseInt(x) + parseInt(elm.offsetLeft);
        elm = elm.offsetParent;
    }
    return x;
}

// ------------------------------------------------------------------------ //
// Get top position - Used by ImagePopUp
// ------------------------------------------------------------------------ //
function getElementTopPos(elm) 
{
    var y = 0;

    //set x to elm’s offsetLeft
    y = elm.offsetTop;

    //set elm to its offsetParent
    elm = elm.offsetParent;

    //use while loop to check if elm is null
    // if not then add current elm’s offsetLeft to x
    //offsetTop to y and set elm to its offsetParent

    while(elm != null)
    {
        y = parseInt(y) + parseInt(elm.offsetTop);
        elm = elm.offsetParent;
    }
    return y;
}

// ------------------------------------------------------------------------ //
// Display it - 
// Requires hold in the body -> <div id="imagepopupbox"></div> 
// Already in the DPMENU.htm if using menu
// ------------------------------------------------------------------------ //
function ImagePopUp(obj,src)
{       
    var imgbox=document.getElementById("imagepopupbox");
    imgbox.style.visibility='visible';
    var img = document.createElement("img");
    //img.src=obj.src;
    img.src = src;
    img.style.width='300px';
    img.style.height='300px';
    
    if(img.addEventListener){
        img.addEventListener('mouseout',ImageKill,false);
    } else {
        img.attachEvent('onmouseout',ImageKill);
    }             
    imgbox.innerHTML='';
    imgbox.appendChild(img);
    imgbox.style.left=(getElementLeftPos(obj)+75) +'px'; // show img at
    imgbox.style.top=(getElementTopPos(obj)-50) + 'px';
    
}


// ------------------------------------------------------------------------ //
// Remove popup image
// ------------------------------------------------------------------------ //
function ImageKill()
{
    document.getElementById("imagepopupbox").style.visibility='hidden';
}


  document.onclick = mclose;
  
  // EOF
