var checkImage = [];
var theIndicator = 0; // pfft. Play with the fools.

/*	There MUST be a description for each and every image stored within the descriptionText array (below).
	With no associated text here, the image won't be used at all in the site, unless you HREF it.
	
    ** 	Ensure you increment the value within the square brackets, for each new image.
 
	** 	Don't use double quotes inside the description, or the site will break.
	
	** 	New image file names must conform to the format below:
		1)	"tiny-[number].jpg" images must be exactly 50 pixels tall but are free width.
		2)	"af-[number]-sml.jpg" images must be 180 pixels wide, but have free height.
		3)	"af-[number].jpg" images should be between 600 and 1000 pixels wide.
		
		The numbers must increment sequentially, and descriptionText numbers must match
		image numbers for the site to work correctly.
*/

var descriptionText=new Array();
	descriptionText[1]="Alison Wilson, Embroiderer and partner at Artisan Fibres";
	descriptionText[2]="The Arts Center in Chriscthurch, and entrance to Artisan Fibres";
	descriptionText[3]="Beatiful little pin cushions and scissor keepers";
	descriptionText[4]="Luscious hand-dyed New Zealand merino yarn";
	descriptionText[5]="Green hand-woven ruana by Valerie";
	descriptionText[6]="The famous Arts Center Cloisters. The flagstones are worn smooth here by millions of feet.";
	descriptionText[7]="Permanent art works at the Arts Center: The Court Jester.";
	descriptionText[8]="Shocking-pink and silver-grey hand-dyed silk scarf by Pippa.";
	descriptionText[9]="Pippa Davies, Embroiderer & Dyer and partner at Artisan Fibres";
	descriptionText[10]="Brightly coloured hand-dyed silk scarf by Pippa. Around $100";
	descriptionText[11]="Lovely little evening clutch purse by Alison";
	descriptionText[12]="A delightfull small shoulder purse by Alison";
	descriptionText[13]="Barbara Wendelken, Patchworker & Quilter, and partner at Artisan Fibres";
	descriptionText[14]="Small shoulder purse by Barbara";
	descriptionText[15]="Products on display at the store.";
	descriptionText[16]="Another of Pippa's delightful hand-dyed silk scarves";
	descriptionText[17]="Selection of wonderful hand-woven woollen scarves by Ria";
	descriptionText[18]="Ria van Lith, Weaver, Spinner & Knitter and partner at Artisan Fibres";
	descriptionText[19]="Charming little character doll by Catherine Bell";
	descriptionText[20]="We have a wide selection of hand-dyed Merino yarns. These examples are by Margaret Stove.";
	descriptionText[21]="An elegant knitted Jacket by Betty Abbott";
	descriptionText[22]="Bright and bold hand-dyed embroidery yarns by Jane van Keulen";
	descriptionText[23]="Playful and fun brooches by Catherine Bell";
	descriptionText[24]="One of Valerie's wonderfully textured and very fine, hand-woven scarves";
	descriptionText[25]="Valerie Osborn, Spinner, Designer & Weaver and partner at Artisan Fibres";
	descriptionText[26]="Another example of the fine hand-woven scarves by Valerie";
	descriptionText[27]="Bright and breezey cushion cover by Alison";
	descriptionText[28]="Cute character doll by Catherine Bell. Bag by Barbara";
	descriptionText[29]="Character doll by Catherine Bell. Bag by Barbara";
	descriptionText[30]="Sensual and stylish hand-made felt hat by Linda Wallace.";
	descriptionText[31]="Another of Catherine Bell's character dolls";
	descriptionText[32]="Lovely hand-worked cushion cover by Alison";
	descriptionText[33]="Character doll by Catherine Bell. Bag by Barbara";
	descriptionText[34]="Beaded evening purse by Alison";
	descriptionText[35]="Beautifully textured hand-made felt hat by Linda Wallace";
	descriptionText[36]="Character doll by Catherine Bell.";
	descriptionText[37]="Detail of ruana and pin by Valerie";
	descriptionText[38]="Assorted silk-fibre Christmas tree decorations from Pippa";
	descriptionText[39]="Detail of felted wool and silk skirt by Shona Schofield";
	descriptionText[40]="Reflecting pool at The Arts Centre";
	descriptionText[41]="Selection of multi-coloured brooches by Alison";
	descriptionText[42]="Fibre-fairy brooches by Catherine Bell";
	descriptionText[43]="Brightly-beaded mask hang-ups by Catherine Bell";
	descriptionText[44]="We often have an assortment of hand-spun wool yarn by Dorothy Dickie";
	descriptionText[45]="Gorgeous layered felt balls and pin cushions by Linda Wallace";
	descriptionText[46]="Detail of ruana and pin by Valerie";
	descriptionText[47]="Spectacle cases by Alison";
	descriptionText[48]="Blue beret by Ria, and black evening bag by Alison, and blue neckpieces by Jillian Johnson";
	descriptionText[49]="Bag by Alison. Neckpieces by Jillian Johnson. Scissor keepers by Alison";
	descriptionText[50]="Character doll by Catherine Bell. Bag by Barbara.";
	descriptionText[51]="Selection of blue and purple hand-dyed silk scarves by Pippa.";
	descriptionText[52]="Hand-knitted berets and scraves by Ria";
	descriptionText[53]="Selection of hand-knitted berets by Ria";
	descriptionText[54]="Selection of large shawls by various AF partners";
	descriptionText[55]="Hand-woven cross-over shawl from Ria";
	descriptionText[56]="Christmas tree decoaryion by Alison";
	descriptionText[57]="Silk and taffeta evening jacket by Jillian Johnson";
	descriptionText[58]="Glass and metallic bead necklace by Betty Abbot";
	descriptionText[59]="Glass and metallic bead necklace by Betty Abbot";
	descriptionText[60]="Necklace by Betty Abbott. Hand-felted silk and wool scarf by Shona Schofield";
	descriptionText[61]="Bag by Barbara";
	descriptionText[62]="Selection of brightly-coloured hats by Linda Wallace";
	descriptionText[63]="Organza neckpiece by Jillian Johnson";
	descriptionText[64]="Embroidered evening shoulder bag by Alison";
	descriptionText[65]="Organza neckpiece by Jillian Johnson";
	descriptionText[66]="7-8cm Felt 'pods' - squeeze to open. By Patricia Took-Stevens";
	descriptionText[67]="Sea-egg and hand-felted Paua shells in hand-made boxes by Patricia Took-Stevens";
	descriptionText[68]="Temari hand-embroidered balls by Lindsey Fenwick";
	descriptionText[69]="Temari hand-embroidered balls by Lindsey Fenwick";
	descriptionText[70]="Little beaded wire hanging by Annette Broadhurst";
	descriptionText[71]="Glass, metal and hand-made beaded necklace by Betty Abbott";
	descriptionText[72]="Evening bag and pincushion set by Alison";
	descriptionText[73]="Paua sheel embellished brooch by Alison";
	descriptionText[74]="Pin cushions by Alison";
	descriptionText[75]="Pin cushions by Pippa, and scarf by Valerie, bag by Barbara, Paua shell necklace by Betty Abbot";
	descriptionText[76]="Beret by Ria with scarves by Pippa. Pin cushion by Alison";
	descriptionText[77]="Traditional gollywog doll by Catherine Bell";
	descriptionText[78]="Orange scarves by Pippa. Woollen scarves by Ria";
	descriptionText[79]="Hand-knitted jackets by Annette Broadhurst";
	descriptionText[80]="Character dolls by Catherine Bell";
	descriptionText[81]="Pin cushions by Pippa. Bag by Barbara";
	descriptionText[82]="Pin cushions by Pippa. Bag by Barbara";
	descriptionText[83]="Pink bag and pin cushion by Alison";
	descriptionText[84]="Arts Center neo-gothic architecture, which is prevalent in Chriscthurch, NZ";
	descriptionText[85]="Hand-knitted cardigan with hand-dyed silk lining by Joy Ashworth";
	descriptionText[86]="Hand-woven woollen little bolero jacket from by Valerie";
	descriptionText[87]="Taffeta evening jacket by Jillian Johnson";
	descriptionText[88]="Detail of pin on felted jacket by Shona Schofield";
	descriptionText[89]="Scarves by Shona Schofield";
	descriptionText[90]="Hand-woven cocoon jacket by Ria";
	descriptionText[91]="Character doll by Catherine Bell";
	descriptionText[92]="Sumptuous scarves by Ria and Pippa";
	descriptionText[93]="A customer examines a range of scarves by Ria and Pippa";
	descriptionText[94]="Character doll by Catherine Bell";
	descriptionText[95]="Selection of goods on display";
	descriptionText[96]="Selection of goods on display";
	descriptionText[97]="Selection of goods on display";
	descriptionText[98]="Selection of scarves by Ria";
	descriptionText[99]="Selection of scarves by Ria";
	descriptionText[100]="Bright orange scarves by Pippa";
	descriptionText[101]="Artisan Fibres store sign";
	descriptionText[102]="Park Terrace looking south-east adjacent the Botanic Gardens";
	descriptionText[103]="Neo-gothic architectural detail at The Arts Center";
	descriptionText[104]="More Arts Center architecture. Much has been done to restore the buildings in recent years";
	descriptionText[105]="Valuted archway details at The Arts Centre, Christchurch";
	descriptionText[106]="The famous 'Dux De Lux' vegetarian restaurant and bar at The Arts Center";
	descriptionText[107]="Lovely detail work in the sandstone at The Arts Centre";
	descriptionText[108]="More neo-gothic architecture, the old University campus is stuffed full of it";
	descriptionText[109]="Copper-coated spire peaks out from between two buildings at The Arts Centre";
	descriptionText[110]="The Canterbury crest over the old university entrance";
	descriptionText[111]="Doesn't seem to concerned about the passage of time!";
	descriptionText[112]="Architectural detail work from a time before labour was expensive";
	descriptionText[113]="Entrance to the old Chemistry block at The Arts Center";
	descriptionText[114]="As well as architecture, many permanent artworks are on display";
	descriptionText[115]="Architectural detail work from a time before labour was expensive";
	descriptionText[116]="Annies' Restaurant and wine bar. Great food and great location";
	descriptionText[117]="A floating whimsy which challenges your persepctive";
	descriptionText[118]="Stained glass windows in the Great Hall at The Arts Centre";
	descriptionText[119]="More modern art adorning The Arts Center";
	descriptionText[120]="Delightful example of some of the stained glass at The Arts Center";
	descriptionText[121]="Main entrance to the old university. Note the worn down step!";
	descriptionText[122]="Zoomed out photo of the main entrance. Rutherford stalked these halls.";
	descriptionText[123]="The Court Theatra at The Arts Centre";
	descriptionText[124]="19th-century Trams cruise slowly up Worcester Boulevard.";
	descriptionText[125]="The interior of the Artisan Fibres store";
	descriptionText[126]="Evening shoulder purse by Alison";
	descriptionText[127]="Little black evening clutch purse by Alison";
	descriptionText[128]="Selection of wool and mohair Touch Yarns";
	descriptionText[129]="Felt cap by Linda Wallace";
	descriptionText[130]="Rainbow scraf by Pippa";
	descriptionText[131]="Mathcing hand-knitted beret and scraf by Ria";
	descriptionText[132]="Hand-woven cocoon jacket, with pin, by Ria";
	descriptionText[133]="Hand-woven Ruana with pin by Valerie";
	descriptionText[134]="Bag by Barbara";
	descriptionText[135]="Bag by Barbara";
	descriptionText[136]="Red Scarves by Pippa";
	descriptionText[137]="Twisted scarves hand-knitted by Barbara";
	descriptionText[138]="Detail of patchwork quilt by Barbara";
	descriptionText[139]="Detail of felted jacket by Betty Abbott";
	descriptionText[140]="Pieced handbag by Alison";
	descriptionText[141]="Beaded scarf pins by Valerie";
	descriptionText[142]="Coccoon by Ria";
	descriptionText[143]="Red Jacket by Jillian Johnson";
	descriptionText[144]="Hand dyed embroidery threads by Jane Van Keulen";
	descriptionText[145]="Gorgeous Orange Hat by Linda Wallace";

