//Rotate properties Script
function Property_Rotate()
{
  this.ScrollDirection = 'up';
  this.ScrollInterval = 10;
  this.ScrollStep = 1;
  this.ShowEffect = null; 
  this.ShowEffectDuration = 0;
  this.SlidePause = 2000;
  this.SmoothScrollSpeed = 'Medium'; 
  this.Slides = new Array();
  this.Tickers = new Array();
  this.LeadTickers = new Array();
  this.GlobalID = ''; 
  this.ElementID = '';
  this.ContainerID = '';
  this.AutoStart = true;
  this.HideEffect = null; 
  this.HideEffectDuration = 0;
  this.Loop = true; 
  this.PauseOnMouseOver = true;
  this.RotationType = 'ContentScroll';

  this.HasTickers = false; 
  this.FirstTicker = null; 
  this.Stopped = false; 
  this.Ticking = false; 
  this.Status = '';
  this.CurrentSlide = -1; 
  this.CurrentLeadTicker = 0; 
  this.ScrollIntervalID = 0; 
  this.NextSlideTimeoutID = 0; 
  this.HideTimeoutID = 0; 
  this.FirstTimeAround = true; 
}


// Starts content rotation for the given Rotate instance 
function prop_Start(Rotate) 
{
  if (Rotate.RotationType == 'SlideShow') 
  {
    aa_ShowNextSlide(Rotate);     
  }
  else
  {
    scroll_Init(Rotate); 
    scroll_ShowNextSlide(Rotate); 
  }
} 

// Continues content rotation after it was stopped 
function prop_Play(Rotate)
{
  if (!Rotate.Stopped) return null;
  Rotate.Stopped = false; 
  
  if (!Rotate.Ticking) 
  {  
    if (Rotate.RotationType == 'SlideShow') 
    {
      aa_Play(Rotate); 
    }
    else  
    {
      scroll_Play(Rotate);       
    }
  }
}

// Stops content rotation for the given Rotate instance 
function prop_Stop(Rotate) 
{
  if (Rotate.Stopped) return null;
  Rotate.Stopped = true; 
  window.clearTimeout(Rotate.NextSlideTimeoutID); 
  window.clearTimeout(Rotate.HideTimeoutID); 
  if (Rotate.SlidePause == 0) window.clearInterval(Rotate.ScrollIntervalID); 
  if (Rotate.RotationType == 'SlideShow') 
  {
    var Container = document.getElementById(Rotate.ContainerID); 
    Container.style.visibility = 'visible'; 
  }
} 


// Sets the index of the next slide 
function prop_SetNextSlideIndex(Rotate)
{
  if (Rotate.CurrentSlide == -1) 
    Rotate.CurrentSlide = 0; 
  else if (Rotate.CurrentSlide == Rotate.Slides.length - 1)
  {
    Rotate.CurrentSlide = 0; 
    Rotate.FirstTimeAround = false; 
  } 
  else
    Rotate.CurrentSlide ++; 
}

// Slideshow client-side code ---------------------------------------------------------------------

// Continues rotation when RotationType == 'SlideShow' 
function aa_Play(Rotate)
{
  if (Rotate.HasTickers && Rotate.Status == 'PlayingShowEffect') return null; 
  if (!Rotate.Ticking) 
  {
    aa_PlayHideEffect(Rotate); 

    var delay = 0; 
    if (Rotate.HideEffect) delay = Rotate.HideEffectDuration; 
    functionParam = 'aa_ShowNextSlide(' + Rotate.GlobalID + ')'; 
    Rotate.NextSlideTimeoutID  = window.setTimeout(functionParam, delay);   
  } 
}

// Shows the next slide when RotationType == 'SlideShow'
function aa_ShowNextSlide(Rotate)
{
  if (Rotate.Stopped) return null;   
  prop_SetNextSlideIndex(Rotate); 
    
  // Setup slide content 
  var Container = document.getElementById(Rotate.ContainerID); 
  var CurSlide = document.getElementById(Rotate.Slides[Rotate.CurrentSlide]); 
  Container.innerHTML = CurSlide.innerHTML; 
  CurSlide.innerHTML = ''; 
  prop_ResetTickers(Rotate); 

  aa_PlayShowEffect(Rotate); 
  
  if (Rotate.HasTickers) 
  {
    // Set timeout for displaying the slide 
    var functionParam = 'prop_StartTickerSequence(' + Rotate.GlobalID + ')'; 
    var timerID = window.setTimeout(functionParam, Rotate.ShowEffectDuration);   
  } 
  else
  { 
    // Set timeout for displaying the slide 
    var functionParam = 'aa_DisplaySlide(' + Rotate.GlobalID + ')'; 
    Rotate.NextSlideTimeoutID = window.setTimeout(functionParam, Rotate.ShowEffectDuration);   
  } 
}

// Displays current slide when RotationType == 'SlideShow'
function aa_DisplaySlide(Rotate)
{
  if (Rotate.Stopped) return null; 
  Rotate.Status = 'DisplayingSlide';

  window.clearTimeout(Rotate.HideTimeoutID); 
  window.clearTimeout(Rotate.NextSlideTimeoutID); 

  if (!Rotate.Loop && Rotate.CurrentSlide == Rotate.Slides.length - 1) 
  {
    prop_Stop(Rotate); 
    return null; 
  }

  // Set timeout for hiding the slide 
  var functionParam = 'aa_PlayHideEffect(' + Rotate.GlobalID + ')'; 
  Rotate.HideTimeoutID = window.setTimeout(functionParam, Rotate.SlidePause);   
  
  // Set timeout for aa_ShowNextSlide 
  var delay = 0; 
  if (Rotate.HideEffect) delay += Rotate.HideEffectDuration; 
  delay += Rotate.SlidePause; 
  functionParam = 'aa_ShowNextSlide(' + Rotate.GlobalID + ')'; 
  Rotate.NextSlideTimeoutID  = window.setTimeout(functionParam, delay);   
} 


