<!--

//it's useful in certain cases to identify that the user uses IE6, Safari or Opera
//WARNING - EVIL browser-sniffing ahead
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var Safari = (document.childNodes) && (!document.all) && (!navigator.taintEnabled) && (!navigator.accentColorName);
var Opera = (self.opera != null); 

// -----------------------
// FUNCTION: fAllowTabbing
// DESCRIPTION: Prevents onkey events firing when the tab key is pressed, thus allowing users to tab past them
// ARGUMENTS: 1: the event - always described as: event, 2: a function name to call without parenthesis "()", 3 variable names to pass to a function. Multiple variable names must be seperated by a "~", i.e. 'variable one~variable two~variable three~etc...'
// RETURNS: n/a
// N.B: onKey.... events should be followed with "return:true;" NOT "return:false" as for onClick events.
// -----------------------
function fAllowTabbing(e, sFunctionName, sVariable) {
	var e = e || window.event;
	var sKeyPressed = e.keyCode || e.charCode;

	if (sKeyPressed != 9) {
		if (sVariable) {
			if (sVariable.match("~")) {
				var aVariables = sVariable.split('~');
				window[sFunctionName].apply(this, aVariables);
			} else {
				window[sFunctionName](sVariable);
			}
		} else {
		window[sFunctionName]();
		}
	}
}
// -----------------------
// FUNCTION: fSwitchClass
// DESCRIPTION: A function that switches a selected class on a specified element.
// ARGUMENTS: 1: The element id, 2: The class to add or remove.
// RETURN: None
// -----------------------
function fSwitchClass(sElementId, sClassToSwitch) {

	var eElement = document.getElementById(sElementId);
	var sClassName = eElement.className;
	if (sClassName.match(sClassToSwitch) || sClassName.match(' ' + sClassToSwitch)) {
		// Removes Class
		eElement.className = eElement.className.replace(sClassToSwitch, '');
	} else {
		// Adds Class
		eElement.className = sClassName + ' ' + sClassToSwitch;
	}
}
// -----------------------
// FUNCTION: addEvent
// DESCRIPTION: Attaches an event to the requested object
// ARGUMENTS: 1: The object type, 2: The event type 3: The function to be called
// RETURN: False, True or sReturn
// -----------------------
function fAddEvent(sObject, sEventType, sFunction){ 
 if (sObject.addEventListener){ 
	 if (Safari && (sEventType == 'DOMContentLoaded'))	{	//safari
		sEventType = 'load';
	 } 
	 sObject.addEventListener(sEventType, sFunction, false); 
	 return true; 
 } else if (sObject.attachEvent){
	if (sEventType == 'DOMContentLoaded') {
		sEventType = 'load';
	}
	var sReturn = sObject.attachEvent("on" + sEventType, sFunction); 
	return sReturn; 
 } else { 
   return false; 
 } 
}
// -----------------------
// FUNCTION: fInputClear
// DESCRIPTION: clears and repopulates inputs of certain class
// ARGUMENTS: 1: the class name
// RETURN: none
// -----------------------
function fInputClear(sInputClass)	{
	var aInputs=document.getElementsByTagName('input');
	var aValues = new Array;

	for (nCount=0; nCount<aInputs.length; nCount++)	{
		aValues[nCount]=aInputs[nCount].value;
		if (aInputs[nCount].className.match(sInputClass))	{
			var closureMaker = function(thisCount) {
			    return function(event){if (aInputs[thisCount].value==aValues[thisCount]){aInputs[thisCount].value="";}};
			};
			var closure = closureMaker(nCount);
			fAddEvent(aInputs[nCount], 'focus', closure);
			var closureMakerBlur = function(thisCount) {
			    return function(event){if (aInputs[thisCount].value==""){aInputs[thisCount].value=aValues[thisCount];}};
			};
			var closureBlur = closureMakerBlur(nCount);			
			fAddEvent(aInputs[nCount], 'blur', closureBlur);
		}
	}

	var aInputsTA=document.getElementsByTagName('textarea');
	var aValuesTA = new Array;

	for (nCount=0; nCount<aInputsTA.length; nCount++)	{
		aValuesTA[nCount]=aInputsTA[nCount].value;
		if (aInputsTA[nCount].className.match(sInputClass))	{
			var closureMaker = function(thisCount) {
			    return function(event){if (aInputsTA[thisCount].value==aValuesTA[thisCount]){aInputsTA[thisCount].value="";}};
			};
			var closure = closureMaker(nCount);
			fAddEvent(aInputsTA[nCount], 'focus', closure);
			var closureMakerBlur = function(thisCount) {
			    return function(event){if (aInputsTA[thisCount].value==""){aInputsTA[thisCount].value=aValuesTA[thisCount];}};
			};
			var closureBlur = closureMakerBlur(nCount);			
			fAddEvent(aInputsTA[nCount], 'blur', closureBlur);
		}
	}
}
// *******************************************************************************
// *******************************************************************************
// BEGIN: Slider Functions
// *******************************************************************************
// *******************************************************************************
// Global variables for slider functions
var sElementId;
var nElementHeight;
var nHeight;
var nTargetHeight;
var sSetStyle;
var sSliderElementId;
var nSpeed;
var sClassName;
var nDivideBy;
var oDelay;
var sLinkElementId;
// -----------------------
// FUNCTION: fSliderSetUp
// DESCRIPTION: Searches for slider tags and attaches an onmousedown event to them
// ARGUMENTS: none
// RETURNS: none
// -----------------------
function fSliderSetUp() {
	var aSliderLinks = document.getElementsByName('toggler-div');
	var nSliderCount = aSliderLinks.length;
	
	for (nCount = 0; nCount < nSliderCount ; nCount++ ) {
		fAddEvent(aSliderLinks[nCount], 'click', fHandleSliderEvents);
		fAddEvent(aSliderLinks[nCount], 'keypress', fHandleSliderEvents);
		var sIdentifier=aSliderLinks[nCount].id.replace(/toggler-link-/,"");
		if (aSliderLinks[nCount].innerHTML=="" && aSliderLinks[nCount].title!="")	{
			aSliderLinks[nCount].innerHTML=aSliderLinks[nCount].title;
			sLinkClass=aSliderLinks[nCount].className;
			if (sLinkClass.match('hidden') || sLinkClass.match(' hidden')) {
				fSwitchClass(aSliderLinks[nCount].id, 'hidden');
			}
		}
		if (sIdentifier == 'personalisation-footer') {
		    var sCookie = fReadCookie('Personalisation.FooterState');
		    if (sCookie) {
		        if (sCookie.match('show')) {
		            document.getElementById('toggler-div-personalisation-footer').className += ' hidden';
		            fSwitchClass('toggler-link-personalisation-footer', 'hide');
		            fSwitchClass('toggler-link-personalisation-footer', 'show');
		            document.getElementById('toggler-link-personalisation-footer').innerHTML = 'show';
		        }
		    } else {
		        var sInitialState = document.getElementById('toggler-link-' + sIdentifier).className;
		        if (sInitialState.match('show')) {
		            document.getElementById('toggler-div-' + sIdentifier).className += ' hidden';		
		            fCreateCookie('Personalisation.FooterState', 'show', 7);
		        }
		    }
		/* fPaddingFix('toggler-div-' + sIdentifier); */
	    } else {
				var sShowOrHide = document.getElementById('toggler-link-' + sIdentifier).className;
				if (sShowOrHide.match('show')) {
					fSwitchClass(('toggler-div-' + sIdentifier), 'hidden');
				}
			
		}
    }
}
// -----------------------
// FUNCTION: fHandleSliderEvents
// DESCRIPTION: Catches slider events
// ARGUMENTS: the event
// RETURNS: none
// -----------------------
function fHandleSliderEvents(e) {
	if (oDelay)	{
		clearTimeout(oDelay);
	}
	var e = e || window.event;
	sKeyPressed = e.keyCode || e.charCode;
	if (sKeyPressed == 9) {
		return false;
	}
	var oTargetElement = e.target || e.srcElement;
	sElementId = oTargetElement.id;
	//var nTheNumber = sElementId.match(/\d+/);
	sIdentifier = sElementId.replace(/toggler-link-/,"");
	sElementId = 'toggler-div-' + sIdentifier;
	sLinkElementId = 'toggler-link-' + sIdentifier;
	fDetectState(sElementId);
}