// Now set the number of images to the number of descriptionTexts
var totalimages = descriptionText.length - 1; // array is zero-based

function showRandomBanners()
{
	// create an array
	var lottery = new Array();
	// load up incrementing values into the array
	for (i = 0; i < totalimages; i++)
	{
		lottery [i] = i;
	}  
	// cycle through all image numbers
	for (inc = 0; inc < totalimages; inc++)
	{
		// switch around the numbers!
		swap = Math.floor(Math.random()*totalimages); 
		t = lottery [inc];
		lottery [swap] = t; 
		lottery [inc] = swap;
	}
	// now we have our randomised order
	var myOutput = '';
	//create 12 unique image references from the first 12 array items
	for(var i = 0; i <= 12; i++) // 12 images in the banner
	{
		imageNo = (lottery [i]+1);
		//assign a default TITLE attribute
		titleText = "Zoom image number" + imageNo +" in a new window";
		if(descriptionText[imageNo] != "")
		{
			titleText = "Zoom image: " + descriptionText[imageNo];	
		}
		// generate most venerable output!
		myOutput += '<div style="float:left;"><a href="images/af-' + imageNo + '.jpg" target="_blank" title="' + titleText + '"><img src="images/tiny-' + imageNo + '.jpg" border="0" align="left" id="thumb-' + imageNo + '" /></a></div>'
	}
	//Now write the output to the banner
	document.getElementById('randombanner').innerHTML = myOutput;
	//Set the banner background to a random image so the overflow isn't always the same
	document.getElementById('randombanner').style.backgroundImage = "url(images/tiny-" + getRandomImageNumber() + ".jpg)";
}


