﻿// JScript File

var currentBanner = 1;
function selectbanner(num)
{
  for (var i = 1; i <= bannersCount; i++) 
  {
    if(i != num)
    {
      document.getElementById("banner_" + i).style.display = "none";
      document.getElementById("banner_button_" + i).className = "box";
    }
    else
    {
      var banner = document.getElementById("banner_" + i);

      document.getElementById("banner_" + i).style.display = "block";
      SetOpacity(banner , 0);

      FadeOpacity("banner_" + i, 0, 100, 500, 25);
      document.getElementById("banner_button_" + i).className = "box_selected";
    }
  }
}
    
function moveNext()
{
  currentBanner = currentBanner % bannersCount + 1;
  selectbanner(currentBanner);
  setTimeout ( "moveNext()", 10000 );
}
    
function SetOpacity(elem, opacityAsInt)
{
	var opacityAsDecimal = opacityAsInt;
	
	if (opacityAsInt > 100)
		opacityAsInt = opacityAsDecimal = 100; 
	else if (opacityAsInt < 0)
		opacityAsInt = opacityAsDecimal = 0; 
	
	opacityAsDecimal /= 100;
	if (opacityAsInt < 1)
		opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
	
	elem.style.opacity = opacityAsDecimal;
	elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{
	var steps = Math.ceil(fps * (time / 1000));
	var delta = (toOpacity - fromOpacity) / steps;
	
	FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
    SetOpacity(document.getElementById(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)));

    if (stepNum < steps)
        setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
}


