var deltaOpacity = 10;
var fadeMilliseconds = 100;
var periodMiniseconds = 5000;

var objRotationFadeZonesArrays = new Object();

  function reposisionRotationFadeZone(z) {
    var firstZone = document.getElementById("Zone" + z);
    var t = getTop(firstZone);
    var l = getLeft(firstZone);
    var alignTop = window["alignTopRotationFadeZone" + z];
  }
  
  function initRotationFadeZone(z) {
    var firstZone = document.getElementById("Zone" + z);
    var t = getTop(firstZone);
    var l = getLeft(firstZone);
    var maxHeight = -1;
    for (var i = objRotationFadeZonesArrays[z].length - 1; i > -1; i--) {
      var zone = document.getElementById(objRotationFadeZonesArrays[z][i]);
      var h = zone.clientHeight;
      if (h > maxHeight) {
        maxHeight = h;
      }
      objRotationFadeZonesArrays[z][i] = zone;
    }
    var alignTop = window["alignTopRotationFadeZone" + z];
    if (alignTop) {
      if (firstZone.clientHeight < maxHeight) {
        var deltaHeight = maxHeight - zone.clientHeight;
        firstZone.style.paddingBottom = deltaHeight + "px";
      }
    }
    for (var i = objRotationFadeZonesArrays[z].length - 1; i > -1; i--) {
      var zone = objRotationFadeZonesArrays[z][i];
      if (!alignTop) {
        if (zone.clientHeight < maxHeight) {
          var deltaHeight = maxHeight - zone.clientHeight;
          var pTop = Math.ceil(deltaHeight / 2);
          var pBottom = deltaHeight - pTop;
          zone.style.paddingTop = pTop + "px";
          zone.style.paddingBottom = pBottom + "px";
        }
      }
      if (i != 0) {
        zone.style.top = t + "px";
        zone.style.left = l + "px";
        zone.style.display = "none";
      }
    }
    setTimeout("fadeInRotationFadeZone(" + z + ");", window["periodMiniseconds" + z]);
    MiniSite_addEvent(window, "resize", new Function("repositionRotationFadeZone(" + z + ");")); 
  }

  function repositionRotationFadeZone(z) {
    var alpha = null;
    var beta = null;
    var zones = objRotationFadeZonesArrays[z];
    var firstZone = zones[0];
    var t = getTop(firstZone);
    var l = getLeft(firstZone);
    var alignTop = window["alignTopRotationFadeZone" + z];
    for (var i = zones.length - 1; i > 0; i--) {
      var zone = zones[i];
      zone.style.left = (((zone.clientWidth - firstZone.clientWidth) / 2) + l) + "px";
      if (alignTop) {
        zone.style.top = t + "px";
      } else {
        zone.style.top = (((zone.clientHeight - firstZone.clientHeight) / 2) + t) + "px";
      }
    }
    
  }
  
  function fadeInRotationFadeZone(z) {
    var alpha = null;
    var beta = null;
    var opacity = window["opacityRotationFadeZone" + z];
    var active = window["activeRotationFadeZone" + z];
    var zones = objRotationFadeZonesArrays[z];
    alpha = zones[active];
    beta = active == zones.length - 1 ? beta = zones[0] : zones[active + 1];
    
    var firstZone = zones[0];
    var t = getTop(firstZone);
    var l = getLeft(firstZone);
    var alignTop = window["alignTopRotationFadeZone" + z];
    if (alpha != firstZone) {
      alpha.style.left = (((alpha.clientWidth - firstZone.clientWidth) / 2) + l) + "px";
      if (alignTop) {
        alpha.style.top = t + "px";
      } else {
        alpha.style.top = (((alpha.clientHeight - firstZone.clientHeight) / 2) + t) + "px";
      }
    }
    
    if (beta != firstZone) {
      beta.style.left = (((beta.clientWidth - firstZone.clientWidth) / 2) + l) + "px";
      if (alignTop) {
        beta.style.top = t + "px";
      } else {
        beta.style.top = (((beta.clientHeight - firstZone.clientHeight) / 2) + t) + "px";
      }
    }
    
    if (opacity == 0) {
      beta.style.display = 'block';
    } else if (opacity == 100) {
      if (active != 0) {
        alpha.style.display = 'none';
      }
    }
    setOpacity(beta, opacity);
    setOpacity(alpha, 100 - opacity);
    
    if (opacity < 100) {
      opacity += deltaOpacity;
      if (opacity > 100) {
        opacity = 100;
      }
      setTimeout("fadeInRotationFadeZone(" + z + ");", fadeMilliseconds);
    } else {
      active++;
      opacity = 0;
      if (active >= zones.length) {
        active = 0;
      }
      setTimeout("fadeInRotationFadeZone(" + z + ");", window["periodMiniseconds" + z]);
    }

    window["opacityRotationFadeZone" + z] = opacity;
    window["activeRotationFadeZone" + z] = active;
  }

  function setOpacity(o, opacity) {
    o.style.filter = 'alpha(opacity=' + opacity + ')';
    o.style.MozOpacity = opacity / 100;
    o.style.opacity = opacity / 100;
  }
  
  function initEditRotationFadeZone(z) {
    var zones = objRotationFadeZonesArrays[z];
    //alert(zones);
    for (var i = 0; i < zones.length; i++) {
      var zone = document.getElementById(zones[i]);
      var ot = document.getElementById(zones[i] + "OptionsTable");
      var delta = ot.clientHeight;
      var lb = document.getElementById(zones[i] + "LB");
      var rb = document.getElementById(zones[i] + "RB");
      var t = getTop(zone);
      var l = getLeft(ot);
      /*
      lb.style.top = "10px";
      rb.style.top = "10px";
      lb.style.left = "10px";
      rb.style.left = "10px";
      lb.style.height = "10px";
      rb.style.height = "10px";
      lb.style.width = "10px";
      rb.style.width = "10px";
      */
      //lb.style.visibility = "visible";
      //rb.style.visibility = "visible";
      
      lb.style.top = (t + delta) + "px";
      rb.style.top = (t + delta) + "px";
      lb.style.left = (l) + "px";
      rb.style.left = (l + zone.clientWidth - 1) + "px";
      lb.style.height = (zone.clientHeight - delta + (i == 0 ? 1 : 0)) + "px";
      rb.style.height = (zone.clientHeight - delta + (i == 0 ? 1 : 0)) + "px";
      lb.style.width = "1px";
      rb.style.width = "1px";
      lb.style.visibility = "visible";
      rb.style.visibility = "visible";
      
    }
    return;
    var firstZone = document.getElementById("Zone" + z);
    var t = getTop(firstZone);
    var l = getLeft(firstZone);
    var maxHeight = -1;
    for (var i = objRotationFadeZonesArrays[z].length - 1; i > -1; i--) {
      var zone = document.getElementById(objRotationFadeZonesArrays[z][i]);
      var h = zone.clientHeight;
      if (h > maxHeight) {
        maxHeight = h;
      }
      objRotationFadeZonesArrays[z][i] = zone;
    }
  
  }
