/* Function to declare the totals number of images and thumbnails per page as global variables */
// Maintenance (i.e. when a new pic is added)
// 1) Add new imagetext[x] arrayitem
// 2) Add pet_thumbx.gif (~100x75)
// 3) Add petx.jpg (300px wide)
// 4) Update home.js (where m==1) for front page

function get_totals() {
	imagetext=new Array()		    /* Declare text in Array for each picture */
	imagetext[-5] = "Dummy entry there is no dog -5";
	imagetext[-4] = "Dummy entry there is no dog -4";
	imagetext[-3] = "Dummy entry there is no dog -3";
	imagetext[-2] = "Dummy entry there is no dog -2";
	imagetext[-1] = "Dummy entry there is no dog -1";
	imagetext[0] = "Dummy entry there is no dog 0";
	imagetext[1] = "Ruby (Vandells Quick Step) - Owned by Mrs Jones";
	imagetext[2] = "Ruby (Vandells Quick Step) - Owned by Mrs Jones";
	imagetext[3] = "Jake (Miccosukees Loose Talk) - Owned by Mrs Jones";
	imagetext[4] = "Guinness - Owned by Rogelio Aguilar in Mexico";
	imagetext[5] = "Guinness - Owned by Rogelio Aguilar in Mexico";
	imagetext[6] = "Archie - Owned by Anna Denham";
	imagetext[7] = "Archie - Owned by Anna Denham";
	imagetext[8] = "Kai (Aust Ch Wojewoda Hot Shot) - Owned by Karin Maxwell";
	imagetext[9] = "Yachtie & Ashlea - Owned by Doug Cameron";
	imagetext[10] = "RC - Owned by Doug Cameron";
	imagetext[11] = "Poppy (Upperdeck Sea Interlude at Compro) - Owned by Genevieve Pearson";
	imagetext[12] = "Charlie - Owned by Siobhan Wilkinson";
	imagetext[13] = "Charlie - Owned by Siobhan Wilkinson";
	imagetext[14] = "Lunar - Owned by Lou & Ginger Calebrese in Atlanta Georgia";
	imagetext[15] = "Zen, Zak & Angus on Eastbourne beach - Owned by Alison Roberts";
	imagetext[16] = "Maxwell - Owned by Pete Bradshaw";
	imagetext[17] = "Maisie - Owned by Carolyn Cable";
	imagetext[18] = "Maisie - Owned by Carolyn Cable";
	imagetext[19] = "Ella & Dexter - Owned by Dan & Toni James";
	imagetext[20] = "Tilly (Valencris Mystic Matilda) - Owned by Louise Grocott";
	imagetext[21] = "Tilly (Valencris Mystic Matilda) - Owned by Louise Grocott";
	imagetext[22] = "Tilly (Valencris Mystic Matilda) - Owned by Louise Grocott";
	imagetext[23] = "Arnie - Owned by Christine Steel";
	imagetext[24] = "Arnie - Owned by Christine Steel";
	imagetext[25] = "Dylan - Owned by Momin Soliman";
	imagetext[26] = "Trudi, Kate & Jade - Owned by Jenny Richardson";
	imagetext[27] = "Talen - Owned by Deborah Jane Allen";
	imagetext[28] = "Zak (Cantebaru Ready For Freddie) - Owned by Jason Varley";
	imagetext[29] = "Jack (Godheim Ben Hur) - Owned by Pamela De Blasio";
	imagetext[30] = "Gus & Siggy - Owned by Linda Collie";
	imagetext[31] = "Oscar & Ollie - Owned by Caroline Freedman";
	imagetext[32] = "George (Rillaton Truth or Dare) - Owned by Angela Fletcher";
	imagetext[33] = "Trever (Westbridge Schabernack)";
	imagetext[34] = "Amos (Elljaye Good Runner ) - Owned by Gill Hamilton";
	imagetext[35] = "Micha (Rimmick Real Stunner) - Owned by Carole Chesterfield";
	imagetext[36] = "Festus Derriman - Owned by Marie & David King";
	imagetext[37] = "Otto - Owned by Angela Fletcher";
	imagetext[38] = "Pia - Owned by Harald Osmundsen in Oslo";
	imagetext[39] = "Amy - Owned by Meg Shortland";
	imagetext[40] = "Bilbo & Mitzy - Owned by Samantha & Lee Davies";
	imagetext[41] = "Rosie (Ebenholz Laura Norder) - Owned by Chris Browse";
	imagetext[42] = "George & Otto - Owned by Angela Fletcher";
	imagetext[43] = "Otto - Owned by Sophie Davidson";
	imagetext[44] = "Toby - (Minalsa Making Magic) Owned by Robert Jones";
	imagetext[45] = "Eddie - Owned by Jayne Owen";
	imagetext[46] = "Eddie - Owned by Jayne Owen";
	imagetext[47] = "Festus (Mini) & Carpenter (Giant) - Owned by David & Marie King";
	imagetext[48] = "Brodie - Owned by Julie & Michael Smith";
	imagetext[49] = "Buster - Owned by Angela Baxter";
	imagetext[50] = "Kate - Owned by Ethan Robson";
	imagetext[51] = "Stanley - Owned by Simon Pearson";
	imagetext[52] = "Errol & Max - Owned by Alison Dunsmore";
	imagetext[53] = "Bear - Owned by Ainsley Herd in Australia";
	imagetext[54] = "Kizzy - Owned by Viv Middleton";
	imagetext[55] = "Mady - Owned by Gary Mcquillan";
	imagetext[56] = "Pero - Owned by Brian & Marilyn Erbe";
	imagetext[57] = "Paddy, Harvey, Monty, Sammy, Teddy & George. - Owned by Bob & Leigh Russell";
	imagetext[58] = "Oscar - Owned by David & Judith Henderson";
	imagetext[59] = "Dillon - Owned by Marion Elvin";
	imagetext[60] = "Paddy & Monty - Owned by Bob & Leigh Russell";
	imagetext[61] = "Brodie & Dylan - Owned by Julie Smith";
	imagetext[62] = "Pepper & Salt & White litter puppies - Owned by Brian & Joan Braybrooke";
	imagetext[63] = "Tia - Owned by Janet Revis";
	imagetext[64] = "Dylan & Hugo - Owned by Rob Benton";
	imagetext[65] = "Lucy - Owned by Kylie Wilkins";
	imagetext[66] = "Chester - Owned by Tracey Farrimond";
	imagetext[67] = "Bosley - Owned by Jenny Thompson";
	imagetext[68] = "Asti - Owned by Alison Jordan";
	imagetext[69] = "Max - Owned by Paula Heywood";
	imagetext[70] = "Lacey & Alfie - Owned by Heather Glass";
	imagetext[71] = "Asterix - Owned by Elme Marais";
	imagetext[72] = "Ellie - Owned by Liz Webster";
	imagetext[73] = "Snazzie - Owned by Margret Banks";
	imagetext[74] = "Shona - Owned by Margret Banks";
	imagetext[75] = "Freddie - Owned by Kevin & Jeanette Jackson";
	imagetext[76] = "Ellie - Owned by Liz Webster";
	imagetext[77] = "Kitty - Owned by Pat Heesom";
	imagetext[78] = "Reggie - Owned by Sherry Knight";
	imagetext[79] = "Kaiser - Owned by Kelly Birch-Machin";
	imagetext[80] = "Bonnie - Owned by Heather & Alistair Browne";
	imagetext[81] = "Mitzi - Owned by Peter Hey";
	imagetext[82] = "Wilson - Owned by The Jenkins Family";
	imagetext[83] = "Mitzy & Bilbo - Owned by Samantha & Lee Davies";
	imagetext[84] = "Eddy - Owned by James and Lewis Moor";
	imagetext[85] = "Jess - Owned by Iain Speers";
	imagetext[86] = "Lily & Wilson - Owned by the Jenkins Family";
	imagetext[87] = "Three Giants - Owned by Elizabeth Lewis-Cracknell";
	imagetext[88] = "Shona - Owned by Margret Banks";
	imagetext[89] = "Shona - Owned by Margret Banks";
	imagetext[90] = "Spinner - Owned by Charlotte Sayer";
	imagetext[91] = "Toby (Minalsa Making Magic) - Owned by Rob Jones";
	imagetext[92] = "Junior - Owned by Roland Richardson";
	imagetext[93] = "Cleo - Owned by Donna Jones & Sean Hinsley";
	imagetext[94] = "Lily & Wilson - Owned by the Jenkins Family";
	imagetext[95] = "Suky - Owned by Tom Barnes";
	imagetext[96] = "Truffles - Owned by Hannah Chapman";
	imagetext[97] = "Bosley - Owned by Jenny Thompson";
	imagetext[98] = "Sidney - Owned by Harriet Wheeler";
	imagetext[99] = "Heidi - Owned by Ashley Watson";
	imagetext[100] = "Alfie - Owned by Patricia Huws";
	imagetext[101] = "Fritz - Owned by Louise Mallard";
	imagetext[102] = "Cleo - Owned by Sean Hinsley & Donna Jones";
	imagetext[103] = "Gajit - Owned by Alison Roberts and Marylin Erbe";
	imagetext[104] = "Archie - Owned by Lizzie Childes";
	imagetext[105] = "Max - Owned by Mrs E Silverthorne";
	imagetext[106] = "Otto & Connie - Owned by Stuart Arch & Caroline Simmons";
	imagetext[107] = "Mookie - Owned by Olivia Robinson";
	imagetext[108] = "Kobi & Ozzie - Owned by Simon and Linda Gill";
	imagetext[109] = "Ozzie - Owned by Simon and Linda Gill";
	imagetext[110] = "Sydney - Owned by Mrs C Farrington";
	imagetext[111] = "Rocket - Owned by Hannah and James Guy";
	imagetext[112] = "Smithy - Owned by Mark and Alison Gladding";
	imagetext[113] = "Heidi - Owned by Donna Jones";
	imagetext[114] = "Otto (left) - Owned by Stuart Arch and Caroline Simmons. Heidi (right) - Owned by Donna Jones";
	imagetext[115] = "Gem - Owned by Karen Wiles";
    
    thumbs_per_page = 6;                // Thumbnails per page
    total_thumbs=imagetext.length;      // Find total number of thumbnails
    total_thumbs--;
    document.getElementById("petcount").innerHTML = "There are "+total_thumbs+" pets to view in Pets Corner";
    
	pointer=total_thumbs;          // Initialise pointer = Start position of next thumb
	direction = "Fwd";             // Initialise direction
	image_counter=thumbs_per_page; // Initialise number of images on display
	}