// -----------------------
// FUNCTION: fDetectState
// DESCRIPTION: Detects the state of the slider div container and then calls either open or close as required
// ARGUMENTS: The id of the element to check
// RETURNS: none
// -----------------------
function fDetectState(sElementId) {
	sSliderElementId = sElementId;
	var eElement = document.getElementById(sSliderElementId);
	sClassName = eElement.className;

	sSetStyle = document.getElementById(sSliderElementId).style;

	if (sClassName.match('divide-') || sClassName.match(' divide-')) {
			var nStringIndex = sClassName.indexOf('divide-');
			nDivideBy = sClassName.slice(nStringIndex + 7, nStringIndex + 11 );
			nDivideBy = parseInt(nDivideBy, 10);
		}
	if (sClassName.match('hidden') || sClassName.match(' hidden')) {
		fSlideOpen();
	} else {
		fSlideClosed();
	}
}
// -----------------------
// FUNCTION: fSlideOpen
// DESCRIPTION: Initial script to set up the div to slide open
// ARGUMENTS: none
// RETURNS: none
// -----------------------
function fSlideOpen() {
	fSwitchClass(sSliderElementId, 'hidden');
	nElementHeight = fGetHeight(sSliderElementId);
	nTargetHeight = nElementHeight;
	nSpeed = (nTargetHeight/nDivideBy);
	sSetStyle.overflow = 'hidden';
	sSetStyle.height = '0px';
	nHeight = 0;
	fOpenControl();
	fCreateCookie('Personalisation.FooterState', 'hide', 7);
}
// -----------------------
// FUNCTION: fSlideClosed
// DESCRIPTION: Initial script to set up the div to slide closed
// ARGUMENTS: none
// RETURNS: none
// -----------------------
function fSlideClosed() {
	nTargetHeight = 0;
	nElementHeight = fGetHeight(sSliderElementId);
	sSetStyle.height = nElementHeight;
	sSetStyle.overflow = 'hidden';
	nHeight = nElementHeight;
	nSpeed = (nElementHeight/nDivideBy);
	fCloseControl();
	fCreateCookie('Personalisation.FooterState', 'show', 7);
}
// -----------------------
// FUNCTION: fOpenControl
// DESCRIPTION: sets speed of slide and repeatedly calls the setHeight() function until fully open - then clears styling
// ARGUMENTS: none
// RETURNS: none
// -----------------------
function fOpenControl() {
	nHeight += nSpeed;
	if (nHeight <= nTargetHeight) {
		oDelay = setTimeout('fSetHeight(\'fOpenControl\')', 1);
	} else {
		sSetStyle.overflow = '';
		sSetStyle.height = '';

		if (document.getElementById(sLinkElementId).className.match('show') || document.getElementById(sLinkElementId).className.match(' show')) {
			fSwitchClass(sLinkElementId, 'show');
			fSwitchClass(sLinkElementId, 'hide');
			if (document.getElementById(sLinkElementId).innerHTML.match('show')) {
			    document.getElementById(sLinkElementId).innerHTML = 'hide';
			}
		}
	}
}
// -----------------------
// FUNCTION: fCloseControl
// DESCRIPTION: sets speed of slide and repeatedly calls the setHeight() function until fully closed - then clears styling
// ARGUMENTS: none
// RETURNS: none
// -----------------------
function fCloseControl() {
	nHeight -= nSpeed;

	if (nHeight >= nTargetHeight) {
		oDelay = setTimeout('fSetHeight(\'fCloseControl\')', 1)
	} else {
		fSwitchClass(sSliderElementId, 'hidden');
		sSetStyle.overflow = '';
		sSetStyle.height = '';
		if (document.getElementById(sLinkElementId).className.match('hide') || document.getElementById(sLinkElementId).className.match(' hide')) {
			fSwitchClass(sLinkElementId, 'hide');
			fSwitchClass(sLinkElementId, 'show');
			if (document.getElementById(sLinkElementId).innerHTML.match('hide')) {
			    document.getElementById(sLinkElementId).innerHTML = 'show';
			}
		}
	}
}
// -----------------------
// FUNCTION: fGetHeight
// DESCRIPTION: get the height of the div
// ARGUMENTS: none
// RETURNS: calculated height
// -----------------------
function fGetHeight() {
	return document.getElementById(sSliderElementId).offsetHeight;
}
// -----------------------
// FUNCTION: fSetHeight
// DESCRIPTION: sets a style height on a div and then calls the function passed to it
// ARGUMENTS: a function name
// RETURNS: none
// -----------------------
function fSetHeight(sFunctionName) {
	document.getElementById(sSliderElementId).style.height = nHeight + 'px';
	window[sFunctionName]();
}
// -----------------------
// FUNCTION: fPaddingFix
// DESCRIPTION: If a div has no padding and then overflow:hidden applied to it the margins can become "collapsed", this function checks a divs padding-top and if it's value is 0 then it applies a padding-top of 1px. It's crazy I know but this prevents movement of the div as the overflow:hidden styling is added and removed.
// ARGUMENTS: an element ID
// RETURNS: none
// -----------------------
function fPaddingFix(sPaddingElementId) {
	var sPadding = fGetStyle(document.getElementById(sPaddingElementId), "padding-top");
	sPadding = (sPadding.match(/\d+/));
	if (sPadding == '0') {
		document.getElementById(sPaddingElementId).style.paddingTop = "1px";
	}
}
function fGetStyle(oElementId, sCssRule) {
	var sValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		sValue = document.defaultView.getComputedStyle(oElementId, "").getPropertyValue(sCssRule);
	}
	else if(oElementId.currentStyle){
		sCssRule = sCssRule.replace(/\-(\w)/g, function (strMatch, nValue){
			return nValue.toUpperCase();
		});
		sValue = oElementId.currentStyle[sCssRule];
	}
	return sValue;
}

