// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// add browser name to body class
$(document).ready(function() {
  addBrowserNameToBody();  
  if ($("#search_name").length > 0) {
    $("#search_name").watermark('Search for a publication');
    $('#search_name').autocomplete('/publishers_and_publications/autocomplete', {
      headings: ["Publishers", "Publications"],
      max: 17,
      scrollHeight: 300,
      selectFirst: false,
      cacheLength: 0
    }).result(function(event, item) {
      $('#search_name').val(item[1]);
    });
  };
  if ($("a#hide_bulletin").length > 0) {
    $('a#hide_bulletin').click(function(event) {
        event.preventDefault();
        $.ajax({
            url: this.href,
            type: 'get',
            dataType: 'script',
            success: function() {
              $(".bulletin").slideUp();
            }
        });

        return false;
    });
  }
  
});

jQuery.ajaxSetup({
  'beforeSend': function(xhr) {
    xhr.setRequestHeader("Accept", "text/javascript")
  }
})

function addBrowserNameToBody() {
  var b = $.browser;
  var c;
  if(b.safari)  c = 'safari';
  if(b.mozilla) c = 'mozilla';
  if(b.msie)    c = 'msie';
  if(b.opera)   c = 'opera';
  $('body').addClass(c);
}