// Plays show effect when RotationType == 'SlideShow'
function aa_PlayShowEffect(Rotate) 
{
  Rotate.Status = 'PlayingShowEffect';
  var Container = document.getElementById(Rotate.ContainerID); 

  if (Container.filters && Rotate.ShowEffect) 
  {
    Container.style.filter = Rotate.ShowEffect; 
    Container.filters[0].apply(); 
  } 
  Container.style.visibility = 'visible'; 

  if (Container.filters && Rotate.ShowEffect) Container.filters[0].play(); 
} 

// Plays hide effect when RotationType == 'SlideShow'
function aa_PlayHideEffect(Rotate) 
{
  Rotate.Status = 'PlayingHideEffect';
  var Container = document.getElementById(Rotate.ContainerID); 

  if (Container.filters && Rotate.HideEffect) 
  {
    Container.style.filter = Rotate.HideEffect; 
    Container.filters[0].apply(); 
  } 
  // Reset slide content 
  var CurSlide = document.getElementById(Rotate.Slides[Rotate.CurrentSlide]); 
  CurSlide.innerHTML = Container.innerHTML; 
  Container.style.visibility = 'hidden'; 
  if (Container.filters && Rotate.HideEffect) Container.filters[0].play(); 
} 


// Ticker integration client-side code ------------------------------------------------------------

// Starts the ticker sequence for the current slide of the given Rotate instance 
function prop_StartTickerSequence(Rotate)
{
  Rotate.Status = 'RunningTickers';
  Rotate.Ticking = true; 
  prop_StartTicker(Rotate.LeadTickers[Rotate.CurrentLeadTicker]); 
}

function prop_EndTickerSequence(Rotate)
{
  Rotate.Ticking = false; 
  if (!Rotate.Stopped)
  {  
    if (Rotate.RotationType == 'SlideShow') 
    {
      aa_DisplaySlide(Rotate); 
    } 
    else
    { 
      var functionParam = 'scroll_ShowNextSlide(' + Rotate.GlobalID + ')'; 
      Rotate.NextSlideTimeoutID = window.setTimeout(functionParam, Rotate.SlidePause); 
    }
  } 
  prop_SetNextLeadTicker(Rotate); 
}

// Sets the lead ticker index for the next slide 
function prop_SetNextLeadTicker(Rotate)
{
  if (Rotate.CurrentLeadTicker == Rotate.LeadTickers.length - 1)
    Rotate.CurrentLeadTicker = 0; 
  else
    Rotate.CurrentLeadTicker ++; 
}

// Sets the text of all ticker instances contained within the give Rotate instance to ''
function prop_ResetTickers(Rotate)
{
  if (Rotate.HasTickers) 
    for (var i = 0; i < Rotate.Tickers.length; i++)
      prop_SetTickerText(Rotate.Tickers[i], ''); 
}

// Mouse over & mouse out Rotate event handlers --------------------------------------------------

function ie_MsOver(obj, rco_Rotate)
{
  if(!obj.contains(event.fromElement) && rco_Rotate) prop_Stop(rco_Rotate); 
}

function ie_MsOut(obj, rco_Rotate)
{
  if(!obj.contains(event.toElement) && rco_Rotate) prop_Play(rco_Rotate); 
}

function ns_MsOver(evt, rElementID, rco_Rotate)
{
  if (nsIsMouseOnObject(rElementID, evt) && rco_Rotate) prop_Stop(rco_Rotate); 
}

function ns_MsOut(evt, rElementID, rco_Rotate)
{
  if (!nsIsMouseOnObject(rElementID, evt) && rco_Rotate) prop_Play(rco_Rotate);  
}


// Utils ------------------------------------------------------------------------------------------

// Determines whether the mouse pointer is currently over the given object 
function nsIsMouseOnObject(objName, evt)
{
  if (objName != null)
  {
    var obj = document.getElementById(objName); 
    var objLeft = ns_pageX(obj) - 1; 
    var objTop = ns_pageY(obj) - 1; 
    var objRight = objLeft + obj.offsetWidth + 1; 
    var objBottom = objTop + obj.offsetHeight + 1;
    
    if ((evt.pageX > objLeft) && (evt.pageX < objRight) && 
        (evt.pageY > objTop) && (evt.pageY < objBottom))
      return true; 
    else  
      return false; 
  }
  else
    return false; 
}

// Calculates the absolute page x coordinate of any element
function ns_pageX(element)
{
  var x = 0;
  do 
  {
    if (element.style.position == 'absolute') 
    {
      return x + element.offsetLeft; 
    }
    else
    {
      x += element.offsetLeft;
      if (element.offsetParent) 
        if (element.offsetParent.tagName == 'TABLE') 
          if (parseInt(element.offsetParent.border) > 0)
          {
            x += 1; 
          }
    }
  }
  while ((element = element.offsetParent));
  return x; 
}

// Calculates the absolute page y coordinate of any element
function ns_pageY(element)
{
  var y = 0;
  do 
  {
    if (element.style.position == 'absolute') 
    {
      return y + element.offsetTop; 
    }
    else
    {
      y += element.offsetTop;
      if (element.offsetParent) 
        if (element.offsetParent.tagName == 'TABLE') 
          if (parseInt(element.offsetParent.border) > 0)
          {
            y += 1; 
          }
    }
  }
  while ((element = element.offsetParent));
  return y; 
}

// Returns the absolute value for the given parameter 
function abs(x)
{
  if (x < 0) 
    return -x; 
  else
    return x;
}