// *******************************************************************************
// *******************************************************************************
// END: Slider Functions
// *******************************************************************************
// *******************************************************************************

// ----------------------
// FUNCTION: fSelectRadio
// DESCRIPTION: A function that checks the required radio button within a fieldset dependent upon a numeric value in the url
// ARGUMENTS: sFieldsetId - the ID of the fieldset containing the required radios
// RETURN: None
// ----------------------
/* function fSelectRadio(sFieldsetId) {
	var sUrl = location.href;
	if (sUrl.match("\\?")) {
		var aUrl = sUrl.split('?');
		if (aUrl[1].match(/\d+/)) {
			var aRadios = document.getElementById(sFieldsetId).getElementsByTagName('input');
			if (aUrl[1] <= (aRadios.length)) {
				var sRadioId = aRadios[aUrl[1]-1].id;
				document.getElementById(sRadioId).checked = true;
			}
		}
	}
} */
//-----------------------
// FUNCTION: fCreateCookie
// DESCRIPTION: A function that creates a cookie
// ARGUMENTS: 1: Cookie Name, 2: Cookie Value 3: Expiry date
// RETURN: none
//-----------------------
function fCreateCookie(sName, sValue, sDays) {
	if (sDays) {
		var oDate = new Date();
		oDate.setTime(oDate.getTime() + (sDays * 24 * 60 * 60 * 1000));
		var sExpires = "; expires=" + oDate.toGMTString();
	}
	else var sExpires = "";
	document.cookie = sName + "=" + sValue + sExpires + "; path=/";
}
//-----------------------
// FUNCTION: fReadCookie
// DESCRIPTION: A function that reads a cookie
// ARGUMENTS: 1: Cookie Name
// RETURN: cookie string or null if no cookie present
//-----------------------
function fReadCookie(sName) {
	var sNameEQ = sName + "=";
	var aCookies = document.cookie.split(';');
	for(var nCount = 0; nCount < aCookies.length; nCount++) {
		var sCookie = aCookies[nCount];
		while (sCookie.charAt(0)==' ') sCookie = sCookie.substring(1, sCookie.length);
		if (sCookie.indexOf(sNameEQ) == 0) return sCookie.substring(sNameEQ.length, sCookie.length);
	}
	return null;
}

