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

jQuery.noConflict();

jQuery(document).ready(function(){
  jQuery('.toggle_event_info').click(function(){
    var parent_id = jQuery(this).parent().attr('id');
    var selector = '#' + parent_id + ' .focus';
    jQuery(this).parent().siblings().children('.extended').slideUp(300);
    jQuery(this).parent().children('.extended').slideToggle(300, function(){
      jQuery(selector).focus();
    });
  });
  
  jQuery('#upload_form').bind("submit", toggle_spinner);
});

function round_to_nearest(round_qty, minutes)
{
  var rounded_mins = 0;
  if (minutes == 0) {
    return 0;
  } else {
    rounded_mins = Math.round((minutes / round_qty)) * round_qty;
    return (rounded_mins == 60 ? 45 : rounded_mins);
  }
}

function toggle_spinner(hide_result)
{
  if (hide_result) {
    jQuery('#upload_result').hide();
  }
  
  jQuery('#submit').toggle();
  jQuery('#spinner').toggle();
}

function toggle_upload_result(text)
{
  jQuery('#upload_result').html(text).toggle();
}