
currentId = false;


function mopen(id)
{		
	if ( currentId != false )
		mclose();
	
	document.getElementById(id).style.visibility = 'visible';
	ie_apply_zindex(id,5)
	currentId = id;
}

function mclose()
{
	if ( currentId != false )
		document.getElementById(currentId).style.visibility = 'hidden';
		
	currentId = false;
}

function mclick(id)
{
	if ( currentId == false )
	{
		mopen(id);
	}
	else if ( currentId != id )
	{
			mclose();
			mopen(id);
	}
	else
	{
			mclose();
	} 
}


var iaz_preserved_elements = [];
var iaz_preserved_zindexes = [];

function ie_apply_zindex(element_id, zindex, context_id) {
   // default values
   if (undefined == zindex) { zindex = 1; }
   var context = (undefined == context_id ? $(context_id) : $(document.body));
   var element = $(element_id);

   // undo past ie_apply_zindex()
   for (i = iaz_preserved_elements.length-1; i >= 0; i--) {
      iaz_preserved_elements[i].setStyle({'z-index': iaz_preserved_zindexes[i]});
   }
   iaz_preserved_elements = [];
   iaz_preserved_zindexes = [];

   // find relative-positioned ancestors of element within context
   element.ancestors().each(
      function(ancestor) {
         if ('relative' == ancestor.getStyle('position')) {
            // preserve ancestor's current z-index
            iaz_preserved_elements.push(ancestor);
            iaz_preserved_zindexes.push( ancestor.getStyle('z-index') );

            // apply z-index to ancestor
            ancestor.setStyle({'z-index': zindex});
         }
         if (ancestor == context) { throw $break; }
      }
   );
}