var speed = 5000;
var intervalID;

function theRotator(id, time) {
  speed = time;
	//Set the opacity of all images to 0
	jQuery('div#'+id+' ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	jQuery('div#'+id+' ul li:first').css({opacity: 1.0});
	
	rotation(id);
}

function rotation(id){
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	intervalID = setInterval('rotate("'+id+'")',speed);
}

function stopRotation(){
	clearInterval(intervalID);
	intervalID = 0;
}

function rotate(id) {
	//Get the first image
	var current = (jQuery('div#'+id+' ul li.show')?  jQuery('div#'+id+' ul li.show') : jQuery('div#'+id+' ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().is('.show')) ? jQuery('div#'+id+' ul li:first') :current.next()) : jQuery('div#'+id+' ul li:first'));
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');

  //nextNumber();
	
}

function nextNumber(){
	//Get the first number
	var current = (jQuery('div.rotator_numbers a.active')?  jQuery('div.rotator_numbers a.active') : jQuery('div.rotator_numbers a:first'));

	//Get next number, when it reaches the end, rotate it back to the first number
	var next = ((current.next().length) ? ((current.next().is('.active')) ? jQuery('div.rotator_numbers a:first') :current.next()) : jQuery('div.rotator_numbers a:first'));

	//give the next number class active
	next.addClass('active');

	//take away class active
	current.removeClass('active');
}

jQuery(document).ready(function() {
/*
	jQuery(".rotator_numbers a").click( function(){
      if(intervalID != 0){
        stopRotation();
        start = 1;
      }else{
        start = 0;
      }
      var content = jQuery(this).html();
      var slide = parseInt(content);
      slide -= 1;
      //Get the first image
      var current = (jQuery('div#rotator ul li.show')?  jQuery('div#rotator ul li.show') : jQuery('div#rotator ul li:first'));

      //Get next image, when it reaches the end, rotate it back to the first image
      if(jQuery('div#rotator ul li:eq('+slide+')').is('.show')){
        return 1;
      }else{
        var next = jQuery('div#rotator ul li:eq('+slide+')');
      }
      //Set the fade in effect for the next image, the show class has higher z-index
      next.css({opacity: 0.0})
      .addClass('show')
      .animate({opacity: 1.0}, 1000);

      //Hide the current image
      current.animate({opacity: 0.0}, 1000)
      .removeClass('show');

      //Get the first number
      var currentNumber = (jQuery('div.rotator_numbers a.active')?  jQuery('div.rotator_numbers a.active') : jQuery('div.rotator_numbers a:first'));

      //Get next number, when it reaches the end, rotate it back to the first number
      if(jQuery('div.rotator_numbers a:eq('+slide+')').is('.active')){
        return FALSE;
      }else{
        var nextNumber = jQuery('div.rotator_numbers a:eq('+slide+')');
      }

      //give the next number class active
      nextNumber.addClass('active');

      //take away class active
      currentNumber.removeClass('active');

      if(start){
        rotation();
      }
      return FALSE;
	});
  jQuery("#playmediarotator").click( function(){
      if(intervalID != 0){
        stopRotation();
        jQuery(this).attr('src','/sites/all/themes/pltw/images/pltw_play_btn.gif');
      }else{
        rotation();
        jQuery(this).attr('src','/sites/all/themes/pltw/images/pltw_pause_btn.gif');
      }
	});
*/
theRotator('header', 5000);
  
});
