// $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;
$(window).load(
  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) {
		//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').hide();
  $('#rotor > .rotor_content > .rotor_tab').removeClass('selected');
  $('.rotor_content', 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);
	}
  }
}