// ----------------------
// FUNCTION: fGetHref
// DESCRIPTION: A function that returns the url of the "what's this' link in social bookmarks
// ARGUMENTS: None
// RETURN: sLinkRef (the url)
// ----------------------
function fGetHref() {
	var aLinks = document.getElementById('social-bookmarks').getElementsByTagName('a');
	var nLength = aLinks.length;

	for (nCount = 0; nCount < nLength ; nCount++) {
		if (aLinks[nCount].className.match('explanation')) {
			var sLinkRef = aLinks[nCount].href;
			return sLinkRef;
		}
	}
}

// ----------------------
// FUNCTION: fRenderBookmarkLinks
// DESCRIPTION: A function that renders bookmark links
// ARGUMENTS: None
// RETURN: None
// ----------------------
function fRenderBookmarkLinks() {
	var sTogglerText = document.getElementById('bookmark-link').innerHTML;
	var sLinkUrl = fGetHref();
	var sChoicesInput = document.getElementById('choices').innerHTML;
	var sNewWindowText = document.getElementById('new-window').innerHTML;
	
	document.getElementById('social-bookmarks').innerHTML = '';
	
	var oElement = '';
	var oElement2 = '';
	var oElement3 = '';
	var oElement4 = '';
	var oText ='';

	oElement = document.createElement('div');
	oElement.className = 'box bookmark';

	oElement2 = document.createElement('div');
	oElement2.className = 'padding bookmark gradient';

	oElement3 = document.createElement('a');
	oElement3.className = 'explanation'
	oElement3.setAttribute('href', sLinkUrl);
	oElement3.setAttribute('title', '');
	oText = document.createTextNode('What are these')
	oElement3.appendChild(oText);
	oElement2.appendChild(oElement3);

	oElement.appendChild(oElement2);

	document.getElementById('social-bookmarks').appendChild(oElement);

	/* Create bookmarks div */
	oElement = document.createElement('div');
	oElement.className = 'box save-this';
	oElement.setAttribute('id', 'bookmarks');

	/* Create Toggler paragraph */
	oElement2 = document.createElement('p');
	oElement2.className = 'save-this';
	oElement3 = document.createElement('strong');
	oText = document.createTextNode(sTogglerText);
	oElement3.appendChild(oText);

	/* Append strong text to paragraph */
	oElement2.appendChild(oElement3);

	/* Create Show Hide link */
	oElement3 = document.createElement('a');
	oElement3.className = 'show';
	
	oElement3.setAttribute('id', 'toggler-link-bookmarks');
	oElement3.setAttribute('tabIndex', '0');
	oElement3.setAttribute('name', 'toggler-div');
	
	oText = document.createTextNode('show');
	oElement3.appendChild(oText);


	/* Append Show link to paragraph */
	oElement2.appendChild(oElement3);	
	/* Append paragraph to bookmarks div */
	oElement.appendChild(oElement2);

	document.getElementById('social-bookmarks').appendChild(oElement);
	
	if (oElement3.addEventListener) {
	 
	    fAddEvent(document.getElementById('toggler-link-bookmarks'), 'click', fHandleSliderEvents);
        fAddEvent(document.getElementById('toggler-link-bookmarks'), 'keypress', function(){fHandleSliderEvents});
	    } else {
	   
	        oElement3.onclick = function (){fHandleSliderEvents();};
	        oElement3.onkeypress = function (){fHandleSliderEvents();};
	      }

	/* Create toggler div */
	oElement = document.createElement('div');
	oElement.className = "divide-10 padding gradient clear hidden";
	oElement.setAttribute('id', 'toggler-div-bookmarks');

	/* Create ul */
	oElement2 = document.createElement('ul');
	oElement2.className = 'bookmarks';

	/* Create list items */
	oElement3 = document.createElement('li');
	oElement3.setAttribute('id', 'choices');
	
	/* Insert Choices Button */
	oElement3.innerHTML = sChoicesInput;
	oElement2.appendChild(oElement3);

	/* Create list item 2 */
	oElement3 = document.createElement('li');
	oElement3.setAttribute('id', 'new-window');
	oText = document.createTextNode(sNewWindowText);
	oElement3.appendChild(oText);
	oElement2.appendChild(oElement3);

	/* Create List item 3 - delicious */
	oElement3 = document.createElement('li');
	oElement3.setAttribute('id', 'delicious');
	oElement4 = document.createElement('a');
	oElement4.setAttribute('title', 'opens in a new window');
	oElement4.setAttribute('href', '#');
	oElement4.setAttribute('id', 'delicious-link');
	oText = document.createTextNode('Delicious');
	oElement4.appendChild(oText);
	oElement3.appendChild(oElement4);
	oElement2.appendChild(oElement3);

	/* Create List item 4 - digg */
	oElement3 = document.createElement('li');
	oElement3.setAttribute('id', 'digg');
	oElement4 = document.createElement('a');
	oElement4.setAttribute('title', 'opens in a new window');
	oElement4.setAttribute('href', '#');
	oElement4.setAttribute('id', 'digg-link');
	oText = document.createTextNode('Digg');
	oElement4.appendChild(oText);
	oElement3.appendChild(oElement4);
	oElement2.appendChild(oElement3);

	/* Create List item 5 - Facebook */
	oElement3 = document.createElement('li');
	oElement3.setAttribute('id', 'facebook');
	oElement4 = document.createElement('a');
	oElement4.setAttribute('title', 'opens in a new window');
	oElement4.setAttribute('href', '#');
	oElement4.setAttribute('id', 'facebook-link');
	oText = document.createTextNode('Facebook');
	oElement4.appendChild(oText);
	oElement3.appendChild(oElement4);
	oElement2.appendChild(oElement3);
	
	/* Create List item 5 - Reddit */
	oElement3 = document.createElement('li');
	oElement3.setAttribute('id', 'reddit');
	oElement4 = document.createElement('a');
	oElement4.setAttribute('title', 'opens in a new window');
	oElement4.setAttribute('href', '#');
	oElement4.setAttribute('id', 'reddit-link');
	oText = document.createTextNode('Reddit');
	oElement4.appendChild(oText);
	oElement3.appendChild(oElement4);
	oElement2.appendChild(oElement3);

	/* Create List item 6 - Stumbleupon */
	oElement3 = document.createElement('li');
	oElement3.setAttribute('id', 'stumbleupon');
	oElement4 = document.createElement('a');
	oElement4.setAttribute('title', 'opens in a new window');
	oElement4.setAttribute('href', '#');
	oElement4.setAttribute('id', 'stumbleupon-link');
	oText = document.createTextNode('Stumbleupon');
	oElement4.appendChild(oText);
	oElement3.appendChild(oElement4);
	oElement2.appendChild(oElement3);
    
	/* Append List */
	oElement.appendChild(oElement2);
	document.getElementById('bookmarks').appendChild(oElement);
	oElement.className = 'divide-10 clear gradient padding hidden';
	
	/* Add bookmarking events for non ie browsers */

    fAddEvent(document.getElementById('delicious-link'), 'click', fDelicious);
    fAddEvent(document.getElementById('delicious-link'), 'keydown', function(){fDelicious});
    fAddEvent(document.getElementById('digg-link'), 'click', fDigg);
    fAddEvent(document.getElementById('digg-link'), 'keydown', function(){fDigg});
    fAddEvent(document.getElementById('facebook-link'), 'click', fFacebook);
    fAddEvent(document.getElementById('facebook-link'), 'keydown', function(){fFacebook});
    fAddEvent(document.getElementById('reddit-link'), 'click', fReddit);
    fAddEvent(document.getElementById('reddit-link'), 'keydown', function(){fReddit});
    fAddEvent(document.getElementById('stumbleupon-link'), 'click', fStumbleupon);
    fAddEvent(document.getElementById('stumbleupon-link'), 'keydown', function(){fStumbleupon});
	
}
function fDelicious() {
	window.open('http://del.icio.us/post?url=' + encodeURIComponent(location.href) + '%26title%3D' + encodeURIComponent(document.title));
}
function fDigg() {
	window.open('http://digg.com/submit?url=' + encodeURIComponent(location.href) + '%26title%3D' + encodeURIComponent(document.title));
}
function fFacebook() {
	window.open('http://www.facebook.com/sharer.php?u='  + encodeURIComponent(location.href) + '%26title%3D' + encodeURIComponent(document.title));
}
function fReddit() {
	window.open('http://reddit.com/submit?url=' + encodeURIComponent(location.href) + '%26title%3D' + encodeURIComponent(document.title));
}
function fStumbleupon() {
	window.open('http://www.stumbleupon.com/submit?url='  + encodeURIComponent(location.href) + '%26title%3D' + encodeURIComponent(document.title));
}

