/**
 * Default Drop Menu.
 * These functions can be used to create a (dropdown) menu from a list of items.
  * An UL element that is inside an LI-element will be shown on mouse over of the LI element,
 * the UL element is hidden on mouse out of the parent LI element.
 * Usage: Give the root of a menu the className 'dropMenu':
 * <ul className="dropMenu">
 *   <li><a>item 1</a></li>
 *   <li><a>item 2</a>
 *       <ul>
 *         <li><a>sub item 1</a></li>
 *       </ul>
 *   </li>
 * </ul>
 */

/**
 * mnuShowHide()
 * Shows/hides the childList in an LI element.
 */
function mnuShowHide(e, showHide) {
    if (! e) { var e = window.event; }
    var elem = e.target ? e.target : e.srcElement;
    var i;

    while (! pDomApi.hasClassName(elem, mnuClassName)) {

        if (elem.tagName.toLowerCase() == 'li') {

            for (i=0; i < elem.childNodes.length; i++) {
                if (elem.childNodes[i].nodeType == 1 && elem.childNodes[i].tagName.toLowerCase() == 'ul') {
                    pDomApi.setClassName(elem.childNodes[i], showHide, showHide == 'show' ? 'hide' : 'show');
                    break;
                }
            }
        }
        elem = elem.parentNode;
    }
}

if (typeof actionAtacher == 'undefined') {
    var actionAttacher = new PrezentDomApi.ActionAttacher();
    pDomApi.addEvent(window, 'domload', function() { actionAttacher.attach(); });
}

var mnuClassName = 'dropMenu';

actionAttacher.addTagEvent(new PrezentDomApi.TagEvent('ul', mnuClassName, 'mouseover', function (e) { mnuShowHide(e, 'show'); }));
actionAttacher.addTagEvent(new PrezentDomApi.TagEvent('ul', mnuClassName, 'mouseout', function (e) { mnuShowHide(e, 'hide'); }));

