// 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/franklin_guesthouse1.jpg";
HTMLArray[2] = "rotator/franklin_guesthouse2.jpg";
//HTMLArray[3] = "4.jpg";

CaptionArray[0] = "Family, Morale, Welfare and Recreation... <br>For All of Your Life.";
CaptionArray[1] = "Franklin Guesthouse has recently renovated its rooms.";
CaptionArray[2] = "Over $50,000 was spent recently on renovating <br>Franklin Guesthouse.";
//CaptionArray[3] = "Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum .";

/*#####################################################################################################*/

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)
}
