﻿// default values
var imgId = null;
var photos = new Array();
var maxPhotos = 0;
var x = 0;
var showTime = 10000;
var t = setTimeout('',0);
var dataValueClass = "bannerDataPath";

// get elements by class name
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};

// initialize
function bannerInit(id)
{
	imgId = id;
	var images = document.getElementsByClassName(dataValueClass);
	if(images != null)
	{
		maxPhotos = images.length;
		for(var i = 0; i < images.length; i++)
		{
			photos[i] = images[i].innerHTML;
		}
	}
	if(maxPhotos > 0)
	{
		nextPhoto();
	}
}

// swap photo
function nextPhoto()
{
	if(document.all) // IE-only fade transition
	{
		document.getElementById(imgId).style.filter = "blendTrans(duration=1)";
		document.getElementById(imgId).filters.blendTrans(duration = 1).Apply();
		document.getElementById(imgId).filters.blendTrans.Play();
	}
	document.getElementById(imgId).src = photos[x];
	inTime();
}

// timed function
function inTime()
{
	x = x + 1;
	if(x >= maxPhotos)
	{
		x = 0;
	}
	t = setTimeout("nextPhoto();",showTime);
}
