var picspaceimages = new Array(12);

// For each picture space
for (var picspacecount = 0; picspacecount <= 11; picspacecount++) {

  // Define an array to store the 2 images for that section
  picspaceimages[picspacecount] = new Array(2);

  // For each of the 2 images
  for (var picspacepiccount = 0; picspacepiccount <= 1; picspacepiccount++ ) {
    
    // Define the array section as a new image
    picspaceimages[picspacecount][picspacepiccount] = new Image();

    // Work out which image number we need to load
    var imgfileid = 2 * picspacecount + picspacepiccount + 1;

    // Load the image src into the array area
    picspaceimages[picspacecount][picspacepiccount].src = "dynamiccontent/"
                                                        + "frontpageimage"
                                                        + imgfileid + "1.jpg";

  }
}

// Set out initial values
// Where we start counting from
var value = 100;
// Which picspace to change first
var picspace = 0;
// Which picid to load first, we need to load the second pic cause the first
// is automagically displayed
var picid = 1;
// Whether we are reducing opacity, initial we are
var reducing = 1;

// The rotate function
function rotate() {

  // See if we are reducing
  if (reducing) {

    // Check we haven't reached the lowest level
    if (value > 3) {

      // Keep going
      value -= 2.5;

    }
    else {
      
      // Else stop reducing
      reducing = 0;

      // Swap to the next picture src in this picspace
      document.getElementById("picspace" + picspace).src = 
                            picspaceimages[picspace][picid].src;

    }
  }
  else {

    // We must be increasing opacity
    // Check we are not at the highest limit
    if (value < 97) {

      // Keep increasing
      value+=2.5;

    }
    else {

      // Stop increasing
      reducing = 1;

      // See if we are on the last picspace
      if (picspace >= 11) {

        // If so start at the first one again
        picspace = 0;

        // See if we are on the last of the 3 pictures
        if (picid >= 1) {

          // If so start at the first one again
          picid = 0;
  
        }
        else {

          // Else move onto the next picture
          picid ++;
        }

      }
      else {

        // Else move onto the next picture space
        picspace ++;

      }
    }
  }

  
  // For mozilla
  if (window.sidebar) {

    document.getElementById("picspace" + picspace).style.MozOpacity
                                                                 = value/100;
  }
    
  // For IE
  if (document.all) {

    document.getElementById("picspace" + picspace).filters[0].opacity
                                                                  = value;
  }
}

// A function to start the rotation
function startrotate() {

  // See if we are running in mozilla
  if (window.sidebar) {
    setInterval("rotate()",25);
  }

  // See if we are running in IE
  if (document.all) {
    setInterval("rotate()",25);
  }
}
