// $Id: rotor.js,v 1.1 2008/04/01 18:14:43 nestormata Exp $
var rotor_items = new Array();
var actual_item = 0;
var rotor_interval = null;
var first_display = true;
$(document).ready(
  function() {
    // Checks that the rotor enabled variable has being set to true
    // this must be done also by setting the rotor_time variable and the
    // rotor div. This is done by the drupal module.
    if (typeof rotor_enabled != 'undefined' && rotor_enabled) {
      //animate_rotor_item();
      animate_rotor();
    }
  }
);

function animate_rotor_item(rotor_item) {
  if(typeof rotor_item == "undefined" || typeof rotor_item == "number"){
  	rotor_item = $('.rotor_content').get(actual_item);
  }
  $('#rotor > .rotor_content > .rotor_content').hide();
  $('.rotor_content', rotor_item).fadeIn(1000);

  var contents = $('.rotor_content');
  var actual = contents.get(actual_item);
  actual_item = (actual_item + 2) % contents.length;

}

function animate_rotor() {
  var contents = $('.rotor_content');
  //if more than 1 banner, animate (number is set to 2 because each banner requires 2 DIVs)
  if (contents.length > 2) {
    if (!rotor_interval) {
      while (first_display) {
        animate_rotor_item();
        first_display = false;
      }
      rotor_interval = setInterval(animate_rotor_item, rotor_time * 1000);
    }
  }
}
