﻿/**********************************************************
Author:
Adam Barry
www.klestrup-partners.dk

Date: October 13 2008

© 2008 Adam Barry, all rights reserved
-----------------------------------------------------------

Name:
expandCollapse script

-----------------------------------------------------------
Description:
Function that enables drop-down navigation functionality by
the use of a standard compliant list-based navigation
structure with drop-down functionality in IE, Firefox,
Opera, Safari etc.

-----------------------------------------------------------
Usage:
Simply place a link to the this script in the head-section
of the XHTML page. The script will then automatically
execute on page load.

<script type="text/javascript" src="dropDownNav.js"></script>

Make sure that your list structure has "navigation" as
classname, according to the example below.

-----------------------------------------------------------
Example:
<script type="text/javascript" src="expandCollapse.js"></script>



-----------------------------------------------------------
Dependencies:
This script depends on the windowOnLoad-script to execute

**********************************************************/

function expandCollapse() {

    if (!document.getElementsByTagName) return;

    var anchors = document.getElementsByTagName("a");

    for (var i = 0; i < anchors.length; i++) {
        if (anchors[i].className.indexOf("toggler") > -1) {
            anchors[i].onclick = function() {
                if (this.parentNode.className.indexOf("expanded") > -1) {
                    this.parentNode.className = this.parentNode.className.replace(new RegExp("expanded\\b"), "");
                }
                else {
                    this.parentNode.className += " expanded";
                }
            }
        }
    }

}
addLoadEvent(function() { expandCollapse(); });
