/* 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==3)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] = "Sasha - Owned by Carol Ravensdale";
	imagetext[2] = "Colin - Owned by Julie Stewart";
	imagetext[3] = "Tilly (Valencris Mystic Matilda) - Owned by Louise Grocott";
	imagetext[4] = "Digby - Owned by Andrea Currie";
	imagetext[5] = "Siggy - Owned by Linda Collie";
	imagetext[6] = "Festus Derriman - Owned by Marie & David King";
	imagetext[7] = "George - Owned Geoff & Sarah Walton";
	imagetext[8] = "4 puppies in a pot - Owned by Glen & Dean Flint";
	imagetext[9] = "Rosie (Ebenholz Laura Norder) - Owned by Chris Browse";
	imagetext[10] = "Hector - Owned by Anne-Marie";
	imagetext[11] = "Eddie - Owned by Jayne Owen";
	imagetext[12] = "Kizzy - Owned by Viv Middleton";
	imagetext[13] = "Ellie - Owned by Jo Barton";
	imagetext[14] = "Dexter - Owned by Elaine Milne";
	imagetext[15] = "Sasha - Owned by Carol Ravensdale";
	imagetext[16] = "Dylan - Owned by Julie Smith";
	imagetext[17] = "Ellie - Owned by Jim Webster";
	imagetext[18] = "Saffy - Owned by Dudley Singleton";
	imagetext[19] = "Spike - Owned by Lucy & Steve Wright";
	imagetext[20] = "Lexi - Owned by Sue Goodchild";
	imagetext[21] = "Stiffy - Owned by Gemma Harris";
	imagetext[22] = "Chester - Owned by Tracey Farrimond";
	imagetext[23] = "Ellie - Owned by Ciara Jennings";
	imagetext[24] = "Jake - Owned by Eileen O'Neil";
	imagetext[25] = "Stiffy - Owned by Gemma Harris";
	imagetext[26] = "Reggie - Owned by Sherry Knight";
	imagetext[27] = "Zigi - Owned by Alison Roberts";
	imagetext[28] = "Eddy - Owned by James Moore";
	imagetext[29] = "Poppy - Owned by Joanne Henson";
	imagetext[30] = "Mister - Owned by V & P Stableford";
	imagetext[31] = "Un-named puppies - Owned by Brian & Marilyn Erbe";
	imagetext[32] = "Holly - Owned by Joanne Henson";
	imagetext[33] = "Monty Zuma - Owned by Katie Yeates & Benjamin Harvey";
	imagetext[34] = "Gem (Linatone's Just a Gem) - Owned by Karen Wiles";
	imagetext[35] = "Louis - Owned by Anne-Marie Pollard";
	imagetext[36] = "Archie - Owned by Ivan Macenzie";
	imagetext[37] = "Harry - Owned by Amy Surman & Stuart Langley";
	imagetext[38] = "Louis - Owned by Anne-Marie Pollard";
	imagetext[39] = "Minka (Floke Ore Inspiring) - Owned by Dagmar & Darren Middleditch";
	imagetext[40] = "Jack - Owned by Roisin Gray";
	imagetext[41] = "Max - Owned by Alison Frost";
	imagetext[42] = "Riana - Owned by Roland Richardson in France";
	imagetext[43] = "Smudge - Owned by Gerry, Martin, James and Matthew Marais";
	imagetext[44] = "Chilli - Owned by Leigh & Rebecca Adams";
	imagetext[45] = "Jessie - Owned by Jenni Kenyon";
	imagetext[46] = "Ruby - Owned by The Heatons";
    imagetext[47] = "Butch - Owned by Simon Meyers";
    imagetext[48] = "Absolute Charm - Owned by Sandy Homewood";
    imagetext[49] = "Ruby - Owned by the Rankin Family";
    imagetext[50] = "Ella - Owned by Jill Baldwin";
    imagetext[51] = "Colby - Owned by Tim Bruce";
    imagetext[52] = "Lilly - Owned by Chris & Margie Harwood";
    imagetext[53] = "Alfred - Owned by Debbie & Steve Broomhead";
    imagetext[54] = "Truffle - Owned by Olivia Robinson";
    imagetext[55] = "Reggie - Owned by Anna Denham";
    
    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+" cute puppy pictures to view";

	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){ 				/* Page Back */
		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){ 				/* Page Forward */
		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") {			/* Page Forward */
		p = pointer+x+1;
		}
	if (direction == "Back") {			/* Page 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") {			/* Page Forward */
		i = pointer+y+1;
		}
	if (direction == "Back") {			/* Page Back */
		i = pointer-thumbs_per_page+y;
		}
    if (i <= 19){                       /* Pet19 and below are .GIFs */
    	imagename = "cutepet" + i + ".gif";
        }
    if (i > 19){                        /* Pet20 and above are .JPGs */
    	imagename = "cutepet" + 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/"+"cutepet_thumb" + z + ".gif";
      				break; 
				case pointer-1 : 
			      	document.images['sorttext4'].src = WebRoot+"/images/petscorner/"+"cutepet_thumb" + z + ".gif";
      				break; 
   				case pointer-2 : 
			      	document.images['sorttext3'].src = WebRoot+"/images/petscorner/"+"cutepet_thumb" + z + ".gif";
      				break; 
   				case pointer-3 : 
			      	document.images['sorttext2'].src = WebRoot+"/images/petscorner/"+"cutepet_thumb" + z + ".gif";
      				break; 
   				case pointer-4 : 
			      	document.images['sorttext1'].src = WebRoot+"/images/petscorner/"+"cutepet_thumb" + z + ".gif";
      				break; 
   				case pointer-5 : 
			      	document.images['sorttext0'].src = WebRoot+"/images/petscorner/"+"cutepet_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/"+"cutepet_thumb" + z + ".gif";
      				break; 
				case pointer+1 : 
			      	document.images['sorttext1'].src = WebRoot+"/images/petscorner/"+"cutepet_thumb" + z + ".gif";
      				break; 
   				case pointer+2 : 
			      	document.images['sorttext2'].src = WebRoot+"/images/petscorner/"+"cutepet_thumb" + z + ".gif";
      				break; 
   				case pointer+3 : 
			      	document.images['sorttext3'].src = WebRoot+"/images/petscorner/"+"cutepet_thumb" + z + ".gif";
      				break; 
   				case pointer+4 : 
			      	document.images['sorttext4'].src = WebRoot+"/images/petscorner/"+"cutepet_thumb" + z + ".gif";
      				break; 
   				case pointer+5 : 
			      	document.images['sorttext5'].src = WebRoot+"/images/petscorner/"+"cutepet_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 */
		}
	}

