/**
 * @fileoverview hasselhoff.js
 * 
 * Repository for JavaScript functions used by the screen hasselhoff.php.
 * 
 * @author Chris 'Chopper' Vincent (22 July 2008)
 */

// Array of Hasselhoff Images
var imageArray = new Array("Dave_birdman.jpg",
	"Dave_Dirty_Video.jpg",
	"Dave_Disguised_As_Huskey.jpg",
	"Dave_dry_ice.jpg",
	"Dave_finger_pistols.jpg",
	"Dave_gypsy_king.jpg",
	"Dave_handling_swollen_goods.jpg",
	"Dave_In_Pants.jpg",
	"Dave_Kerb_Crawling.jpg",
	"Dave_leg_stretch.jpg",
	"Dave_Looking_Like_An_Imbecile.jpg",
	"Dave_loving_KIT.jpg",
	"Dave_Lures_Child_To_Car.gif",
	"Dave_puppy_love.jpg_1.jpg",
	"Dave_Shouting.jpg",
	"Dave_wet_n_angry.jpg",
	"Dave_Working_As_Troll_Under_Bridge.jpg"
	);

// Array of Hasselhoff image comments (synchronised with image array)
var commentArray = new Array("<p>In this image, David attempts to look manly by holding a bird of prey.  What is not obvious is " +
	"that at least one of David or the Bird look as if they've recently been to a taxidermist.  Perhaps " +
	"David shot it himself.</p>",
	"<p>Nobody is quite sure why David posed for this image due to its apparent pointlessness and bad taste. " +
	"One can only assume that due to being unsuccessful, David was willing to try his hand at other " +
	"trades such as sponsered bestiality or male model for 'Love your Dog' magazine.</p>",
	"<p>Here we see David dressed like a tit in an attempt to blend in with the eskimos.  Sadly in order " +
 	"to get such a nice coat, he had to shoot the eskimo's huskeys resulting in many angry eskimos and " +
 	"yet another country David can no longer go.</p>",
 	"<p>David decides to copy Michael Jackson's dancing in this image leading to the possibility that an " +
 	"affinity for MJ inspired him to start singing in the first place.  We now at last have someone to " +
 	"blame and can only hope singing and dancing are the only MJ traits David copied.</p>",
 	"<p>Here we see David attempting to look cool.  As you can see clearly failed and is now disliked " +
	"worldwide.  Nice one David.</p>",
	"<p>David tries to prove that he is more than a mediocre actor and a crap singer by holding a guitar " +
	"in a pathetically manly way.  Sadly David cannot play the instrument.</p>",
	"<p>David is caught leaving the shower, this is all we thought we should display as any more " +
	"would break several international laws.</p>",
	"<p>This image was kindly donated by the dating agency: 'Sad, Desperate Ugly Men R Us'.  David went to them " +
	"sometime in the mid 90's and to this day, his picture has had no replies, been vomitted on 67 times " +
	"and has been linked to 3 fatalities.</p>",
	"<p>At first this looks like an image from the set of Baywatch, however this picture was taken by " +
	"a poor lady in Western Super-Mare who David tried to pick up in his bi-weekly kerb crawling session.</p>",
	"<p>Here, David is on the set of Knight Rider.  In his early days David was quite vain and was always " +
	"playing up to the cameras.</p>",
	"<p>This time David is on the set of Baywatch looking like a wanker.</p>",
	"<p>Nobody told David at high school about sex and the fact that making love to a car is not " +
	"possible</p>",
	"<p>This is quite worrying that David was luring kids back to his car very early in his career.</p>",
	"<p>David tries to appeal to women by trying to show off a sensitive side.  What we didn't see was " +
	"one of the dogs pissing on David, angering him and as a result, he shot those poor dogs.</p>",
	"<p>David is excited as he is asked for his first autograph by a sight-impaired old woman who thinks " +
	"that he is Meatloaf.</p>",
	"<p>This is my personal favourite.  Whilst walking down the street, someone recognised David and threw " +
	"a bowl of dirty dishwater over him then took a photo as he looked up in anger.  He almost looks like " +
	"the incredible hulk just before he turned.</p>",
	"<p>This is David acting on one of his <em>good</em> ideas.  After reading the tale about the Troll " +
	"under the bridge, David moved to a country that didn't have goats in it and stood under a bridge " +
	"waiting for the money to roll in.  He is still waiting.</p>"
	);

/**
 * Load the next image in the array
 */
function nextImage()
{
	var currentIndex = parseInt(document.getElementById("imgIdx").value);
	loadImage(currentIndex + 1);
}

/**
 * Load the previous image in the array
 */
function previousImage()
{
	var currentIndex = parseInt(document.getElementById("imgIdx").value);
	loadImage(currentIndex - 1);
}

/**
 * Function loads an image and a corresponding comment into the two divs on the
 * screen, based upon an index passed which is stoed in a hidden field on the
 * screen.  Enabling of the Previous and Next buttons also occurs here based upon
 * the index.
 * 
 * @param [Integer] The index to use to reference an image and comment
 */
function loadImage(index)
{
	// Handle invalid indexes
	if ( index < 0 || index >= imageArray.length )
	{
		index = 0;
	}
	
	if ( index == 0 )
	{
		// First image, disable Previous button
		document.getElementById("prevButton").disabled = true;
		document.getElementById("nextButton").disabled = false;
	}
	else if ( index == imageArray.length-1 )
	{
		// Last image, disable Next button
		document.getElementById("prevButton").disabled = false;
		document.getElementById("nextButton").disabled = true;
	}
	else
	{
		// Enable both buttons
		document.getElementById("prevButton").disabled = false;
		document.getElementById("nextButton").disabled = false;
	}
	
	// Set the image and comment divs and the hidden index field
	document.getElementById("imageDiv").innerHTML = "<p><img src='../images/hasselhoff/" + imageArray[index] + "' alt='David Hasselhoff gallery'></p>";
	document.getElementById("commentDiv").innerHTML = "<p>" + commentArray[index] + "</p>";
	document.getElementById("imgIdx").value = index;
}