// ----------------------
// FUNCTION: fCreateSniffer
// DESCRIPTION: A function that adds A hidden input to confirm JS is running for search results with map tab
// ARGUMENTS: None
// RETURN: None
// ----------------------
function fCreateSniffer() {
	var oInput = document.createElement('input');
	oInput.setAttribute('type', 'hidden');
	oInput.setAttribute('name', '___JSSniffer');
	oInput.id = '___JSSniffer';
	oInput.value = 'true';
	var oTheForm = document.body.getElementsByTagName('form');
	var nFormCount = (oTheForm.length -1);
	oTheForm[nFormCount].appendChild(oInput);
}

// ----------------------
// FUNCTION: fHideElements
// DESCRIPTION: A function that hides elements by adding the 'hidden' class
// ARGUMENTS: 1: Container ID, 2: Element type to hide
// RETURN: None
// ----------------------
function fHideElements(sContainerId, sElementType) {
	var sElementId;
	var sContainer = document.getElementById(sContainerId);
	var aElements = sContainer.getElementsByTagName(sElementType);
	var nArrayLength = aElements.length;
	for (nCount = 0; nCount < nArrayLength ; nCount++) {
		sElementId = aElements[nCount].id;
		fSwitchClass(sElementId, 'hidden');
	}
}

var oMSGlobals; // Global variable for Main Search.

