// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
document.observe('dom:loaded', function() {
  setTimeout(hideFlashes, 25000);
  var container = $(document.body)
  $('loading').hide(); //hide the loading box

//This is used to tell, everytime an AJAX function is created and completed, the following will get executed.
Ajax.Responders.register({
onCreate: function() {
new Effect.Opacity('page', { from: 1.0, to: 0.3, duration: 0.7 });
new	Effect.toggle('loading', 'appear');

},
onComplete: function() {
new Effect.Opacity('page', { from: 0.3, to: 1, duration: 0.7 });
new	Effect.toggle('loading', 'appear');
}
});

  if (container) {
    var img = new Image
    img.src = '/images/ajax-loader.gif'

    function createSpinner() {
      return new Element('img', { src: img.src, 'class': 'spinner' })
    }

    container.observe('click', function(e) {
      var el = e.element()
      if (el.match('.pagination.ajax a')) {
        el.up('.pagination.ajax').insert(createSpinner())

        new Ajax.Request(el.href, { method: 'get' })
        e.stop()
      }
    })
  }
});

var hideFlashes = function() {
  $$('.notice', '.warning', '.error').each(function(e) {
    if (e) Effect.Fade(e, { duration: 1.5 });
  })
}

