/* Aragon Online - Copyright 2003-2010 by Russell Shilling */
/* rotator.js */

/* Adapted from: http://www.htmlgoodies.com/beyond/javascript/article.php/3872041/Web-Developer-Class-Build-Your-Own-JavaScript-Content-Rotator.htm */

var Rotator = {

  // Tracking variables
  contentAreas: 4,              // Total number of content areas in rotation
  contentIndex: 1,              // Track which content area is currently being displayed
  continueRotation: 0,          // Track whether rotation is currently on or off
  rotationInProgress: 0,        // True if on delay before doRotate is executed
  changeDelay: 5000,            // in milliseconds
  menuClass: 'thead vbmenu_control',		// Default class when not selected
  menuSelected: 'thead vbmenu_control tborder',	// Class when selected

  // Make all content areas other than 1 not visible
  init: function() {

    for (var i = 2; i <= Rotator.contentAreas; i++) {

      var contentAreaID = 'content' + i;  
      // $(contentAreaID).setAttribute('style', 'display: none');
      $(contentAreaID).style.display = 'none';
    }
    
    Rotator.start();
  },

  // This function handles all of the content rotation
  doRotate: function() { 

    if (Rotator.continueRotation == 1) {

      var contentAreaID = 'content' + Rotator.contentIndex;

      // Turn off current content area
      // $(contentAreaID).setAttribute('style','display: none');
      $(contentAreaID).style.display = 'none';

      var menuID = 'menu' + Rotator.contentIndex;  
      // $(menuID).setAttribute('class', Rotator.menuClass);
      $(menuID).className = Rotator.menuClass;
      
      // Turn on next content area
      if (Rotator.contentIndex >= Rotator.contentAreas) {

        // Roll back to the first area
        Rotator.contentIndex = 1;

      } else {

        Rotator.contentIndex ++;

      }

      contentAreaID = 'content' + Rotator.contentIndex;

      // $(contentAreaID).setAttribute('style', 'display: inline');
      $(contentAreaID).style.display = 'inline';

      menuID = 'menu' + Rotator.contentIndex;  
      // $(menuID).setAttribute('class', Rotator.menuSelected);
      $(menuID).className = Rotator.menuSelected;

      // Call the rotation function again with the delay interval we defined above
      setTimeout(Rotator.doRotate, Rotator.changeDelay);

      // Rotation continues, set rotationInProgress
      Rotator.rotationInProgress = 1;

    } else {

      // Rotation is stopped, reset rotationInProgress
      Rotator.rotationInProgress = 0;

    }
  },

  // Go to a specific content item
  goto: function(index) {

    // Turn off current content area
    var contentAreaID = 'content' + Rotator.contentIndex;
    // $(contentAreaID).setAttribute('style','display: none');
    $(contentAreaID).style.display = 'none';

    var menuID = 'menu' + Rotator.contentIndex;  
    // $(menuID).setAttribute('class', Rotator.menuClass);
    $(menuID).className = Rotator.menuClass;

    // Turn on specified content area
    contentAreaID = 'content' + index;
    // $(contentAreaID).setAttribute('style','display: inline');
    $(contentAreaID).style.display = 'inline';
    
    menuID = 'menu' + index;  
    // $(menuID).setAttribute('class', Rotator.menuSelected);
    $(menuID).className = Rotator.menuSelected;
    
    Rotator.contentIndex = index;
  },

  // This starts/restarts the content rotation
  start: function() {

    Rotator.continueRotation = 1;

    // Only call the rotation function when we are not
    // in the middle of a rotation delay

    if (Rotator.rotationInProgress == 0) {

      Rotator.rotationInProgress = 1;

      setTimeout(Rotator.doRotate, Rotator.changeDelay);

    }
  },

  // This stops the content rotation
  stop: function() {

    // Stop rotation by setting the continueRotation flag to zero
    Rotator.continueRotation = 0;

  }
}

