// is it a DOM-enabled browser?
domBrowser = document.getElementById ? true : false;
ie = document.all ? true : false;
curMenu = new Array("", "");
overMenu = false;
closeThread = null;

//document.onmousedown = mouseDown;
//
//function mouseDown(e) {
// setTimeout( "hide( '"+curMenu[0]+"' )", 200 );
// setTimeout( "hide( '"+curMenu[1]+"' )", 200 );
//}

function showMenu( id ) {
 curMenu[1] = curMenu[0];
 curMenu[0] = id;

 if( curMenu[1] == curMenu[0]) curMenu[1] = "";
 else if( $(curMenu[1]) ) hide( curMenu[1] );

 // there is an annoying flicker without this delay because the menu gets shown before it's positioned
 // the delay isn't noticeable -- mhdavids
 //setTimeout( "show( \"" + id + "\" )", 10);
 show( id );
}

function cleanUpMenu( id ) {
 overMenu = false;
 closeThread = setTimeout( "hide( '"+curMenu[0]+"' )", 200 );
 if( curMenu[1] != "") hide( curMenu[1] );
}

function retainMenu() {
 overMenu = true;
 window.clearTimeout( closeThread );
}

// TOGGLE VISIBILITY OF DIVs
function hide( id ) {
    if( !overMenu ) {
        Element.hide( id );
    }
}               
function show( id ) {
    Element.show(id);
}

// SET ANY STYLE OF DIV
function setProperty( id, property, value) {
        var styleObject = $( id );
        if (styleObject != null) {
                styleObject = styleObject.style;
                styleObject[ property ] = value;
        }
}

function getAbsX (elt) {
  if (elt.x) return (elt.x);

  var xpos = 0;
  while (elt != null) {
    xpos += elt.offsetLeft;
    elt = elt.offsetParent;
  }
  return xpos;
}

function getAbsY (elt) {
  if (elt.y) return (elt.y);

  var ypos = 0;
  while (elt != null) {
    ypos += elt.offsetTop;
    elt = elt.offsetParent;
  }
  return ypos;
}


      function listener( object, type ) {
        this.o = object;
        this.t = type;

        this.contains = function( x, y ) {
           el = $( this.o );
           if( x > getAbsX(el) && x < getAbsX(el)+el.offsetWidth  &&
               y > getAbsY(el) && y < getAbsY(el)+el.offsetHeight ) return true;
        };

        this.containedBy = function( x, y ) {
           el = $( this.o );
           if( x > getAbsX(el) && x < getAbsX(el)+100  &&
               y > getAbsY(el) && y < getAbsY(el)+15 ) return true;
        };

        this.highlight = function( on, type ) {
           if( this.t == type ) { return ''; }
           el = $( this.o );
           if( on ) {
               setProperty( this.o, 'border', 'thin dotted #ff0000' );
               return 'Add ' + type + ' to ' + this.t;
           }
           else {
               setProperty( this.o, 'border', 'none' );
               return '';
           }
        };
      }


