//////////////////////////////////////////////////////////////////
// fixffscroll: make Mozilla Firefox < v1.5 scroll divs with	//
// the mouse wheel properly. This bug was fixed in FF v1.5)		//
// version 1.0, 21-April-2006									//
// written by Dan Forster <dan 'at' paintballevolution.co.uk>	//
//																//
// You may use this code freely, and let me know if it works	//
// for you!														//
//																//
// You need to declare the div like this:						//
//																//
//		<div onmouseover="fixFFScroll(this);">					//
//		<a></a>													//
//																//
// N.B. You MUST include the empty anchor tag and also NOT put	//
// 		ANY text (including comments in the line after the div	//
//		declaration endmarker ( > ) and before the anchor, or 	//
//		it will not work for some strange reason!				//
//																//
//		Also, if you are using forms, the script will remove	//
//		focus from the form elements unless you use the			//
//		runLoadHandler() function to set the events for these.	//
//		This is what the document.addEventListener method is	//
//		there for - it will automatically add a listener as		//
//		soon as the script is loaded and begins execution.		//
//		The event it looks for is MOZILLA ONLY.					//
//////////////////////////////////////////////////////////////////

//////////// BEGIN FIXFFSCROLL CODE //////////////////////////////

var activeFormElement = null; 	// initialise global variable to contain the element object if form element has focus.
var firstrun = 1; // initialise global var - check if first run of code
var isFF = 0; // initialise global var - for browsers not FF
var versionnumber = ""; //initialise blank global var to hold the FF version number

function runBlurHandler() { // when form element loses focus, null the object holding var.
	activeFormElement = null;
}

function runFocusHandler(theEvent) { // when a form element receives focus, run this
	var eventObject = theEvent ? theEvent : window.event;
	if (!eventObject) return; // if no object was captured, do nothing
	if (eventObject.target) activeFormElement = eventObject.target; // if object has a target property that can be read, copy target to var
	else if(eventObject.srcElement) activeFormElement = eventObject.srcElement; // otherwise it might have a srcElement property - copy it to a var
}

function runLoadHandler() { // this just walks the DOM looking for form elements and setting focus and blur events on them all
	var i, j;
	for (i = 0; i < document.forms.length; i++)
		for (j = 0; j < document.forms[i].elements.length; j++) {
			document.forms[i].elements[j].onfocus = runFocusHandler;
			document.forms[i].elements[j].onblur  = runBlurHandler;
		}
}

function fixFFScroll(thediv) {
	if (firstrun == 1) { // only run this if never run before (var is as it was when initialised)
		var ffindex = navigator.userAgent.toLowerCase().indexOf('firefox'); // see if 'firefox' appears in UA (will be -1 if not found)
		isFF = ffindex + 1;// so make it 0 if it was not found (can then be used as false later on)
		var versionindex = ffindex + 8; // skip version index up to where version number starts in UA string
		var numdigits = 3;
		var i = '';
		for ( i=0; i < (numdigits); i++ ) {
			versionnumber += navigator.userAgent.charAt(versionindex + i);
		}
		firstrun = 0; //stop this detection from running again as we already have it
	}

	// if its firefox and less than v1.5 (where the scroll bug was fixed) and a form element is not focussed
	if (isFF && parseFloat(versionnumber) < 1.5 && activeFormElement == null) {
		var tmp = thediv.scrollTop; //save scroll position
		thediv.childNodes[1].focus(); // focus the scrollable div
		thediv.scrollTop = tmp; // restore scroll position
	}
}

// the below if statement is required for the focus events to be caught.
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", runLoadHandler, false);
}

//////////// END FIXFFSCROLL CODE ////////////////////////////////


// this function used to change elements colour that IE usually won't do
function changeCSS(obj, bgColor, ftColor) {
   	if (document.getElementById) {
		obj.style.backgroundColor = bgColor;
		obj.style.color = ftColor;
	}
}