/*
 * accordians
 */



/*
 *  Type 1:
 *  DefinitionList type accordian , used in FAQ and others
 *  acDL_functionName 
 */
 
  /*       
   *    Include the following in the header of the file implementing the accordian and replace the parameters with the relevant values.    
         
           document.observe("dom:loaded", function() {
                            acDL_attachEventListnersToTitles('accordian_container', 'accordian_header', accordianContentClass);
                            acDL_closeAll('accordian_container','accordian_header','accordian_content');
                            //acDL_FirstTimeKeepOpen('headerID','contentID'); //this opens up the ids specified
                            acDL_openFirst(accordianID, accordianTitleClass, accordianContentClass); //this opens the first item
            
            });
            
   * 
   */
   
 
 
            //open all the accordian_content elements / show them
            //open all the contents and change the title status
            function acDL_openAll(accordianID, accordianTitleClass, accordianContentClass){
                      var nodes = $(accordianID).getElementsByClassName(accordianContentClass)
                        $A(nodes).each(function(cnode){
                                    // add the 'visible' class to the contentBox
                                    if(!cnode.hasClassName('visible')){ cnode.addClassName('visible'); }
                                    //show the contentBox
                                    cnode.show();
                                        //add the open title class from the accordian headings
                                        var nodes = $(accordianID).getElementsByClassName(accordianTitleClass)
                                        $A(nodes).each(function(hnode){
                                                 if(!hnode.hasClassName('opened')){ hnode.addClassName('opened'); }
                                        });
                        });
            }
        
        
            //close all the contents and change the title status
            function acDL_closeAll(accordianID, accordianTitleClass,accordianContentClass){
                        //hide all the contents
                      var nodes = $(accordianID).getElementsByClassName(accordianContentClass)
                        $A(nodes).each(function(cnode){
                                    if(cnode.hasClassName('visible')){ cnode.removeClassName('visible'); }
                                    cnode.hide();
                                    
                        });
             
                        //remove the open title class from the accordian headings
                         var nodes = $(accordianID).getElementsByClassName(accordianTitleClass)
                                        $A(nodes).each(function(hnode){
                                             if(hnode.hasClassName('opened')){ hnode.removeClassName('opened'); }
                        });
            }
        
        
        
        
         
         //attach event listners to the accordian titles
         function acDL_attachEventListnersToTitles(accordianID, accordianTitleClass,accordianContentClass){
                //get all the title event listners
                var nodes = $(accordianID).getElementsByClassName(accordianTitleClass)
                $A(nodes).each(function(hnode){
                                    hnode.observe('click', acDL_accordianTitleEventListner.bindAsEventListener(this, accordianContentClass));
                        });
         }   
            

            //eventlistner for the accordian titles
            function acDL_accordianTitleEventListner(evnt,accordianContentClass){
                 
                   el = Event.element(evnt);     //this gets the class name of the object on which this event occoured
                  
                   el.toggleClassName('opened');
                  
                  if(el.hasClassName('opened')){
                          if(el.next('.'+accordianContentClass,0).hasClassName(accordianContentClass)){
                                el.next('.'+accordianContentClass,0).addClassName('visible').show();;
                          }else{
                             //   el.next('.accordian_content',0).addClassName('hidden').hide();;
                          }
                  }else{
                          if(el.next('.'+accordianContentClass,0).hasClassName(accordianContentClass)){
                                el.next('.'+accordianContentClass,0).removeClassName('visible').hide();
                          }else{
                                //el.next('.accordian_content',0).addClassName('hidden').hide();
                          }
                  }
                 
            }


            //set the style of all the accordian_contents to hidden
          function acDL_hideAll_acClass(accordianID, accordianContentClass){
                      var nodes = $(accordianID).getElementsByClassName(accordianContentClass)
                        $A(nodes).each(function(c){
                                                   c.hide();
                        });
              }


            // use this function to open any ID(title and content) to open up when the page loads
            function acDL_FirstTimeKeepOpen(titleID, contentID){
                    $(titleID).show();
                            if(! ($(titleID).hasClassName('opened'))){ $(titleID).addClassName('opened'); }
                    $(contentID).show();
                            if(! ($(contentID).hasClassName('visible'))){ $(contentID).addClassName('visible'); }
            }


                //this opens the first item-pair of the accordian
               function acDL_openFirst(accordianID, accordianTitleClass, accordianContentClass){
                        
                      var firstNode = $(accordianID).getElementsByClassName(accordianContentClass).first();
                        
                        if (firstNode) {
                                if (!firstNode.hasClassName('visible')) {
                                    firstNode.addClassName('visible');
                                }
                                //show the contentBox
                                firstNode.show();
                        }
                            
                       var firstNode = $(accordianID).getElementsByClassName(accordianTitleClass).first()
                        
                        if (firstNode) {
                            //open the title
                            if (!firstNode.hasClassName('opened')) {
                                firstNode.addClassName('opened');
                            }
                        }  
                }
 

/*
 * acDL - ends
 */


