/*
 * Copyright (c) 2006 A&B FACE2NET GmbH
 *
 * author JDE
 * version $Revision: 1.6 $
 */

var Modulbox = Class.create();

Modulbox.prototype = {

  initialize: function() {


    if (!document.getElementsByTagName) { return false; }

  var anchors = document.getElementsByTagName('a');
  var k=0;
  moduleanchorlist = [];
  otheranchorlist = [];

  for (var i=0; i<anchors.length; i++) {
    var myanchor = anchors[i];
    var relAttribute = String(myanchor.getAttribute('rel'));

    if (myanchor.getAttribute('href') && (relAttribute.toLowerCase().match('module'))) {

        moduleanchorlist[k] = anchors[i];
    k++;
      myanchor.onclick = function () {
        myModulbox.toggleCurrent(this);
          return false;
    }
    }
    }
  },


    toggleCurrent: function(moduleLink) {

    if (!document.getElementsByTagName) { return false; }
    if(moduleLink.getAttribute('rel') == 'module') {
    var currentLink = moduleLink.getAttribute('id');
    if(currentLink){
      var currentModuleID = 'detail'.concat(currentLink);
      var currentModule = document.getElementById(currentModuleID);
      if(currentModule.className =='hidden' || currentModule.getAttribute('class')=='hidden'){
       currentModule.style.display = "none";
       myModulbox.hideAll(moduleanchorlist);
       }
      new Effect.toggle(currentModuleID, 'slide', {duration:0.4} );
      Element.addClassName(currentModule, 'current');
      Element.addClassName(currentLink, 'active');
      Element.removeClassName(currentModule, 'hidden');
      //alert(currentModule.style.height);
    }
     }
  },

  hideAll: function(anchorList){
    for (var i=0; i<anchorList.length; i++) {
      var moduleLink = anchorList[i].getAttribute('id');
    var testactive = anchorList[i].getAttribute('class');
    if(moduleLink){
        var moduleID = 'detail'.concat(moduleLink);
        var module = document.getElementById(moduleID);
        if(module.getAttribute('class')=='current' || module.className =='current' ) {
        new Effect.toggle(moduleID, 'blind');
        Element.addClassName(module, 'hidden');
        Element.removeClassName(module, 'current');
        Element.removeClassName(moduleLink, 'active');
        //alert(moduleID);
        }
      }


     }

  }
}

function initModulbox() { myModulbox = new Modulbox(); }
Event.observe(window, 'load', initModulbox, false);
