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;
}

function update_subject_extra_info(value) {
 var result_text = '';
 if (value == 'feedback') result_text = 'hello';
 $('#subject_extra_info span').text(result_text);
}

$(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_page #subject').change(function(){
  update_subject_extra_info($(this).get(0).value);
  });

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