/*  Hitting Illustrated JavaScript: Display Random Clips  */

allClips = new Array( "products/infiniTee/itT.gif",
			"products/handsBackHitter/hbhT.gif",
			"products/personalPitcher/ppT.gif",
			"products/grobat/gbT.gif",
			"products/battingGloves/bg.gif",
			"products/webGlov/wg.gif",
			"products/homeHittingLab/hhl.gif" );
			
allPaths = new Array( "products/infiniTee/",
			"products/handsBackHitter/",
			"products/personalPitcher/",
			"products/grobat/",
			"products/battingGloves/",
			"products/webGlov/",
			"products/homeHittingLab/" );
			
allLinks = new Array( "Infini-TEE",
			"Hands Back Hitter",
			"Personal Pitcher",
			"GroBat",
			"SPC Batting Gloves",
			"&nbsp;WebGlov",
			"Home Hitting Lab" );
			
displayIndexes = new Array(null, null, null, null);


function displayClips()
{
	var clipTag;
	var linkTag;
	for (i=0; i<displayIndexes.length; i++)
	{
		clipTag = document.getElementById("RandomClip" + i);
		clipTag.className = "Random";
		clipTag.src = allClips[ displayIndexes[i] ];
		clipTag.alt = allLinks[ displayIndexes[i] ];
		
		linkTag = document.getElementById("RandomLink" + i);
		linkTag.href = allPaths[ displayIndexes[i] ];
		linkTag.innerHTML += allLinks[ displayIndexes[i] ];
	}
}


function randomClips()
{
	var length = allClips.length - 1;
	var index = Math.round( length * Math.random() );
	var i=1;
	var j=0;
	var found = false;
	displayIndexes[0] = 0;
	while (i<displayIndexes.length)
	{
		for (j=0; j<=i; j++)
		{
			if (index == displayIndexes[j])
			{
				found = true;
				break;
			}
		}
		if (!found)
		{
			displayIndexes[i] = index;
			i++;
		}
		index = Math.round( length * Math.random() );
		found = false;
	}	
	displayClips();
}


addEvent(window, "load", randomClips);
removeEvent(window, "unload", randomClips);