// ----------------------
// FUNCTION: fMainSearchGlobals
// DESCRIPTION: Object instance to hold global variables for main search switching.
// ARGUMENTS: none
// RETURN: None
// ----------------------
function fMainSearchGlobals() {
	this.sSearchContainer = 'search-options';
	this.sActiveId = 'search-1';
	this.sActiveClassName = 'active';
}

// ----------------------
// FUNCTION: fSearchOptionsSetUp
// DESCRIPTION: Re-styling and event allocation for main search.
// ARGUMENTS: none
// RETURN: None
// ----------------------
function fSearchOptionsSetUp() {
	fHideElements('search-options','input');
	oMSGlobals = new fMainSearchGlobals();
	var aLabels = document.getElementById(oMSGlobals.sSearchContainer).getElementsByTagName('label');
	var nLabelCount = aLabels.length;
	for (nCount = 0; nCount < nLabelCount; nCount++ ) {
		fAddEvent(document.getElementById(aLabels[nCount].id), 'click', fSearchOptionsSwitch);
		fAddEvent(document.getElementById(aLabels[nCount].id), 'keydown', fSearchOptionsSwitch);
	}
}

// ----------------------
// FUNCTION: fSearchOptionsSwitch
// DESCRIPTION: Switches active search tab
// ARGUMENTS: none
// RETURN: None
// ----------------------
function fSearchOptionsSwitch(e) {
	e = e || window.event;
	if (e.target) {
		var sTargetId = e.target.id;
	}
	if (e.srcElement) {
		var sTargetId = e.srcElement.id;
	}
	if (sTargetId) {
		if (sTargetId.match(/\d+/)) {
			if (sTargetId != oMSGlobals.sActiveId) {
				fSwitchClass(oMSGlobals.sActiveId, oMSGlobals.sActiveClassName);
				fSwitchClass(sTargetId, oMSGlobals.sActiveClassName);
				oMSGlobals.sActiveId = sTargetId;
			}
		}	
	}
}