function getRandomImageNumber()
{
	// Generate random imagenumber based on total number of images
	randomImageNumber = parseInt((Math.random() * totalimages) + 1);
	return randomImageNumber;
}

function navigate(idName)
{
	// You need a comment for this???
	window.location = idName + ".shtml";
}

function rollon(idName)
{
	// navigation onmouseover
	document.getElementById(idName).style.backgroundImage = "url(images/nav-active.gif)";
	document.getElementById(idName+"-right").style.backgroundImage = "url(images/nav-right-active.gif)";
}

function rolloff(idName)
{
	//navigation on mouseout
	document.getElementById(idName).style.backgroundImage = "url(images/nav.gif)";
	document.getElementById(idName+"-right").style.backgroundImage = "url(images/nav-right-inactive.gif)";
}

function showPageLoaded()
{
	//get the page name as a string - not an object
	myPage = document.location + " ";
	try
  	{
		// try to get the string between the last "/" and the last "."
  		pageName = myPage.substring(myPage.lastIndexOf("/") + 1, myPage.lastIndexOf("."));
  	}
	catch(err)
	{
		//failed to get the string. We get signal - WHAT HAPPEN???
	 	alert("I don't seem to be able to find what page you are on, sorry! :-(");
	}
	// The home page may only show the domain name. Catch that happening.
	if(pageName == ".nz/")
	{
		pageName="index";
	}

	try
	//OK we got the string - now try to make the active page show
  	{
		// create an element to re-use
		myElement = document.getElementById(pageName);
		//set the background of the active page to be white
		myElement.style.backgroundImage = "url(images/nav-active.gif)";
		//stick in the tiny indicator image on the right
		document.getElementById(pageName+"-right").style.backgroundImage = "url(images/nav-right-active.gif)";
		//decativate the link on the active page
		myElement.onclick = null;
		//stop all that mouseover mouseout stuff
		myElement.onmousover = null;
		myElement.onmouseout = null;
		myElement.style.cursor = "crosshair";
		// Use TITLE to announce what this is
		myElement.setAttribute('title', 'You are here');
		document.getElementById(pageName+"-right").title = "The orange tab indicates this is the page you are on.";
		// have some potential fun with image clickers. 
		document.getElementById(pageName+"-right").setAttribute("onclick", "indicator()");
	}
	catch(err)
	{
		// Your attempt to display the current page is FAIL!
		alert("I found what page you are on, but my Javascript Code Broke! :-(");
	}
}