/* Function to page Forward (2) or Back (1)*/
function newpage(page){
	if (page == 1){
		direction = "Back";
		if (last_direction == "Fwd"){		/* Re initialise pointer if you change direrction */
			pointer=pointer+thumbs_per_page+1;
			}
		if (pointer < total_thumbs){
			get_thumbs();			/* Run the function to display the next lot of thumbnails */
			}
		else {
			window.alert("You are at the beginning you can only go forward");
			}
		}
	
	if (page == 2){
		direction = "Fwd";
		if (last_direction == "Back"){		/* Re initialise pointer if you change direrction */
			pointer=pointer-thumbs_per_page-1;
			}
		if (pointer > 0){
			get_thumbs();			/* Run the function to display the next lot of thumbnails */
			}
		else {
			window.alert("You are at the end you can only go backward");
			}
		}
	}

/* Function to get the text when mouse hovers over each thumbnail */
function getinfo(x){
	if (direction == "Fwd") {
		p = pointer+x+1;
		}
	if (direction == "Back") {
		p = pointer-thumbs_per_page+x;
		}
	document.getElementById("hovertext").innerHTML = imagetext[p];
	}

/* Function to get the real image for each thumbnail */
function get_image(y){
	SetupPaths();
	if (direction == "Fwd") {
		i = pointer+y+1;
		}
	if (direction == "Back") {
		i = pointer-thumbs_per_page+y;
        }
    if (i <= 61){                       /* Pet61 and below are .GIFs */
    	imagename = "pet" + i + ".gif";
        }
    if (i > 61){                        /* Pet62 and above are .JPGs */
    	imagename = "pet" + i + ".jpg";
        }
	document.images['imagecell'].src = WebRoot+"/images/petscorner/"+imagename;
	document.getElementById("fixedtext").innerHTML = imagetext[i];
	}