// ----------------------
// FUNCTION: fSetIds
// DESCRIPTION: Searches for element types with a specific classname and adds an ID to them of that classname + a number. e.g. <ul class="list"> becomes <ul class="list" id="list-1">
// Arguments: sType is the element type e.g. "div" or "ul", sClassName is the class name to match
// RETURN: N/A
// ----------------------
function fSetIds(sType, sClassName) {
	var aElements = document.getElementsByTagName(sType);
	var nLength = aElements.length;
	var nIdCount = 0;
	this.aIds = new Array();

	for (nCount = 0; nCount < nLength ; nCount++) {
		if (aElements[nCount].className.match(sClassName)) {
			aElements[nCount].id = (sClassName + '-' + nIdCount);
			this.aIds[nIdCount] = (sClassName + '-' + nIdCount);
			nIdCount++
		}
	}
}

var oCLGlobals; // Global variable for carousel style lists.

function fCarouselListGlobals() {
	this.sClassIdentifier = 'carousel-list'; // classname attached to lists to search for
	this.sNewClass = 'carousel-list-js'; // New classname for the JS version list
	this.nListCount;
	this.nListPosition;
	this.nListItemCount;
	this.nSlideTime = '500'; // Time for sliding between list items (1000 = 1 second).
	this.nSlideInterval = '50'; // Time for each slide interval (100 = 0.1 second).
	this.nSectionWidth;
	this.sParentClass = 'list-box' // Classname for parent container that sets overall width for individual list item.
	this.nIntervalCounter = 0;
	this.nSwapCount = new Array();
	this.bIsActive = false;
}

function fAddListItemIds(sParentId, nListNumber) {
	var aListItems = document.getElementById(sParentId).getElementsByTagName('li');
	oCLGlobals.nListItemCount = aListItems.length;
	for (nSubCount = 0; nSubCount < oCLGlobals.nListItemCount ; nSubCount++) {
		aListItems[nSubCount].id = 'list-' + nListNumber + '-item-' + nSubCount;
	}
}

function fAddNav(sListId, sDirection) {
	var oDiv = document.createElement('span');
	oDiv.className = sDirection + '-arrow';
	var oImg = document.createElement('img');
	oImg.setAttribute('src', '/img/nhsdirect/' + sDirection + '-arrow.gif');
	oImg.setAttribute('alt', sDirection);
	oImg.setAttribute('height', '28');
	var oLink = document.createElement('a');
	oLink.setAttribute('title', sDirection);
	oLink.id = sListId + '-' + sDirection + '-arrow';
	var sLinkId = sListId + '-' + sDirection + '-arrow';
	oLink.appendChild(oImg);
	oDiv.appendChild(oLink);
	oParent = document.getElementById(sListId).parentNode;
	sListId = document.getElementById(sListId);
	oParent.insertBefore(oDiv, sListId);
	fAddEvent(document.getElementById(sLinkId), 'click', function() {fScroll(sLinkId, sDirection)});
}

function fScroll(sElementId, sDirection) {
	if (oCLGlobals.bIsActive == false) {
		var nListNumber = sElementId.match(/\d+/);
		var sListId = (oCLGlobals.sClassIdentifier + '-' + nListNumber);
		fSlideList(sListId, sDirection);	
	}	
} 

function fSlideList(sListId, sDirection) {
	var nIntervalCount = (oCLGlobals.nSlideTime / oCLGlobals.nSlideInterval);
	var nSlideDistance = (oCLGlobals.nSectionWidth / nIntervalCount);
	var sCurrentLeft = document.getElementById(sListId).style.left;
	if (oCLGlobals.nIntervalCounter < (nIntervalCount)) {
		var oSliderTimeout = setTimeout(function () {fSliderTimeout(sListId, sDirection, sCurrentLeft, nSlideDistance)}, oCLGlobals.nSlideInterval);
		oCLGlobals.bIsActive = true;
	} else {
		oCLGlobals.nIntervalCounter = 0;
		clearTimeout(oSliderTimeout);
		oCLGlobals.bIsActive = false;
		sListId = document.getElementById(sListId);
		fCenterList(sListId);
		fSwitchList(sListId, sDirection);
		}
}

function fSliderTimeout(sListId, sDirection, sCurrentLeft, nSlideDistance) {
	var nCurrentLeft = sCurrentLeft.match(/\d+(\.\d+)?/);
	if (sDirection == 'back') {
		var nNewLeft = (parseFloat(nCurrentLeft) - parseFloat(nSlideDistance));
	} else {
		var nNewLeft = (parseFloat(nCurrentLeft) + parseFloat(nSlideDistance));
	}
	document.getElementById(sListId).style.left = ('-' + nNewLeft + 'em');
	oCLGlobals.nIntervalCounter++;
	fSlideList(sListId, sDirection);
}

