// $Id: rotor.js,v 1.1.2.3 2008/11/22 13:06:12 mrfelton Exp $ 

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;
    
	  // set speed to an appropriate value
	  rotor_speed == 0? rotor_speed = 1 : rotor_speed = rotor_speed * 1000;

    // 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_items();
    }   
};

function animate_rotor_items(){
	// redefine Cycle's updateActivePagerLink function 
	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex){
		$(pager).find('.rotor-tab').removeClass('selected')
		.filter('.rotor-tab:eq(' + currSlideIndex + ')').addClass('selected');
	};
	
	$('.rotor-items').cycle({
		timeout: rotor_time * 1000,
		speed: rotor_speed,
		fx: rotor_effect,
		pause: rotor_pause,
		pager: '.rotor-tabs',
		pagerAnchorBuilder: function(idx, slide){
			return '.rotor-tabs .rotor-tab:eq(' + idx + ')'; 
		}
	});
};
