var msgs = {
  toggleLabelEdit: function(id) {
    Element.toggle('controls_for_' + id, 'label_for_' + id)
  },

  beforeRemoveAttachment: function(id) {
    Element.show('spin_' + id)
  },

  afterRemoveAttachment: function(id) {
    new Effect.Fade('attachment_' + id,
      {duration: 0.5,
       afterFinish: function() { Element.remove('attachment_' + id) }})
  },

  relabelAttachment: function(id, url) {
    Element.show('label_' + id)
    new Ajax.Updater('attachment_' + id, url,
      {asynchronous:true, parameters:'label=' + $('new_label_for_' + id).value,
       onComplete:function(request) {
         new Effect.Highlight('attachment_' + id)
       }})
  },

  attacher: {
    toggle: function(filefield) {
      this.visible(filefield) ? this.hide(true, filefield) : this.show(true, filefield)
    },

    show: function(animate, filefield) {
      visible = this.visible(filefield)


      animate ?
        new Effect.BlindDown(filefield+'Attachments', {duration: 0.2}) :
        Element.show(filefield+'Attachments')

      Element.hide(filefield+'Attachments_link')

      return visible
    },

    hide: function(animate, filefield) {
      visible = this.visible(filefield)
      
      animate ?
        new Effect.BlindUp(filefield+'Attachments', {duration: 0.2}) :
        Element.hide(filefield+'Attachments')

      Element.show(filefield+'Attachments_link')

      return visible
    },

    visible: function(filefield) {
      return $(filefield+'Attachments').style.display != "none"
    }

  },

  milestoner: {
    toggle: function() {
      this.visible() ? this.hide(true) : this.show(true)
    },

    show: function(animate) {
      visible = this.visible()

      animate ?
        new Effect.BlindDown('RelatedMilestone', {duration: 0.2}) :
        Element.show('RelatedMilestone')

      Element.hide('RelatedMilestone_link')

      return visible
    },

    hide: function(animate) {
      visible = this.visible()
      
      animate ?
        new Effect.BlindUp('RelatedMilestone', {duration: 0.2}) :
        Element.hide('RelatedMilestone')

      Element.show('RelatedMilestone_link')

      return visible
    },

    visible: function() {
      return $('RelatedMilestone').style.display != "none"
    },
    
    associate: function() {
      var list = $('post_milestone_id')
      if(list.selectedIndex == 0) {
        // "none"
        Element.hide('with_milestone')
        Element.show('without_milestone')
      } else {
        // a valid milestone
        Element.hide('without_milestone')
        $('milestone_name').innerHTML = list.options[list.selectedIndex].innerHTML
        Element.show('with_milestone')
        if($('completes_milestone').checked)
          Element.show('completes_milestone_check')
        else
          Element.hide('completes_milestone_check')
      }
      this.hide(true)
    }
  },
  
  notifier: {
    toggle: function() {
      this.visible() ? this.hide() : this.show()
    },

    visible: function() {
      return Element.visible('NotifyBlock')
    },

    show: function() {
      visible = this.visible()

      new Effect.BlindDown('NotifyBlock', {duration: 0.2})
      Element.hide('Notify_link')
      $('notify_everyone').checked = false

      return visible
    },

    hide: function() {
      visible = this.visible()
      
      new Effect.BlindUp('NotifyBlock', {duration: 0.2})
      Element.show('Notify_link')

      return visible
    },
    
    all: function() {
      if($('notify_everyone').checked) this.hide()
    }
  },
  
  formatGuide: {
    toggle: function() {
      this.visible() ? this.hide() : this.show()
    },

    visible: function() {
      return Element.visible('formatting_guide')
    },

    show: function() {
      visible = this.visible()

      new Effect.BlindDown('formatting_guide', {duration: 0.2})
      Element.activate('formatting_guide_link', true)

      return visible
    },

    hide: function() {
      visible = this.visible()
      
      new Effect.BlindUp('formatting_guide', {duration: 0.2})
      Element.activate('formatting_guide_link', false)

      return visible
    }
  }
}