/* Function to get the thumbnails and display the most recent first. Run ON-LOAD of the web-page
   and called whenever the Back or Forward buttons are pressed  */

function get_thumbs(){
	SetupPaths();
	/* Clear 6 thumbnail place holders */
	document.images['sorttext0'].src = "spacer.gif";
	document.images['sorttext1'].src = "spacer.gif";
	document.images['sorttext2'].src = "spacer.gif";
	document.images['sorttext3'].src = "spacer.gif";
	document.images['sorttext4'].src = "spacer.gif";
	document.images['sorttext5'].src = "spacer.gif";

	if (direction == "Fwd") {			/* Page Forward */
		if (pointer >= total_thumbs) {
			pointer=total_thumbs;		/* Point to next image to display */
			image_counter=thumbs_per_page;	/* Reset image_counter */
			}
		dest_pointer = pointer-image_counter;
		
		image_counter = 0;
		for (z=pointer;z>=dest_pointer+1;z--){	/* Display Thumbnails */
			if (z==0){break;}
			switch (z) {
				case pointer : 
				document.images['sorttext5'].src = WebRoot+"/images/petscorner/pet_thumb" + z + ".gif";
      				break; 
				case pointer-1 : 
			      	document.images['sorttext4'].src = WebRoot+"/images/petscorner/pet_thumb" + z + ".gif";
      				break; 
   				case pointer-2 : 
			      	document.images['sorttext3'].src = WebRoot+"/images/petscorner/pet_thumb" + z + ".gif";
      				break; 
   				case pointer-3 : 
			      	document.images['sorttext2'].src = WebRoot+"/images/petscorner/pet_thumb" + z + ".gif";
      				break; 
   				case pointer-4 : 
			      	document.images['sorttext1'].src = WebRoot+"/images/petscorner/pet_thumb" + z + ".gif";
      				break; 
   				case pointer-5 : 
			      	document.images['sorttext0'].src = WebRoot+"/images/petscorner/pet_thumb" + z + ".gif";
      				break; 
				}
			image_counter++;
			}
		last_direction="Fwd";
		}

	if (direction == "Back") {			/* Page Back */
		if (pointer <= 0) {
			pointer=image_counter+1;	/* Point to next image to display */
			image_counter=thumbs_per_page;	/* Reset image_counter */
			}
		dest_pointer = pointer+thumbs_per_page;

		image_counter = 0;
		for (z=pointer;z<=dest_pointer-1;z++){	/* Display Thumbnails */
			if (z>total_thumbs){break;}
			switch (z) {
				case pointer : 
				document.images['sorttext0'].src = WebRoot+"/images/petscorner/pet_thumb" + z + ".gif";
      				break; 
				case pointer+1 : 
			      	document.images['sorttext1'].src = WebRoot+"/images/petscorner/pet_thumb" + z + ".gif";
      				break; 
   				case pointer+2 : 
			      	document.images['sorttext2'].src = WebRoot+"/images/petscorner/pet_thumb" + z + ".gif";
      				break; 
   				case pointer+3 : 
			      	document.images['sorttext3'].src = WebRoot+"/images/petscorner/pet_thumb" + z + ".gif";
      				break; 
   				case pointer+4 : 
			      	document.images['sorttext4'].src = WebRoot+"/images/petscorner/pet_thumb" + z + ".gif";
      				break; 
   				case pointer+5 : 
			      	document.images['sorttext5'].src = WebRoot+"/images/petscorner/pet_thumb" + z + ".gif";
      				break; 
				}
			image_counter++;
			}
		last_direction="Back";
		}

	/* Setup pointer ready for next time */
	if (direction == "Fwd") {
		pointer=pointer-thumbs_per_page;	/* Start location of next thumbnail */
		}

	if (direction == "Back") {
		pointer=pointer+thumbs_per_page;	/* Start location of next thumbnail */
		}
	}

