
    // <![CDATA[
    menuItems = new Object();
    
    showTimeout = null;
    hideTimeout = null;
    requestShowDiv = null;
    currentShowingDiv = null;
    
    alwaysOpenDiv = null; // Can be set by the user clicking on one of the buttons
    
    bSelectBoxOpened = false; // To get around an IE bug where opening a select dropdown will take the focus off the HTML div

    function getSlideoutDiv(num) { return "media_slideout_" + num; }
    function getImageDiv(num) { return "menu_image_" + num; }
    function getHighlightUrl(num) { return "/images/flyV2/" + num + "-on.gif"; }
    function getImageUrl(num) { return "/images/flyV2/" + num + "-off.gif"; }

	// findPos functions from http://www.quirksmode.org/js/findpos.html
	function findPosX(obj)
	{
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}
	
	function findPosY(obj)
	{
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}

    function showMediaSlideout(div_num)
    {
	  // In this case, we want to close the div, but the select box is open in the div and so we shouldn't close it yet.
	  // Give it a little more life...
	  if ((div_num == null) && bSelectBoxOpened) {
	  	hideTimeout = setTimeout("showMediaSlideout(null)", 1000);
	  	return;
	  }

    
      for (div in menuItems) {
        if (menuItems[div] && ((div != div_num) || (div_num == null))) {
          Element.hide(getSlideoutDiv(div));
          menuItems[div] = false;
          $(getImageDiv(div)).src = getImageUrl(div);
        }
      }
      
      if (div_num != null) {
        $(getImageDiv(div_num)).src = getHighlightUrl(div_num); // , transition:Effect.Transitions.linear
        $(getSlideoutDiv(div_num)).style.left = (findPosX($(getImageDiv(div_num))) + 200) + "px";
        $(getSlideoutDiv(div_num)).style.top  = findPosY($("mcHeader")) + "px"; // findPosY($(getImageDiv(div_num))) + "px";
        // This effect only seems to look good in IE
        if (document.all) {
	        Effect.SlideDown(getSlideoutDiv(div_num), {scaleX:true, scaleY:false, scaleContent:true, from:0.65, duration:0.2, fps:100});
        }
        else {
        	Element.show(getSlideoutDiv(div_num));
        }
        menuItems[div_num] = true;
      }

      currentShowingDiv = div_num;
      
      if (div_num) showTimeout = null; // We just showed something, so the showTimeout is reset
      else hideTimeout = null; // We just hid everything, so reset the hideTimeout

	  bSelectBoxOpened = false; // A new div came up, or no divs came up, so reset this flag for whether a select box was triggered
    }
    
    
    function requestDivShow(divNum)
    {
      var timeout = 400;
      // If the div's already open...
      if (currentShowingDiv == divNum) {
        // Kill any potentially competing timeouts that might open other things (in case you just
        // touched over something else and came back to the proper div in the grace period.
        if (showTimeout) {
          clearTimeout(showTimeout);
          showTimeout = null;
        }
        if (hideTimeout) {
          clearTimeout(hideTimeout);
          hideTimeout = null;
        }
        return;
      }
      
      // If we have an alwaysOpenDiv directive and it's not the present div, then we kill any request to open another div
      if (alwaysOpenDiv && (alwaysOpenDiv != divNum)) {
      	return;
      }
      
      // If we have a hide pending, just kill it.  Showing this div will hide others anyway.
      if (hideTimeout) {
        clearTimeout(hideTimeout);
        hideTimeout = null;
      }
      if (showTimeout) // If we're already queued to show something else...
        clearTimeout(showTimeout); // ...we kill the former request   
      
      requestShowDiv = divNum;
      
      if (currentShowingDiv == null)
        timeout = 0; // might as well do it immediately if nothing else is showing.
        
      showTimeout = setTimeout("showMediaSlideout(" + requestShowDiv + ")", timeout);
    }
    
    function requestDivHide(divNum)
    {
      var timeout = 1000;

      // If we have an alwaysOpenDiv directive this div should not be made hidden
      if (alwaysOpenDiv && (alwaysOpenDiv == divNum)) {
      	return;
      }

    
      // No point in trying to hide a div that's hidden.  We don't reset the other vars though,
      // cause there might be a pending request to hide something that is showing
      if (divNum != currentShowingDiv) {
        return;
      }
    
      // If there was a previous hide, kill it, there was some extension on our life cause we got called again
      if (hideTimeout) {
        clearTimeout(hideTimeout);
        hideTimeout = null;
      }

      // Whenever a div is shown, all the others are hidden automatically anyway.  So if there's a
      // showTimeout that's active, we should kill our hideTimeout (done above anyway) and return.
      if (showTimeout) {
        return;
      }
      
      // Finally, we do our hide command
      hideTimeout = setTimeout("showMediaSlideout(null)", timeout);
    }
    
    function clickDiv(divNum) 
    {
    //	if (alwaysOpenDiv == divNum) {
    //		alwaysOpenDiv == null;
    //		hideAllSlideouts();
    //	}
    //	else {
    		alwaysOpenDiv = divNum; // if they want to close the div again, they have to use the [x]
    		requestDivShow(divNum);	
    //	}
    }
    
    function setSelected(el) {
	    bSelectBoxOpened = true;
//	    alert("set");
    }
    
    function unsetSelected(el) {
    	bSelectBoxOpened = false;
//    	alert("unset");
    }
    
    function hideAllSlideouts() {
	    showMediaSlideout(null);
	    alwaysOpenDiv = null;	
    }

  // ]]>