function indicator()
{
	// have some fun with the Intertube weirdos
	theIndicator++; // keeps track of number of clicks
	if(theIndicator < 8)
	{
		switch (theIndicator)
		{
			case 1: alert("You CAN click this image, but nothing happens.\n\nNo... Wait....\n\n                                                                  THIS happened!"); break;
			case 2: alert("PLEASE DO NOT CLICK THE IMAGE AGAIN."); break;
			case 3: alert("Funny."); break;
			case 4: alert("Do you think you are getting closer to a prize?"); break;
			case 5: alert("I promise you nothing happens by clicking on this image"); break;
			case 6: alert("Really. Seriously.\n\nNothing."); break;
			case 7: alert("NO - THING!"); break;
			default: alert('Huh?');
		}
	}
	else
	{
		//They persisted, so now it's broken :P
		document.getElementById(pageName+"-right").setAttribute('onclick', '');
		document.getElementById(pageName+"-right").setAttribute('title', '........................................................................................................................................................................................................... ...........................................................................................................................................................................................................');
	}
	
}

function showPartner(theID)
{
	document.getElementById('howto').style.display = "none";
	//show all header divs
	document.getElementById('pippa').style.visibility = "visible";
	document.getElementById('valerie').style.visibility = "visible";
	document.getElementById('barbara').style.visibility = "visible";
	document.getElementById('alison').style.visibility = "visible";
	document.getElementById('ria').style.visibility = "visible";
	//hide all details divs
	document.getElementById('pippa-details').style.display = "none";
	document.getElementById('valerie-details').style.display = "none";
	document.getElementById('barbara-details').style.display = "none";
	document.getElementById('alison-details').style.display = "none";
	document.getElementById('ria-details').style.display = "none";
	
	document.getElementById(theID + "-details").style.display = "block";
	document.getElementById(theID).style.visibility = "hidden";
	
	// Flip top image thumbnails
	showRandomBanners();	
}

