var fold_away_orgs;
var current_feature_frame = 1;
var num_feature_frames;
var auto_rotate_feature_frame;

function feature_scroll(frame_number){
 clearTimeout(auto_rotate_feature_frame);
 current_feature_frame = frame_number;
 var counter = 1;
 $("#features .feature").each(function(i){
   $(this).animate( { marginLeft: (-980 * (frame_number - (counter++))) + 'px' }, { queue:false, duration: 500 } );
 });
 auto_rotate_feature_frame = setTimeout("feature_scroll(" + ((current_feature_frame % num_feature_frames) + 1) + ")", 25000);
 return false;
}

$(document).ready(function(){
  $(".feature_scroll_link").show();
  $("#feature_bar").show();
  num_feature_frames = $("#features .feature").length;
  auto_rotate_feature_frame = setTimeout("feature_scroll(" + ((current_feature_frame % num_feature_frames) + 1) + ")", 25000);
  
  $("a.org").hover(function(){
    $("a.org").animate( { width: '0px' }, { queue: false, duration: 200 } );
    $(this).animate( { width: '300px' }, { queue: false, duration: 200 } );
    clearTimeout(fold_away_orgs);
  }, function(){
    clearTimeout(fold_away_orgs);
    fold_away_orgs = setTimeout(function(){
      $("a.org").animate( { width: '0px' }, { queue: false, duration: 200 } );
    }, 5000);
  });
  
  $('#contact_section #subject').change(function(){
    var result_text = '';
    if ($(this).val() == 'forgotten_password') result_text = '<strong>Please note:</strong> <em>Three Rings</em> staff will not help you with forgotten usernames/passwords unless there is nobody at your organisation who can do so. Please contact the support people at your organisation <em>first</em>.';
    $('#subject_extra_info').html(result_text);
  }).change();

  $('.features_links a.ui-state-default').hover(
    function() { $(this).addClass('ui-state-hover'); }, 
    function() { $(this).removeClass('ui-state-hover'); }
  );
});
