/**
 * Rollover, combining Keyboard focus with mouse over.
 * i.e. an instance of this class represents an image link, and if the link has keyboard focus
 * or the mouse is hovering over it then the Active image is displayed. 
 * @author Mark Franklyn Baker
 * @version 0.1 Feb 20 2009
 * @type class
 
 ToDo: rename to uk.co.mfbaker.Rollover
 ToDo: on reload is still a problem, if this page had been left, and gone back to,
       e.g. the User selecting the "Back Button", 
       then this object loosed track of the mouse position and keyboard focus. 
 
 */

//if (!co.uk.baughfarm.TourViewNavigation) co.uk.baughfarm.TourViewNavigation = {};

/**
 * .
 * @author Mark Franklyn Baker
 * @version 0.1 Feb 20 2009
 * @param stringProperty - string, .
 * @param inputParentID - string, is the "id" of the <a> element node, which contains the <img> element node.
 * @param imageName - string, is the "name" of the <img> element node.
 * @type constructor
 */
co.uk.baughfarm.TourViewNavigation = function (stringProperty, inputParentID, imageName, linkURL, activeURL) {

	this.imageName = imageName;
	this.linkURL = linkURL;
	this.activeURL = activeURL;
	this.focus = false;
	this.over = false;
	
	var utility = co.uk.baughfarm.Utility;
	var inputParent = document.getElementById(inputParentID);
	
	if (inputParent) {
	
		utility.assignEventHandler(inputParent, 'onfocus', stringProperty+'.onFocus(this);');
		utility.assignEventHandler(inputParent, 'onblur', stringProperty+'.onBlur(this);');
		utility.assignEventHandler(inputParent, 'onmouseover', stringProperty+'.onMouseOver(this);');
		utility.assignEventHandler(inputParent, 'onmouseout', stringProperty+'.onMouseOut(this);');
	
	}
	else {
alert('co.uk.baughfarm.TourViewNavigation'
+'\nUnable to find the parent element with id "'+inputParentID
+'"');
	}
	
	(new Image()).scr = this.activeURL;
	
}

/**
 * on focus event handler, can be placed on an <a> element.
 * @author Mark Franklyn Baker
 * @version 0.1 Feb 20 2009
 * @param aNode is the <a> element node.
 * @type instance-method
 */
co.uk.baughfarm.TourViewNavigation.prototype.onFocus = function (aNode) {
	this.focus = true;
	this.setImage();
}

co.uk.baughfarm.TourViewNavigation.prototype.onBlur = function (aNode) {
	this.focus = false;
	this.setImage();
}

co.uk.baughfarm.TourViewNavigation.prototype.onMouseOver = function (aNode) {
	this.over = true;
	this.setImage();
}

co.uk.baughfarm.TourViewNavigation.prototype.onMouseOut = function (aNode) {
	this.over = false;
	this.setImage();
}


co.uk.baughfarm.TourViewNavigation.prototype.setImage = function () {

	if (this.over || this.focus) {
		imageSrc = this.activeURL;
	}
	else {
		imageSrc = this.linkURL;
	}

	 // document.next.src
	document.images[this.imageName].src = imageSrc; 

}

/**
 * on reload.
 * this gets called when a browser returnes to the page
 * (e.g. when the user clickes on the back button).
 * Key board focus seems to be the same, but the mouse location has
 * changed, so this method assumes the mouse is no longer over this button.
 * @author Mark Franklyn Baker
 * @version 0.1 Mar 02 2009
 * @type instance-method
 */
co.uk.baughfarm.TourViewNavigation.prototype.onReload = function () {
	this.over = false;
}