function Accordion() {

    this.beMutualProperty = false;

    this.setLinkEvt = function(idcnt, eltitle) {
        var self = this;
        var titles = $id(idcnt).getElementsByTagName(eltitle);
        for (var i=0; i<titles.length; i++) {
            
            var link = titles[i].getElementsByTagName('a')[0];
            
            oldonclick = link.onclick || undefined;
            link.onclick = function(oldonclick) {
                return function() {
                    if (oldonclick) oldonclick();
                    
                    if (self.beMutualProperty) {
                        self.closeAllPanels();
                    }
                    
                    this.className = (this.className == 'close')? 'open' : 'close';                
                    var container = this.href.replace(/^[^#]+#/, '');
                    switch(this.className) {
                        case 'open' : $id(container).className = 'cntopen'; break;
                        case 'close' : $id(container).className = 'cntclose'; break;
                    }
                    return false;
                }
            }(oldonclick);
            
            link = null; // Leak Memory IE (Circular reference)
            
        }
    }
    
    
    this.closeAllPanels = function() {
        els = this.cnt.getElementsByTagName('*');
        for (i=0; i<els.length; i++) {
            if (/^open$/.test(els[i].className)) { els[i].className = ''; }
            if (/^cntopen$/.test(els[i].className)) { els[i].className = 'cntclose'; }
        }
    }
    
    this.revealContents = function(idcnt, eltitle, openitem) {
        var contents = $id(idcnt).getElementsByTagName('div');
        var titles = $id(idcnt).getElementsByTagName(eltitle);
        var j = 0;
        
       
        for (var i=0; i<contents.length; i++) {
            if (contents[i].id) {
                
                var link = titles[j++].getElementsByTagName('a')[0];
                if (typeof(openitem) != 'object') {
                    contents[i].className = (openitem != j)? 'cntclose' : 'cntopen' ;
                    link.className = (openitem != j)? 'close' : 'open';
                }
                else {        
                    contents[i].className = (j in openitem)? 'cntopen' : 'cntclose'  ;
                    link.className = (j in openitem)? 'open' : 'close' ;
                }
                
            }
        }
    }
    
    this.beMutual = function(b) {
        this.beMutualProperty = b;    
    }
    
    this.getHash = function() {
        var hash = location.hash.replace('#', '');
        if ($id(hash)) {
            $id(hash).className = 'cntopen';
            $id(hash).parentNode.getElementsByTagName('a')[0].className = 'open';
        }
    }

    this.init = function(idcnt, eltitle, openitem) {
        op = openitem || 0;
        if ($id(idcnt)) {
            this.cnt = $id(idcnt);
            this.revealContents(idcnt, eltitle, op);
            this.setLinkEvt(idcnt, eltitle);
            this.getHash(idcnt);
        }
    }
}

var _h_Accordion = Accordion;