var linkNameId = "dynamicTabImageLink";
var imageMainId = "dynamicTabMainImage";


var x = -1;
var globalAutoSwitch = 1; // mean on, 0 off
/*

//SPECIFY THESE IN MAIN FILE!!!!!

var tabCount = 3;

var imagesAndLinks = Array(tabCount);
imagesAndLinks[0] = Array(5);
imagesAndLinks[0][0] = "images/index/newfeat19.jpg";
imagesAndLinks[0][1] = "xml/wwe/wwe2.html";
imagesAndLinks[0][2] = "images/index/tab1.jpg";
imagesAndLinks[0][3] = "images/index/tab1_e.jpg";
imagesAndLinks[0][4] = "tabNum1";

imagesAndLinks[1] = Array(5);
imagesAndLinks[1][0] = "images/index/newfeat20.jpg";
imagesAndLinks[1][1] = "xml/life_cycle/life_cycle2.html";
....
*/

var lastItems = new Array(tabCount - 1);
var imagesMain = new Array(tabCount);
var imagesTop = new Array(tabCount);
var imagesBottom = new Array(tabCount);

// Fill showed array -->
for(x = 0; x < tabCount; ++x)
	lastItems[x] = -1;
// END -->

// Preload images -->
for(x = 0; x < tabCount; ++x)
{
	imagesMain[x] = new Image();
	imagesMain[x].src = imagesAndLinks[x][0];
}

for(x = 0; x < tabCount; ++x)
{
	imagesTop[x] = new Image();
	imagesTop[x].src = imagesAndLinks[x][2];
}

for(x = 0; x < tabCount; ++x)
{
	imagesBottom[x] = new Image();
	imagesBottom[x].src = imagesAndLinks[x][3];
}
// END -->

var globalAutoSwitch = 1;
var global2ndLastIndex = -1;
var global1stLastIndex = -1;

function isIEAgent()
{
	if(navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Opera") == -1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function showImage(index,firstTime)
{
	//document.writeln("here1!");
	if(firstTime == 1)
	{
		if(isIEAgent())
		document.writeln("<a id=\""+linkNameId+"\" href=\""+imagesAndLinks[index][1]+"\"><img id=\""+imageMainId+"\"style=\"border-style: none; display: block; margin-top: -5px; margin-bottom: 0px;\" src=\""+imagesAndLinks[index][0]+"\"/></a>");
		else
		document.writeln("<a id=\""+linkNameId+"\" href=\""+imagesAndLinks[index][1]+"\"><img id=\""+imageMainId+"\"style=\"border-style: none; display: block; margin-top: -5px; margin-bottom: 0px;\" src=\""+imagesAndLinks[index][0]+"\"/></a>");
	}
	else
	{
		if(isIEAgent())
			document.images(imageMainId).src = imagesMain[index].src;
		else
			document.images[imageMainId].src = imagesMain[index].src;
		if(isIEAgent())	
			document.links(linkNameId).setAttribute("href", imagesAndLinks[index][1]);
		else
			document.links[linkNameId].setAttribute("href", imagesAndLinks[index][1]);
		
		var z = 0;
		for(;z < tabCount;++z)
		{
			var tabImg = imagesTop[z];
			if(index == z) tabImg = imagesBottom[z];
			
			if(isIEAgent())
				document.images(imagesAndLinks[z][4]).src = tabImg.src;
			else
				document.images[imagesAndLinks[z][4]].src = tabImg.src;
		}
	}
	
	if(firstTime == 1)
	{
		var z = 0;
		for(;z < tabCount; ++z)
		{
			if(z == index)
				document.writeln("<a href=\""+imagesAndLinks[z][1]+"\"><img style=\"margin-left: -1px;\" border=\"0\" id=\""+imagesAndLinks[z][4]+"\" onMouseOver=\"globalAutoSwitch = 0; showImage("+z+",0);\" src=\""+imagesAndLinks[z][3]+"\" align=\"right\"/></a>");
			else
				document.writeln("<a href=\""+imagesAndLinks[z][1]+"\"><img style=\"margin-left: -1px;\" border=\"0\" id=\""+imagesAndLinks[z][4]+"\" onMouseOver=\"globalAutoSwitch = 0; showImage("+z+",0);\" src=\""+imagesAndLinks[z][2]+"\" align=\"right\"/></a>");
		}
	}
}


function switchImage()
{
	//document.writeln("here2!");
	if(lastItems[0] != -1 && globalAutoSwitch != 1)
	{
		return;
	}

        while(1)
        {
        	var ranNumber= Math.floor(Math.random()*(tabCount-0.01));
        	
        	if(lastItems[0]  == -1)
        	{
        		lastItems[0] = ranNumber;
                	showImage(ranNumber,1);
                	break;
                }
                else
                {
                	var found = 0;
                	var k = 0;
                	for(;k < (tabCount-1); ++k)
                	{
                		if(ranNumber == lastItems[k])
                			found = 1;
                	}
                	if(found == 0)
                	{
                		k = 0;
                		for(;k < tabCount-1; ++k)
                		{
                			lastItems[k+1] = lastItems[k];
                		}
                		lastItems[0] = ranNumber;
                		
                		showImage(ranNumber,0);
                		break;
                	}
                }
        }
}

switchImage();
setInterval("switchImage()",3200);


