// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
Event.addBehavior({
  '#formatting_guide_link:click' : function(e){
    Effect.toggle("format_guide", "appear", { duration: 0.5 });
    return false;
  },
  '#sidebar_link:click' : function(e){
    if ($(this).up("div").hasClassName("with_sidebar_content")){
      if (!$("page_sidebar_content").present() || confirm("Are you sure you want to delete the sidebar?")){
        $(this).up("div").removeClassName("with_sidebar_content");
        $(this).update("[Use sidebar]");
        $("page_sidebar_content").clear();
      }
    } else {
      $(this).up("div").addClassName("with_sidebar_content");
      $(this).update("[Delete sidebar]");
    }
    return false;
  },
  '#format_guide #close:click' : function(e){
    Effect.toggle("format_guide", "appear", { duration: 0.5 });
    return false;
  },
  '#page_in_menu:change' : function(e){
    Effect.toggle($('menu_options'), 'appear',{ duration: 0.5 });
  },
  '.close:click' : function(e){
    $(this).up('.popup').fade({ duration: 0.5 });
    return false;
  },
  '.open:click' : function(e){
    Effect.toggle($(this).next('.popup'),'appear',{ duration: 0.5 });
    $$('.panel .popup').without($(this).next('.popup')).invoke('fade',{ duration: 0.5 });
    return false;
  },
  '#more_attachments:click' : function(e){
    $('other_attachments').appear({ duration: 0.5 });
    $('more_attachments').hide();
    return false;
  },
  '.new_comment:submit' : function(e){
    e.stop();
    var form = e.element();
    
    new Ajax.Request(form.action,{
      method: "post",
      parameters: form.serialize(),
      evalJS: true
    })
    return false;
  }
})

Event.onReady(function(){
  if($('page_in_menu') && !$('page_in_menu').checked)
  {
    $('menu_options').hide();
  } 
})

function mark_for_destroy(element) {
  $(element).next('.should_destroy').value = 1;
  $(element).up('.image').hide();
}
