﻿var iQuoteIndex=0, iQuoteCount=5;
var iLogoIndex=1, iLogoCount=3;

function cycleLogos() {
  var sImageName;
  
  if (navigator.appName.toLowerCase().match("microsoft") != null) {
    iLogoIndex++;
    if (iLogoIndex > iLogoCount) iLogoIndex = 1;
    
    if (iLogoIndex == 1)
      sImageName = "images/cust_logo1.jpg";
    else if (iLogoIndex == 2)
      sImageName = "images/cust_logo2.jpg";
    else
      sImageName = "images/cust_logo3.jpg";
    
    document.getElementById("logos").filters[0].apply();
    document.getElementById("logos").src = sImageName;
    document.getElementById("logos").filters[0].play();
    setTimeout("cycleLogos()", 2000);
  }
  else {
    if (document.getElementById("logos").style.opacity == "") {
      document.getElementById("logos").style.opacity = 1;
    }
    
    if (document.getElementById("logos").style.opacity <= 0) {
      iLogoIndex++;
      if (iLogoIndex > iLogoCount) iLogoIndex = 1;
      
      if (iLogoIndex == 1)
        sImageName = "images/cust_logo1.jpg";
      else if (iLogoIndex == 2)
        sImageName = "images/cust_logo2.jpg";
      else
        sImageName = "images/cust_logo3.jpg";
      
      document.getElementById("logos").src = sImageName;
      fadeOpacity(0, 1, .1, 50);
      setTimeout("cycleLogos()", 2000);
    }
    else if (document.getElementById("logos").style.opacity >= 1) {
      fadeOpacity(1, 0, -.1, 50);
      setTimeout("cycleLogos()", 1000);
    }
    else {
      setTimeout("cycleLogos()", 100);
    }
    
    document.getElementById("logos").src = sImageName;
  }
}

function fadeOpacity(startOpacity, endOpacity, incr, delay) {
  if ((startOpacity > endOpacity && incr < 0) || (startOpacity < endOpacity && incr > 0)) {
    startOpacity += incr;
    document.getElementById("logos").style.opacity = startOpacity;
    setTimeout("fadeOpacity(" + startOpacity + ", " + endOpacity + ", " + incr + ", " + delay + ")", delay);
  }
}

function cycleQuotes() {
  var color;
  
  if (document.getElementById("quotes").style.color == "") {
    document.getElementById("quotes").style.color = "rgb(255,255,255)";
  }
  
  color = document.getElementById("quotes").style.color.toLowerCase();
  color = color.replace(" ", "");
  color = color.replace(" ", "");
  
  if (color == "rgb(255,255,255)") {
    iQuoteIndex++;
    if (iQuoteIndex > iQuoteCount) iQuoteIndex = 1;
    document.getElementById("quotes").innerHTML = "This is the text for Quote " + iQuoteIndex;
    fadeInTextColor();
    setTimeout("cycleQuotes()", 5000);
  }
  else if (color == "rgb(0,0,0)") {
    fadeOutTextColor();
    setTimeout("cycleQuotes()", 1000);
  }
  else {
    setTimeout("cycleQuotes()", 100);
  }
}

function fadeInTextColor() {
  fadeTextColor(255, 0, -10, 50);
}

function fadeOutTextColor() {
  fadeTextColor(0, 255, 10, 50);
}

function fadeTextColor(startColor, endColor, incr, delay) {
  if ((startColor > endColor && incr < 0) || (startColor < endColor && incr > 0)) {
    startColor += incr;
    document.getElementById("quotes").style.color = "rgb(" + startColor + "," + startColor + "," + startColor + ")";
    setTimeout("fadeTextColor(" + startColor + ", " + endColor + ", " + incr + ", " + delay + ")", delay);
  }
}

