/* Javascript written by:
Mike McIntire

McIntire Media
Marketing & Branding
Web Development & Design
Photography and more
Free to use with these credits intact
*/

	
	//These elements are set by the user. 
	var totalElements=3; 				//number of photos and words used
	var maxPhotos=3; 					//maximum number of photos available
	var maxWords=3;					//maximum number of words available
	
	var altText=new Array();
	
	altText[0]="a0";
	altText[1]="a1";
	altText[2]="a2";
	altText[3]="a3";
	altText[4]="a4";
	altText[5]="a5";
	altText[6]="a6";
	altText[7]="a7";
	altText[8]="a8";
	altText[9]="a9";
	altText[10]="a10";

	//Functions and arrays for chosing random elements and storing them.
	var photosUsed=new Array(); 		//remember the photos used 
	var wordsUsed=new Array();			//remember words used
	function chooseRandom(maxElement)
	{
		//chose the random element based on max number available
		elementPicked = Math.floor(Math.random()*maxElement);
		return elementPicked;	
	}
	
	function isUsed(writeTo,elementPicked)
	{
		//Checks the specified array "writeTo" for the random # "elementPicked"
		var used=false;				//Trigger for a used element
		var j=1;					//just a counter
		
		while (j<=eval(writeTo).length) {	
		//check the array to see if the element has been chosen before
		
			if (elementPicked==eval(writeTo)[j]){
				used=true;			//if found, make note of it
			}
			j++;
		}
		return used;
	}	
	
	function buildElementArrays(elementArray,max) 
	{
		//Populates the arrays of graphics to use
		var i=1;
		while (i<=totalElements) 
		
		{
			var chosenElement = chooseRandom(max);		//pick an element
			//has it been used?
			if (isUsed(elementArray,elementPicked)==false)
			{
				//not used? Store it.
				eval(elementArray)[i]=chosenElement;
				i++;
			}
		}
	}
	
	//build the arrays we'll need.
	buildElementArrays('wordsUsed',maxWords);
	buildElementArrays('photosUsed',maxPhotos);
		
	
	function doIt()
	{
		var k=1;
		var headerGraphic='';
		while (k<=totalElements)
		{
		
			
			headerGraphic = headerGraphic + '<img src="i/p'+photosUsed[k]+'.jpg" alt=""/>';
			headerGraphic = headerGraphic +'<img src="i/w' + wordsUsed[k]+'.jpg" alt="' + altText[eval(wordsUsed[k])] + '"/>';
			k++;
		}
		document.write(headerGraphic);
		}