function showGallery(startNo, endNo, idNo)
{
	// Set all gallery links to be inactive
	for(i=1; i < 9; i++)
	{
		document.getElementById('gall-' + i).style.backgroundColor = "white";
		document.getElementById('gall-' + i).style.color = "black";
		document.getElementById('gall2-' + i).style.backgroundColor = "white";
		document.getElementById('gall2-' + i).style.color = "black";
	}
	//make active links highlighted at top and bottom of page
	document.getElementById("gall-" + idNo).style.backgroundColor = "#F9740D";
	document.getElementById("gall-" + idNo).style.color = "white";
	document.getElementById("gall2-" + idNo).style.backgroundColor = "#F9740D";
	document.getElementById("gall2-" + idNo).style.color = "white";

	//now sort out the images thumbs and links: how many images are there?
	var counter = endNo - startNo + 1;
	// loop through the range indicated
	for(count=1; count <= counter; count ++)
	{
		// get an item number from the range within the loop
		itemNumber = parseInt(parseInt(startNo)+ parseInt((count-1)));
		// set the box value to empty
		myTextBox = "";
		// check to see if the array is filled for this item
		if(descriptionText[itemNumber] != "")
		{
			// got something - so let's display it with a box attached to the image.
			myTextBox = '<div class="desc">' + descriptionText[itemNumber] + '</div>';
		}
		
		// create the image, link and description text HTML
		theHTML = '<a href="images/af-' + itemNumber + '.jpg" target="_blank" title="Opens in a new window/tab" /><img src="images/af-' + itemNumber + '-sml.jpg" width="180" alt="" class="image" /></a>' + myTextBox;
		
		// Now run through the HTML adding links where the partners names appear, ignoring case 
		theHTML = theHTML.replace(/Pippa Davies/gi,'<a href="artists.shtml?artist=pippa" class="partnerlink">Pippa Davies</a>');
		// leave a space ahead of the first name check - this stops us picking up the one we just did!
		theHTML = theHTML.replace(/ Pippa/gi,' <a href="artists.shtml?artist=pippa" class="partnerlink">Pippa</a>');
		
		theHTML = theHTML.replace(/Ria van Lith/gi,'<a href="artists.shtml?artist=ria" class="partnerlink">Ria van Lith</a>');
		theHTML = theHTML.replace(/ Ria/gi,' <a href="artists.shtml?artist=ria" class="partnerlink">Ria</a>');
		
		theHTML = theHTML.replace(/Valerie Osborn/gi,'<a href="artists.shtml?artist=valerie" class="partnerlink">Valerie Osborn</a>');
		theHTML = theHTML.replace(/ Valerie/gi,' <a href="artists.shtml?artist=valerie" class="partnerlink">Valerie</a>');
		
		theHTML = theHTML.replace(/Barbara Wendelken/gi,'<a href="artists.shtml?artist=barbara" class="partnerlink">Barbara Wendelken</a>');
		theHTML = theHTML.replace(/ Barbara/gi,' <a href="artists.shtml?artist=barbara" class="partnerlink">Barbara</a>');
		
		theHTML = theHTML.replace(/Alison Wilson/gi,'<a href="artists.shtml?artist=alison" class="partnerlink">Alison Wilson</a>');
		theHTML = theHTML.replace(/ Alison/gi,' <a href="artists.shtml?artist=alison" class="partnerlink">Alison</a>');
	
		// write the HTML to the table TD
		document.getElementById(eval(parseInt(count))).innerHTML = theHTML;
	}
	// done writing table TD contents. Now let's tidy up...
	
	// clear any TDs that weren't written into.
	if(counter < 18)
	{
		for(thing = counter + 1; thing <= 18; thing++)
		{
			document.getElementById(thing).innerHTML = "";
		}
	}
	// scroll to the top of the page
	window.scrollTo(0,0);
	//reactivate the page top stuff
	showRandomBanners();
}

