Event.addBehavior.reassignAfterAjax = true;

// Unobtrusive javascript using lowpro, it's good for the Google.
// No <a href="#" onCLick="..."> nonsense should be going on.
Event.addBehavior({
  'body' : function(e) {
    //   $('info_bg').setStyle({"height": ($('info_text').getHeight() + 20 + "px")})
    // 
    $$('fieldset.hidden').invoke('hide');
    //   
    // Replace all <h1 class="title">Test</h1> with
    // <div class="title"><h1 class="title"><span>Test</span></h1></div>
    //$$('h1.title').each(
    //  function(thing) {
    //    innerspan = new Element('span').update(thing.innerHTML);
    //    newheader = new Element('h1', { 'class' : 'title' }).update(innerspan);
    //    outerdiv  = new Element('div', { 'class': 'h1_title' }).update(newheader);
    //    thing.replace(outerdiv);
    //  }
    //);
  },
  
  // Handles the in-textfield labels and hiding them automatically when
  // the user focuses on the field.
  '#login:focus' : function(e) {
    if (this.value == "E-mail") { this.value = ''; }
  },
  '#login:blur' : function(e) {
    if (this.value == "") { this.value = 'E-mail'; }
  },
  '#password_placeholder:focus' : function(e) {
    this.hide();
    $('password').show();
    $('password').focus();
  },
  '#password:blur' : function(e) {
    if (this.value == "") {
      this.hide();
      $('password_placeholder').show();
    }
  },
  
  
  'a.reveal_fieldset:click' : function(e) {
    $$('fieldset').invoke('hide');
    $(this.readAttribute('href').gsub('#','')).show();
    $$('a.reveal_fieldset.up').invoke("removeClassName", "up")
    this.addClassName("up")
    return false;
  },
  '#login_submit:mouseover' : function(e) {
    this.writeAttribute('src', '/images/common/log_in_o.png')
  },
  '#login_submit:mouseout' : function(e) {
    this.writeAttribute('src', '/images/common/log_in.png')
  },
  '#groupname:focus' : function(e) {
    if (this.value == "groupname") { this.value = ''; }
  },
  '#groupname:blur' : function(e) {
    if (this.value == "") { this.value = 'groupname'; }
  }
    
    
    
// ,
  //   
  //   '#password_placeholder2:focus' : function(e) {
  //     this.hide();
  //     $('user_password2').show();
  //     $('user_password2').focus();
  //   },
  //   '#user_password2:blur' : function(e) {
  //     if (this.value == "") {
  //       this.hide();
  //       $('password_placeholder2').show();
  //     }
  //   }
})