// Common JavaScript code across your application goes here.
$(document).ready(function(){

  // Collapsible lists
  $(".collapsible .head").click (function(){
    $ (this).next().slideToggle('slow');
    return false
  }).next().hide().slideUp();

  // Form stuffs
  // Default value show-and-clear
  $('form.clear input[type=text], form.clear textarea').formclear({
    activecolor: '#fff'  
  });

  // Text field autogrow
  $('input[type=text]').autoGrowInput({
    comfortZone: 50,
    maxWidth: 750
  })
  
  $('textarea').growfield({
    max: 450,
    min: 35,
  });
  
  // Auto-resize text depending on quote size.
  $('div#frontpage_frame p.member_quote').dynamicFontSize({lines: 2, squeezeFactor: 0.3, tries: 5});

  // This takes care of individual delete links
  $('a.delete').click(function(e) {
    e.preventDefault();
    if( confirm( "Really delete news entry \""+ $(this).next().html() + "\"?" ) ) {
      var entry = $(this).parent().parent();
      $.ajax({
        type: 'delete',
        url: '/news_entries/' + entry.attr('id').replace(/^[a-zA-Z-_]*/,''),
        beforeSend: function() {
          entry.animate({'backgroundColor':'#fb6c6c'},600);
        },
        success: function() {
          entry.slideUp(800,function() {
            entry.remove();
          });
        },
      });
    }
  });

  $("input#page_name").autocomplete({ serviceUrl: '/wiki/getpaths' }).enable;
});