function showRequestedGallery()
{
	//get the querystring if there is one
	queryString = unescape(location.search.substr(1));
	// grab the content after the equals sign
	requestedGallery = queryString.substring(queryString.lastIndexOf("=")+1) 
	// run the function according to the requested page. Handle bad input gracefully
	switch (requestedGallery)
	{
		case "1": showGallery(1,18,'1'); break;
		case "2": showGallery(19,36,'2'); break;
		case "3": showGallery(37,54,'3'); break;
		case "4": showGallery(55,72,'4'); break;
		case "5": showGallery(73,90,'5'); break;
		case "6": showGallery(91,108,'6'); break;
		case "7": showGallery(109,126,'7'); break;
		case "8": showGallery(127,141,'8'); break;
		case "": showGallery(1,18,'1'); break;
		default: showGallery(1,18,'1');
	}
}

function showRequestedArtist()
{
	//get the querystring if there is one
	queryString = unescape(location.search.substr(1));
	//strip everything from last "=" onwards
	requestedArtist = queryString.substring(queryString.lastIndexOf("=")+1).toLowerCase();
	// run the function according to the artist's name
	switch (requestedArtist)
	{
		case "pippa": showPartner("pippa"); break;
		case "ria": showPartner("ria"); break;
		case "alison": showPartner("alison"); break;
		case "barbara": showPartner("barbara"); break;
		case "valerie": showPartner("valerie"); break;
		case "": break;
		// fail badly
		default: alert("Huh? I'm sorry, but I do not know what to do with your garbled input.\n\nAre you trying to break this page?");
	}
}

function decloak(CloakedEmail, subject, name)
{
	// Magic to replace # with @ and $ with.
	var thing
	thing = CloakedEmail.replace('#','@').replace(/\$/g,'.')+ '?subject=' + subject;
	thing = '<a href="mailto:'+ thing +  '" class="emaillink" title="Had to hide e-mail links from spambots!">' + name + '</' + 'a>';
	return thing;
}
























