// This script section rotates through customer logos on the home page
// Logos should be placed in logoDir along with corresponding images faded to white
// files should end in _20.gif, _40.gif, . . ., _100.gif
// _20.gif corresponds to the version which is only 20% visible
// _40.gif corresponds to the version which is only 40% visible
// _100.gif is the normal version of the image
// - Steve Smith 2005
// values in ms:
fadeInterval=80;
displayInterval=3600;
logoDir=pathToTop+"images/homelogos/";

numLogos=20;
// maximum number of times to loop through the logos... keeps certain browsers from perpetually hitting web site...
maxLoops=20;
logoList = new Array(numLogos);
// Number zero is always displayed first... the rest are randomized

logoList[0]="atlantic";
logoList[1]="miniclip";
logoList[2]="newline";
logoList[3]="eyeblaster";
logoList[4]="namesco";
logoList[5]="rgj";
logoList[6]="healthline";
logoList[7]="staceys";
logoList[8]="bilingual";
logoList[9]="chickfila";
logoList[10]="meguiars";
logoList[11]="urbannet";
logoList[12]="arabic";
logoList[13]="office_supply";
logoList[14]="computer";
logoList[15]="pharmacy";
logoList[16]="healthcare";
logoList[17]="co_paper";
logoList[18]="telco";
logoList[19]="pdi";   // added 4/3/08 bug 4714

preloadArray = new Array();
logosLeft=maxLoops*numLogos+1;

for (i=1;i<numLogos;i++) {
  // shuffle logos around so we get a random order
  swapNum=parseInt(Math.random()*(numLogos-i)+i,10);
  if (swapNum!=i) {
    tmp=logoList[i];
    logoList[i]=logoList[swapNum];
    logoList[swapNum]=tmp;
  }
}

firstLogo=logoDir+logoList[0]+"_100.gif";
preloaded = 0;
nextID=0;

// density = 0 completely faded; density = 100 normal color
function doNext(logoNum,countdown,density,interval) {
  var t = fadeInterval;
  if (countdown) {
    t = displayInterval/5;
    countdown--;
    nextCmd = "doNext("+logoNum+","+countdown+","+density+","+interval+")";
  } else if (density == 0) {
    document.images["logos"].src=logoDir+"blank.gif";
    logoNum++;
    if (logoNum>=numLogos) {
      logoNum=0;
    }
    nextCmd = "doNext("+logoNum+","+countdown+",20,20)";
  } else {
    document.images["logos"].src=logoDir+logoList[logoNum]+"_"+density+".gif";
    if (density == 100) {
      t = displayInterval/5;
	  logosLeft--;
      nextCmd = "doNext("+logoNum+",5,80,-20)";
    } else {
      density+=interval;
      nextCmd = "doNext("+logoNum+","+countdown+","+density+","+interval+")";
    }
  }
  if (logosLeft) 
    nextID = setTimeout(nextCmd,t);
  if (! preloaded) {
    k=preloadArray.length;
    for (i=0;i<numLogos;i++) {
      for (j=100;j>0;j-=20) {
        preloadArray[k]=new Image;
        preloadArray[k].src=logoDir+logoList[i]+"_"+j+".gif";
        k++;
      }
    }
    preloadArray[k]=new Image;
    preloadArray[k].src=logoDir+"blank.gif";
    preloaded=1;
  }
}

function logo_faster() {
  displayInterval=displayInterval/2;
  if (displayInterval<225) {
    displayInterval=225;
  }
  fadeInterval=fadeInterval/2;
  if (fadeInterval<5) {
    fadeInterval=5;
  }
  if (logosLeft==0) {
    logosLeft=maxLoops*numLogos+1;
    doNext(0,0,100,-20);
  }
}

function logo_slower() {
  displayInterval=displayInterval*2;
  if (displayInterval>14400) {
    displayInterval=14400;
  }
  fadeInterval=fadeInterval*2;
  if (fadeInterval>320) {
    fadeInterval=320;
  }
  if (logosLeft==0) {
    logosLeft=maxLoops*numLogos+1;
    doNext(0,0,100,-20);
  }

}
