// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
//ajax pagination.  modified from http://wiki.github.com/mislav/will_paginate/ajax-pagination
document.observe("dom:loaded", function() {
  // the element in which we will observe all clicks and capture
  // ones originating from pagination links
  var container = $('results')

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

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

    container.observe('click', function(e) {
      var el = e.element()
      if (el.match('.pagination a')) {
        el.up('.pagination').insert(createSpinner())
        //new Ajax.Request(el.href, { method: 'post' })
        //note that the form is explicicity grabbed by name
        new Ajax.Request(el.href, { method: 'post' , asynchronous:true, evalScripts:true,  onComplete:function(request){Element.hide('glightbox')}, onLoading:function(request){Element.show('glightbox');} , parameters: $('filter_form').serialize(true) } )

        e.stop()
      }
    })
  }
})