function fSwitchList(sListId, sDirection) {
	var aItems = sListId.getElementsByTagName('li');
	if (sDirection == 'back') {
		var oElementToSwitch = aItems[aItems.length-1].id;
		var oElementHolder = sListId.removeChild(document.getElementById(oElementToSwitch));
		sListId.insertBefore(oElementHolder, sListId.firstChild);
	} else {
		var oElementToSwitch = aItems[0].id;
		var oElementHolder = sListId.removeChild(document.getElementById(oElementToSwitch));
		sListId.appendChild(oElementHolder);
	}
	sListId.style.visability = '';
}

function fCreateCarouselLists() {
	oCLGlobals = new fCarouselListGlobals();
	var oSetIds = new fSetIds('ul', oCLGlobals.sClassIdentifier);
	oCLGlobals.nListCount = oSetIds.aIds.length;
	for (nCount = 0; nCount < oCLGlobals.nListCount; nCount++) {
		fSwitchClass(oSetIds.aIds[nCount], oCLGlobals.sClassIdentifier);
		fSwitchClass(oSetIds.aIds[nCount], oCLGlobals.sNewClass);
		fAddListItemIds(oSetIds.aIds[nCount], nCount);
		fAddNav(oSetIds.aIds[nCount], 'forward');
		fAddNav(oSetIds.aIds[nCount], 'back');
		var sListId = document.getElementById(oSetIds.aIds[nCount]);
		oCLGlobals.nSwapCount[nCount] = Math.floor(oCLGlobals.nListItemCount / 2);
		for (nSubCount = 0; nSubCount < oCLGlobals.nSwapCount[nCount] ; nSubCount++) {
			fSwitchList(sListId, 'back');
		}
	fCenterList(sListId);
	} 
}

function fCenterList(sListId) {
	var nListNumber = sListId.id;
	var nListNumber = nListNumber.match(/\d+/);
	// Loop up to parent that sets width.
	var sParentId = sListId;
	do {
		sParentId = sParentId.parentNode;
	} while (sParentId.className != oCLGlobals.sParentClass);
	
	// Get parent width
	if (window.getComputedStyle) {
		oCLGlobals.nListPosition = getComputedStyle(sParentId, null).getPropertyValue("width");
		var nDivideBy = fCalculateEMs(sListId ,oCLGlobals.nListPosition);	
		oCLGlobals.nListPosition = oCLGlobals.nListPosition.replace('px', '');
		oCLGlobals.nListPosition = Math.round(oCLGlobals.nListPosition / nDivideBy);
	} else if (sParentId.currentStyle) {
		oCLGlobals.nListPosition = sParentId.currentStyle.width + '';
		oCLGlobals.nListPosition = oCLGlobals.nListPosition.replace ('em', '');
	}
	// Add the negative margin to the list.
	sListId.style.visability = 'hidden';
	oCLGlobals.nSectionWidth = oCLGlobals.nListPosition;
	oCLGlobals.nListPosition = ('-' + (oCLGlobals.nListPosition * oCLGlobals.nSwapCount[nListNumber]) + 'em');
	sListId.style.left = oCLGlobals.nListPosition;
}

function fCalculateEMs(sListId, nPixelSize) {
	var oTempDiv = document.createElement('div');
	oTempDiv.id = 'em-test-div';  // N.B. Need id declaration to match in CSS with width of 1000em;
	sListId.appendChild(oTempDiv);
	var oTempId = document.getElementById('em-test-div');
	var nPixelWidth = window.getComputedStyle(oTempId, null).getPropertyValue("width");
	nPixelWidth = nPixelWidth.replace('px', '');
	var nEmWidth = (nPixelWidth / 1000);
	sListId.removeChild(oTempId);
	return nEmWidth;
}

// ----------------------
// FUNCTION: fAddChoicesEvents
// DESCRIPTION: A function that adds Choices events where appropriate
// ARGUMENTS: None
// RETURN: None
// ----------------------
function fAddChoicesEvents() {
	/* if (document.getElementById('find-services-search-options')) {
		fSelectRadio('find-services-search-options');
	} */
	fSliderSetUp();
	if (document.getElementById('social-bookmarks')) {
		fRenderBookmarkLinks();
	}
	if (document.getElementById('questions')) {
		fCreateCarouselLists();
	}
	if (document.getElementById('search-options')) {
		fSearchOptionsSetUp();
	}
    fCreateSniffer();
}
fAddEvent(window, 'load', fAddChoicesEvents);
fAddEvent(window, 'DOMContentLoaded', function(){fInputClear('js-clear');}); //clears inputs with class 'js-clear'

//-->

