
function setup(objname,growdir,minheight,minwidth,mframes,mdelay,vis,bg_color,bg_url){
 var obj1=document.getElementById(objname);
 obj1.growdir=growdir;   
 obj1.minheight=minheight;
 obj1.maxheight=parseInt(obj1.style.height);
 obj1.minwidth=minwidth;
 obj1.maxwidth=parseInt(obj1.style.width);
 obj1.mframes=mframes;
 obj1.mdelay=mdelay;
 obj1.style.visibility=vis;
 if (bg_color !='') obj1.style.backgroundColor=bg_color;
 if (bg_url != '')  obj1.style.background='url('+bg_url+')';
 obj1.mstat=0;
 obj1.tlx=parseInt(obj1.style.left)+parseInt(document.getElementById('mdiv').style.left); // calculated corners
 obj1.tly=parseInt(obj1.style.top)+parseInt(document.getElementById('mdiv').style.top);
 obj1.brx=obj1.tlx+obj1.maxwidth;
 obj1.bry=obj1.tly+obj1.maxheight;
 }

function mouseX(evt) { // get mouse X position cross-platform
 if (evt.pageX) {
  return evt.pageX;
  } else {
  if (evt.clientX){
   return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft :   document.body.scrollLeft);
   } else {
   return null;
   }
 }        
}
function mouseY(evt) {  // get mouse Y position cross-platform
if (evt.pageY) {
 return evt.pageY;
 } else {
 if (evt.clientY){
  return evt.clientY + (document.documentElement.scrollTop ?
  document.documentElement.scrollTop :
  document.body.scrollTop);
  }else {
  return null;
  }
 }
}
function turnoff(objname) {
// pointless indirection in this context, but could be expanded if required to do more when the div is closed.
 shrinkmenu(objname);
 }
function turnon(objname){
 growmenu(objname);
}
// -- There may be a better way, but one gmenu per choice in this application...
// -- Adding more entries will require adding more of these. We should be able to store them in the object DIV.
 
   function resize(targt,xinc,yinc,sizedir){ // -------------------------
   // targt=target object 
   // xinc=addition to width (may be <0)
   // yinc=addition to height(may be <0)
   // sizedir=grow or shrink direction 
   //	0=centered,
   //	1 from bottom left,
   //	2 from bottom right,
   //	3 from bottom right,
   //	4 from top right
    var newtop =parseInt(targt.style.top);
    var newleft=parseInt(targt.style.left);
    if (newtop <0) newtop=0;
    if (newleft<0) newtop=0;
    targt.style.top=newtop +'px';
    targt.style.left=newleft +'px';
     // Add values to height and width
    targt.style.width   =(parseInt(targt.style.width )+xinc)+'px';
    targt.style.height  =(parseInt(targt.style.height)+yinc)+'px';  
   } // ---------------- end resize -------------------------------------

  function growmenu(objname){ // -------------------  
   var obj=document.getElementById(objname);
   if (obj.mstat==0){
    obj.style.visibility='visible';
    var currheight=parseInt(obj.style.height);
    var currwidth= parseInt(obj.style.width );
    var yinc=(obj.maxheight-obj.minheight)/obj.mframes;
    var xinc=(obj.maxwidth- obj.minwidth) /obj.mframes;
    var yremainder=obj.maxheight-currheight;
    if (yremainder<yinc){yinc=yremainder};
    var xremainder=obj.maxwidth-currwidth;
    if (xremainder<xinc){xinc=xremainder};
    var dly=obj.mdelay/obj.mframes;

    resize(obj,xinc,yinc,obj.growdir);
    if (currheight < obj.maxheight){
     var cmd='growmenu(\"'+objname+'\");';
     setTimeout(cmd,dly);
     }
    }
  } // ----end growmenu----------------------------

  function shrinkmenu(objname){ // -----------------
    var obj=document.getElementById(objname);
    obj.mstat=1;
    var currheight=parseInt(obj.style.height);
    var yinc=(obj.maxheight-obj.minheight)/obj.mframes;
    var remainder=currheight-obj.minheight;
    if (remainder<yinc) yinc=remainder;
    var dly=obj.mdelay/obj.mframes;
    resize(obj,0,0-yinc,obj.growdir);
    if (currheight > obj.minheight){
     var cmd='shrinkmenu(\"'+objname+'\");';
     setTimeout(cmd,dly);
     } else {
      obj.mstat=0;
      obj.style.visibility='hidden';
     }
    } // ----end shrinkmenu-------------------------

