function sign_up_behaviors () {
  // set the tabindexes on the form values
  $('input#user_first_name').attr('tabindex', 1)
  $('input#user_last_name').attr('tabindex', 2)
  $('input#user_login').attr('tabindex', 3)
  $('input#user_email').attr('tabindex', 4)
  $('input#user_password').attr('tabindex', 5)
  $('input#user_password_confirmation').attr('tabindex', 6)
  
  // enable the sign up button when you agree to the terms
  $('input#accept-terms').click(function() {
    $('input#sign-up').attr('disabled',!this.checked);
  });
  
  // process the sign up
  $('input#sign-up').click(function() {
    $(this).attr('disabled',true);
    $(this).val("Processing your sign up...");
    $('#sign-up-form').submit();
  });
  
}

function option_bar_behaviors () {
  if (!browser_is_ie_six()){
    // hide all record options
    $('div.record-options').attr('style', 'display:none') 
    
    $('.records-list-items').option_bar()
    $('.records-options').revealer()
    
    // reactivate once we can get this working in IE
    // $('a.rjs').add_rjs()
  }
}

/* == apply rjs juice to anchors == */ 
// FIXME : this doesn't work in IE at all'
// $.fn.add_rjs = function() {
//   $(this).click( function() {
//       $.ajax({
//           url: this.href,
//           dataType: "script",
//       });
//       return false; # this is the line that is breaking it...
//   });
// }

/* == behaviors for the option bar == */ 
$.fn.option_bar = function() {
  $(this).hover(function() {
    elem = "div#" + $(this).attr('rel')
    $(elem).attr('style', 'display:block')
  }, function() {
    elem = "div#" + $(this).attr('rel')
    $(elem).attr('style', 'display:none')
  });
}

/* == reveals the option_bar on hover == */
$.fn.revealer = function() {
  $(this).hover(function() {
    $(this).attr('style', 'display:block')
  }, function() {
    $(this).attr('style', 'display:none')
  });
}

// general page behaviors
function page_behaviors () {
  
  // for elements that need sliding
  $('a.slide_toggler').click(function() { 
    $(id_from_anchor(this)).slideToggle(100); 
  });
  
  // for elements that need closing
  $('a.slide_close').click(function() { $(id_from_anchor(this)).slideUp(100) });
  // for elements that need opening
  $('a.slide_down').click(function() { $(id_from_anchor(this)).slideDown(100) });
  
  $('a.toggler').click(function() {
    $(id_from_anchor(this)).show('fast')
    $(id_from_rel(this)).hide('fast')
  });
  
}

// retrieves the element id from an href attribute
function id_from_anchor (elem) { return $(elem).attr('href'); }
function id_from_rel (elem) { return $(elem).attr('rel'); }

function set_facebox () {
  $('a[rel*=facebox]').facebox();
}

function respond_to_fix () {
  // fixes the respond_to bug for use with rails rjs stuff
	jQuery.ajaxSetup({ 
	  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept",
	    "text/javascript")} 
	})
}

// why ie6 why? 
// get your forks because dinner is served
function browser_is_ie_six () { return $('html').attr('class').match(/ie6/) == "ie6"; }

$(document).ready(function() {
  respond_to_fix();
  set_facebox();
  sign_up_behaviors();
  option_bar_behaviors();
  page_behaviors();
});

