function stopped_moving() {
  moving = false;
  //update_status_text();
}

function next(set) {
  move("up", null, null, set);
}

function move( dir, callback, fast, set ) {
  if( moving ) { return false; }

  moving = true;
  
  duration = ( fast ? 0.5 : 1.0 );
  if( ! callback ) { 
    cb = function() { stopped_moving(); };
  } else {
    cb = function() {
      stopped_moving();
      callback();
    };
  }
  
  // Divide by number of products showing
  // 1 is the "screen"
   switch (set){
     case 'a':
       var remainder = ( product_count_a % num_displayed );
       var groups = ( product_count_a - remainder ) / num_displayed;
       break;
     case 'b':
       var remainder = ( product_count_b % num_displayed );
       var groups = ( product_count_b - remainder ) / num_displayed;
       break;
     case 'c':
       var remainder = ( product_count_c % num_displayed );
       var groups = ( product_count_c - remainder ) / num_displayed;
       break;
     default:
       var remainder = ( product_count % num_displayed );
       var groups = ( product_count - remainder ) / num_displayed;
   } 
    
    
    if( groups >= 0) {
      groups = Math.floor( groups );
    } else {
      groups = Math.ceil( groups );
    }
  
  
  
  
  
  
  var max_screens = groups + ( remainder > 0 ? 1 : 0 );
  //if( product_count / num_displayed > 0 ) {
  //  max_screens += 1;
  //}

  var max_up = ( (max_screens - 1) * move_interval ) * -1;
  
  switch (set){
   case 'a':
      var e = $('fc_a');
      break;
   case 'b':
      var e = $('fc_b');
      break;
   case 'c':
      var e = $('fc_c');
      break;
   default:
      var e = $('fc');
  } 
  
  
  
  var current_top = parseFloat(Element.getStyle(e,'left')  || '0');
  //var indic_current_top = parseFloat(Element.getStyle('indic','top')  || '0');
  
  var move_by = ( move_interval * -1 );
  //var indic_move_by = 10;
  
  if ( dir == "down" ) { 
    move_by = move_by * -1; 
    //indic_move_by = indic_move_by * -1;
  }
      
  var new_top = current_top + move_by

  if( new_top == max_up ) {
    //loadmore();
  }



  if( new_top > 0 || new_top < max_up ) {
    //alert("Trying to move past bounds");
    if( dir == "up") {
      move_by = max_up * -1;
      //indic_move_by = move_interval;
    } else { 
      move_by = max_up;    

      // indic something
    }
  }
  
  if( dir == "top" || dir == "bottom" ) {
    if( dir == "top" ) {
      move_by = current_top * -1;
      //indic_move_by = indic_current_top * -1;
    } else {
      move_by = max_up - current_top;
      if( move_by != 0 ) {
        //loadmore();
        
      }
      //indic_move_by = move_interval - indic_current_top - 10; // 10 is indic height
    }
  }

  switch (set){
    case 'a':
      new Effect.MoveBy( 'fc_a', 0, move_by, {transition: Effect.Transitions.Linear, duration: duration, afterFinish: cb } );
      break;
    case 'b':
      new Effect.MoveBy( 'fc_b', 0, move_by, {transition: Effect.Transitions.Linear, duration: duration, afterFinish: cb } );
      break;
    case 'c':
      new Effect.MoveBy( 'fc_c', 0, move_by, {transition: Effect.Transitions.Linear, duration: duration, afterFinish: cb } );
      break;
    default:
      new Effect.MoveBy( 'fc', 0, move_by, {transition: Effect.Transitions.Linear, duration: duration, afterFinish: cb } );
  } 


  
  //new Effect.MoveBy( 'indic', indic_move_by, 0, {transition: Effect.Transitions.Linear, duration: duration  } );

}

function top(set) {
  move("top", null, null, set);
}

function bottom(set) {
  move("bottom", null, null, set);
}

function prev(set) {
  move("down", null, null, set);
}

function startmove( fast ) {
  motion_desired = true;
  keep_moving(fast);
}

function keep_moving( fast) {
  if( motion_desired ) {
    move("up", function() { keep_moving(fast) }, fast );
  }
}

function stopmove() {
  motion_desired = false;
}

/*
function reset() {
  var ctls = $('selects');
  var selects = ctls.getElementsByTagName("SELECT");
  for( var i = 0; i < selects.length; i ++ ) {
    selects[i].selectedIndex = 0;
  }
  
  refilter();
}
*/