// $Id: rotor.js,v 1.1.2.2 2008/04/29 22:53:59 nestormata Exp $ 
var rotor_items = new Array();
var actual_item = 0;
var rotor_interval = null;
var rotor_init = false;
$(window).load(
  function() {init_rotor();}
);

if(window.onload) {
    window.onload = init_rotor;
}

function init_rotor() {
    // This check is for the hack for ie6. In some cases the jquery $(window).load
    // give some issues then we set the onload function and make sure we don't
    // call init_rotor more than once. 
    if(rotor_init){
        return true;
    }
    rotor_init = true;
    
    // 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) {
        //debugger;
      $('.rotor_content > .rotor_tab').click(function() {
        //clearInterval(rotor_interval);
        //rotor_interval = null;
        animate_rotor_item($(this).parent());
      });
      animate_rotor_item();
      wait_next_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_detail').hide();
  $('#rotor > .rotor_content > .rotor_tab').removeClass('selected');
  $('.rotor_content_detail', rotor_item).show();
  $('.rotor_tab', rotor_item).addClass('selected');
  var contents = $('.rotor_content');
  var actual = contents.get(actual_item);
  actual_item = (actual_item + 1) % contents.length;
}

function wait_next_rotor() {
  var contents = $('.rotor_content');
  if(contents.length > 0) {
    if (!rotor_interval) {
        rotor_interval = setInterval(animate_rotor_item, rotor_time * 1000);
    }
  }
}
