// JavaScript Document
pic1= new Image(); 
pic2= new Image(); 
pic3= new Image(); 
pic4= new Image(); 
pic5= new Image(); 
pic1.src="images/rotation/photo1-1.jpg";
pic2.src="images/rotation/photo1-2.jpg";
pic3.src="images/rotation/photo1-3.jpg";
pic4.src="images/md_rotation/md_11.jpg";
pic5.src="images/rotation/photo1-5.jpg";

var imageLocations0 = new Array;
//imageLocations0[0] = ["photo1-1.jpg","/NICE/nice_newsletter.asp"];
//imageLocations0[1] = ["photo2-1.jpg","/NICE/healthy_fruit_vegetables.asp"];
//imageLocations0[2] = ["photo3-1.jpg","/NICE/teen_healthy_downloads.asp"];
//imageLocations0[3] = ["NICETestBanner01.jpg","/NICE/"];

// Use the following lines to define banner ad photo rotation
// Syntax: 
// imageLocations0[index] = [photo to use in /images/banner/, link URL];

imageLocations0[0] = ["bnrKiosk.jpg","#"];
imageLocations0[1] = ["bnrNICE.jpg","/NICE/"];

var imageLocations1 = new Array("photo1-2.jpg","photo2-2.jpg","photo3-2.jpg","photo4-2.jpg");
var imageLocations2 = new Array("photo1-3.jpg","photo2-3.jpg","photo3-3.jpg","photo4-3.jpg");
var imageLocations3 = new Array("DParker_FNP.jpg","RBrilliant_DO.jpg","SMitta_MD.jpg","DWarner_NP.jpg","MRyan_NP.jpg");
var imageLocations4 = new Array("photo1-5.jpg","photo2-5.jpg","photo3-5.jpg","photo4-5.jpg");
var currentImg0 = 0;
var currentImg1 = 0;
var currentImg2 = 0;
var currentImg3 = 0;
var currentImg4 = 0;


// Code 0 -- controls banner ad
function callFadeOut0 () {
	//timeout controls amount of time before image fades
	window.setTimeout("fadeOut(\"thephoto0\",100)",9500);
} // end function

function startUpRotation0() {
	imageId = 'thephoto0';
//	document.getElementById("photoHolder0").innerHTML="<a href='"+imageLocations0[currentImg0][1]+"'><img src='images/rotation/"+imageLocations0[currentImg0][0]+"' alt='Photo' name=\"thephoto0\" id='thephoto0' border='0' /></a>";
	document.getElementById("photoHolder0").innerHTML="<a href='"+imageLocations0[currentImg0][1]+"'><img src='images/banner/"+imageLocations0[currentImg0][0]+"' alt='Photo' name=\"thephoto0\" id='thephoto0' border='0' /></a>";
	currentImg0++;
	if (currentImg0>=imageLocations0.length) {currentImg0=0}
	//timeout controls amount of time before image changes
	window.setTimeout("startUpRotation0()", 11100);
	callFadeOut0 ()
	initImage0();
} // end function

function initImage0() {
  imageId = 'thephoto0';
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
}
// End Code 0


// Code 1 -- not used when banner ad is active
function callFadeOut1 () {
	window.setTimeout("fadeOut(\"thephoto1\",100)",9500);
} // end function

function startUpRotation1() {
	imageId = 'thephoto1';
	document.getElementById("photoHolder1").innerHTML="<img src='images/rotation/"+imageLocations1[currentImg1]+"' alt='Photo' name=\"thephoto1\" id='thephoto1' />";
	currentImg1++;
	if (currentImg1>=imageLocations1.length) {currentImg1=0}
	window.setTimeout("startUpRotation1()", 11100);
	callFadeOut1 ()
	initImage1();
} // end function

function initImage1() {
  imageId = 'thephoto1';
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
}
// End Code 1


// Code 2 -- not used when banner ad is active
function callFadeOut2 () {
	window.setTimeout("fadeOut(\"thephoto2\",100)",9500);
} // end function

function startUpRotation2() {
	imageId = 'thephoto2';
	document.getElementById("photoHolder2").innerHTML="<img src='images/rotation/"+imageLocations2[currentImg2]+"' alt='Photo' name=\"thephoto2\" id='thephoto2' />";
	currentImg2++;
	if (currentImg2>=imageLocations2.length) {currentImg2=0}
	window.setTimeout("startUpRotation2()", 11100);
	callFadeOut2 ()
	initImage2();
} // end function

function initImage2() {
  imageId = 'thephoto2';
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
}
// End Code 2


// Code 3 -- controls MD photos in page body
function callFadeOut3 () {
	window.setTimeout("fadeOut(\"thephoto3\",100)",6400);
} // end function

function startUpRotation3() {
	imageId = 'thephoto3';
	document.getElementById("docs").innerHTML="<img src='images/md_rotation/"+imageLocations3[currentImg3]+"' alt='Photo' name=\"thephoto3\" id='thephoto3' />";
	currentImg3++;
	if (currentImg3>=imageLocations3.length) {currentImg3=0}
	window.setTimeout("startUpRotation3()", 8000);
	callFadeOut3 ()
	initImage3();
} // end function

function initImage3() {
  imageId = 'thephoto3';
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
}
// End Code 3


// Code 4 -- controls pics in header on right side of banner
function callFadeOut4 () {
	window.setTimeout("fadeOut(\"thephoto4\",100)",9500);
} // end function

function startUpRotation4() {
	imageId = 'thephoto4';
	document.getElementById("Ads").innerHTML="<img src='images/rotation/"+imageLocations4[currentImg4]+"' alt='Photo' name=\"thephoto4\" id='thephoto4' />";
	currentImg4++;
	if (currentImg4>=imageLocations4.length) {currentImg4=0}
	window.setTimeout("startUpRotation4()", 11100);
	callFadeOut4 ()
	initImage4();
} // end function

function initImage4() {
  imageId = 'thephoto4';
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
}
// End Code 4


function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;

  if (document.getElementById) {
	  // IE/Win
	  obj.style.filter = "alpha(opacity:"+opacity+")";

	  // Safari<1.2, Konqueror
	  obj.style.KHTMLOpacity = opacity/100;

	  // Older Mozilla and Firefox
	  obj.style.MozOpacity = opacity/100;

	  // Safari 1.2, newer Firefox and Mozilla, CSS3
	  obj.style.opacity = opacity/100;
	}
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity < 100) {
      setOpacity(obj, opacity);
      opacity += 5;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 75);
    }
  }
}
function fadeOut(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity > 0) {
      setOpacity(obj, opacity);
      opacity -= 5;
      window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 75);
    }
  }
}

function fadeOutFirst(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity > 0) {
      setOpacity(obj, opacity);
      opacity -= 5;
      window.setTimeout("fadeOutFirst('"+objId+"',"+opacity+")", 75);
    } // end if
	else {
		switch (objId) {
			case "thephoto0": startUpRotation0(); break;
			case "thephoto1": startUpRotation1(); break;
			case "thephoto2": startUpRotation2(); break;
			case "thephoto3": startUpRotation3(); break;
			case "thephoto4": startUpRotation4(); break;
		} // end switch
	} // end else
  } // end if
} // end function



