// JavaScript Document
var TimeInterval = 5000;
var BlendSpeed = 500;
var RotateOn;
var CaptionOn;
var FadeOn;
var CurrentIndex = 0;
var RotatingContainerId;
var RotatingCaptionId;
var HTMLArray = new Array();
var CaptionArray = new Array();
var RotateTimer;

//HTMLArray[0] = "<p><img src='1.jpg'></img></p>";
//HTMLArray[1] = "<p><img src='2.jpg'></img></p>";
//HTMLArray[2] = "<p><img src='3.jpg'></img></p>";
//HTMLArray[3] = "<p><img src='4.jpg'></img></p>";

HTMLArray[0] = "rotator/1.jpg";
HTMLArray[1] = "rotator/KL CYSS ArmyBday08.JPG";
HTMLArray[2] = "rotator/KL CYSS Builders.JPG";
HTMLArray[3] = "rotator/KL CYSS FirePrevention.JPG";
HTMLArray[4] = "rotator/KL CYSS MOMCBubble08.JPG";

HTMLArray[5] = "rotator/KL CYSS Skies Flute1.JPG";
HTMLArray[6] = "rotator/KL CYSS Skies TKD.JPG";
HTMLArray[7] = "rotator/KL CYSS Skies TKD1.JPG";
HTMLArray[8] = "rotator/KL CYSS Skies Flute2.JPG";
HTMLArray[9] = "rotator/KL CYSS Skies TKD2.JPG";
HTMLArray[10] = "rotator/KL CYSS Skies TKD3.JPG";

HTMLArray[11] = "rotator/SAS_summercamp.jpg";
HTMLArray[12] = "rotator/kleber_cdc2.jpg";
HTMLArray[13] = "rotator/MCDC_truck.jpg";
HTMLArray[14] = "rotator/soldier.jpg";
HTMLArray[15] = "rotator/LCDC_Storytime.jpg";
HTMLArray[16] = "rotator/SAS_cookingclub.jpg";

CaptionArray[0] = "Family, Morale, Welfare and Recreation... <br>For All of Your Life.";
CaptionArray[1] = "The Garrison Commander reads to children during the <br>2008 Army Birthday Celebration.";
CaptionArray[2] = "CYSS offers opportunities in educational fun.";
CaptionArray[3] = "Children learn about fire prevention and safety during <br>Fire Prevention Week.";
CaptionArray[4] = "Month of the Military Child Celebration, 2008.";
CaptionArray[5] = "Kasey Phillips, instructor, provides flute lessons at the Middle School Teen Program.";
CaptionArray[6] = "Taekwondo Instructor Master Park provides a demo class, in which children as young as 5 years old can participate.";
CaptionArray[7] = "Adia Dobbs demonstrates her Taekwondo skills <br>with her father.";
CaptionArray[8] = "Flute lessons are one of many activities offered by the CYSS SKIES Unlimited program.";
CaptionArray[9] = "A Taekwondo student jumps over 3 participants and <br>breaks a board with his foot upon landing.";
CaptionArray[10] = "Taekwondo Girls: Darian Dobbs, Taylor Dobbs, Adia Dobbs.";

CaptionArray[11] = "SAS Summer Camp is always a hit!";
CaptionArray[12] = "At Kleber CDC, we offer a varitey of fun activities which help children develop physically, socially and emotionally.";
CaptionArray[13] = "Children of the Miesau CDC enjoy a day of activities and fun in celebration of the Army Birthday.";
CaptionArray[14] = "There are lots of volunteer opportunities available at SAS.";
CaptionArray[15] = "Army Birthday Story time with Chaplain McCoy <br>at Landstuhl CDC.";
CaptionArray[16] = "The cooking club is one of many popular SAS activities.";


/*#####################################################################################################*/

function RotateContent(ContainerId, CaptionId, pRotateOn, pCaptionOn, pFadeOn)
{
	RotatingContainerId = ContainerId;	
	RotatingCaptionId = CaptionId;
	RotateOn = pRotateOn;
	FadeOn = pFadeOn;
	CaptionOn = pCaptionOn;
	
	//document.getElementById(RotatingContainerId).innerHTML = HTMLArray[CurrentIndex];
		
	if(RotateOn)
	{
		NextHTML();				
		
		RotateTimer = setTimeout("RotateContent('" + RotatingContainerId + "', '" + RotatingCaptionId + "', "+RotateOn+","+CaptionOn+", "+FadeOn+")", TimeInterval);		
	}
}

function StopRotate()
{
		clearTimeout(RotateTimer);
}

function NextHTML()
{
	//StopRotate();
	//RotateContent('RotatingContainerId ', 'RotatingCaptionId ', RotateOn,CaptionOn);
	
	//alert("CurrentIndex: " + CurrentIndex + "\n" + "Array Length: " + HTMLArray.length);
	CurrentIndex = (CurrentIndex+1) % HTMLArray.length;	
	//alert("CurrentIndex: " + CurrentIndex + "\n" + "Array Length: " + HTMLArray.length);
	
	if(FadeOn)
		blendimage("blenddiv","blendimg",HTMLArray[CurrentIndex],BlendSpeed);
	else
		document.getElementById("blenddiv").innerHTML = "<img src='"+HTMLArray[CurrentIndex]+"' />";
		//document.getElementById(imageid).src = imagefile;
	
	if(CaptionOn)
		document.getElementById(RotatingCaptionId).innerHTML = CaptionArray[CurrentIndex];
		
}

function PrevHTML()
{
	//alert("CurrentIndex: " + CurrentIndex);

	if(CurrentIndex == 0)
	{
		CurrentIndex = HTMLArray.length-1;		
	}
	else
	{
		//alert("CurrentIndex: " + CurrentIndex + "\n" + "Array Length: " + HTMLArray.length);
		CurrentIndex = (CurrentIndex-1) % HTMLArray.length;	
		//alert("CurrentIndex: " + CurrentIndex + "\n" + "Array Length: " + HTMLArray.length);		
	}

	if(FadeOn)
		blendimage("blenddiv","blendimg",HTMLArray[CurrentIndex],BlendSpeed);
	else
		document.getElementById("blenddiv").innerHTML = "<img src='"+HTMLArray[CurrentIndex]+"' />";
	
	if(CaptionOn)
		document.getElementById(RotatingCaptionId).innerHTML = CaptionArray[CurrentIndex];
		
}

/*###################################################################################################*/

//this function courtesy of http://www.brainerror.net/scripts_js_blendtrans.php
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//this function courtesy of http://www.brainerror.net/scripts_js_blendtrans.php
//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

//this function courtesy of http://www.brainerror.net/scripts_js_blendtrans.php
function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

//this function courtesy of http://www.brainerror.net/scripts_js_blendtrans.php
function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

//this function courtesy of http://www.brainerror.net/scripts_js_blendtrans.php
function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}