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

var $j = jQuery.noConflict();

jQuery(document).ready(function($){


  

  $(".toggler").click(function(){
    $("#" + $(this).attr("rel")).toggle();
    return false;
  });
  
  $(".toggler").each(function(){
    $("#" + $(this).attr("rel")).hide();
  });
  
  //scroll the message box to the top offset of browser's scroll bar
  $(window).scroll(function()
  {
    $('#cart').animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 350});
  });
  
  
  // AJAX Forms
  // need livequery here so that ajax forms loaded up in 
  // facebox can still use the "xhr" class
  $("form.xhr").livequery(function(){
    $(this).jaxy();
  });
  

  // turn links into video and sound players
  // $("a.video").media({ width: 280, height: 210 });
  //   $("a.sound").media({ width: 280, height: 20 });

  // helper functions for Ajaxifying standard links and forms, and evaluating returned Javascript
    $("a.xhr").live("click", function() {
      $.ajax({
          url: this.href,
          dataType: "script"
      });
      return false;
    });
    
    // AJAX Forms
    // $("form.rjs").ajaxForm({
    //   dataType: 'script',
    //   resetForm: true
    // });
    
    // delete links using button_to
    // PROBLEM - AJAX created items will not be deletable via this method
    // may need livequery or listen plugin
    // $('input[name=_method][value=delete]')
    // .siblings('[class=rjs]')
    // .parents('form.button-to')
    // .ajaxForm({
    //     dataType: 'script'
    // })
    

  
});

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

jQuery(document).ajaxSend(function(event, request, settings) {
  if (typeof(AUTH_TOKEN) == "undefined") return;
  // settings.data is a serialized string like "foo=bar&baz=boink" (or null)
  settings.data = settings.data || "";
  settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
});