// add behaviors once DOM has loaded
$(document).ready(function() {
  $('form:first *:input:text[type!=hidden]:first').focus()
  
  setTimeout("$('p.notice, p.warning, p.error').fadeOut(1500)", 20000);
	
	$('a.course-details').handleToggle()
	$('table.totalize td input.text').tally()
	$('#round_course_id').loadScorecard()
  
	// handle the welcome tab radio buttons
	$('ul#welcome_tab_settings input.radio').click(function() {		
		// remove the check completely
		$('ul#welcome_tab_settings li').each(function(e) {
			$(this).removeClass('checked');
		});		
		// add the check to the chosen option
		$(this).parent('li').addClass('checked');
	})
	
	$('a[rel=external]').click(function(e) {
	  e.preventDefault()
    window.open($(this).attr('href'))
  })
  
  $('a[rel*=facebox]').facebox()
  
  $('input[type=submit]').click(function() {
    $(this).val('Working...')
  })
  
  $.ajaxSetup({ 
    'beforeSend': function(xhr) {
      xhr.setRequestHeader("Accept", "text/javascript")
      $('#loading').show()
    },
    'complete': function(xhr) {
      $('#loading').hide()
    } 
  })
});