/**
  * Form::element()
  * get or create an element
  * 
  * @param string $key
  * @param mixed $mixedTypeIndex FALSE/ int : get element, string: create element
  * @param array $settings
  * @return Form_Element
  */
 public function element($key, $mixedTypeIndex = FALSE, $settings = array())
 {
     if ($mixedTypeIndex === FALSE) {
         /**
          *  get element
          */
         if (isset($this->_fields[$key])) {
             if ($this->_fields[$key]['group'] === TRUE) {
                 // return array(group)
                 return $this->_fields[$key]['elements'];
             } else {
                 // return first element (not group)
                 return $this->_fields[$key]['elements'][0];
             }
         } else {
             return FALSE;
         }
     } elseif (is_int($mixedTypeIndex)) {
         /**
          * get n'th element
          */
         if (isset($this->_fields[$key]) && isset($this->_fields[$key]['elements'][$mixedTypeIndex])) {
             return $this->_fields[$key]['elements'][$mixedTypeIndex];
         } else {
             return FALSE;
         }
     } else {
         /**
          *  add element
          */
         // raise event
         Event::raise($this, Event::BEFORE_FORM_ELEMENT, array('form' => $this, 'key' => $key, 'type' => $mixedTypeIndex, 'settings' => $settings));
         // create the element
         $element = new Form_Element($key, $mixedTypeIndex, $settings);
         // get field
         if (isset($this->_fields[$key])) {
             // get existing field
             $field = $this->_fields[$key];
             // check if existing elementnames should be updated
             if ($field['group'] === FALSE) {
                 $updateName = TRUE;
             } else {
                 $updateName = FALSE;
             }
             // set group property to true
             $field['group'] = TRUE;
         } else {
             // create new field
             $field = array('group' => FALSE, 'multiple' => FALSE, 'elements' => array(), 'rules' => array(), 'processors' => array(), 'default' => NULL, 'compound' => FALSE, 'keys' => array());
             $updateName = FALSE;
         }
         // check & set compound
         if (isset($settings['compound']) && $settings['compound'] == TRUE) {
             $field['compound'] = TRUE;
         }
         // check $ set compound keys
         if (isset($settings['keys'])) {
             $field['keys'] = $settings['keys'];
         }
         // check if a default was given & set default
         if (isset($settings['default'])) {
             $field['default'] = $settings['default'];
         }
         // check if the group property is explicitly set
         if (isset($settings['group']) && $settings['group'] == TRUE) {
             $field['group'] = TRUE;
         }
         // check if it is multiple
         $field['multiple'] = $element->multiple();
         // create name
         $name = $key;
         if ($field['group'] === TRUE) {
             $name .= '[]';
         }
         if ($field['multiple'] === TRUE) {
             $name .= '[]';
         }
         // set name of this element
         $element->name($name);
         // update existing elements if necesary
         if ($updateName === TRUE) {
             $this->_fields[$key]['elements'][0]->name($name);
         }
         // store element
         $field['elements'][] = $element;
         // store field
         $this->_fields[$key] = $field;
         // store element in list
         $this->_elements[] = $element;
         // raise hook
         Event::raise($this, Event::AFTER_FORM_ELEMENT, array('form' => $this, 'element' => $element));
         // return element
         return $element;
     }
 }