    /*  START jQuery functions*/
	function riskSpectrum(){
		if (jQueryUsed){
			if($("#riskSpectrum").length > 0){
				var maxRiskRating = 3.2559;//raised slightly to show the end pixel .
				var minRiskRating = 0;
				var riskSliderBounds = [0,0.2,0.85,1.60,3.25];
				var riskSliderValueCurrent;
				var RiskTextMinimal = "<strong>Minimal risk</strong>: If you’re only prepared to take minimal risk it’s likely that your main concern is the security of your money. Minimal risk funds tend to be cash or cash-like investments. Minimal risk doesn’t mean there’s no risk."
				var RiskTextLow = "<strong>Low risk</strong>: If you are a low risk investor, it’s likely that, when investing your money, you look for the security that your investment’s value won’t go up and down a lot. Low risk funds tend to have a mix of investment types, or just fixed interest securities." 
				var RiskTextMedium = "<strong>Medium risk</strong>: If you’ve got a medium attitude to risk, it’s likely that you already have an interest in investing and are comfortable with the ups and downs of the stock market. Medium risk funds take risks to provide greater returns. They tend to contain higher risk fixed interest investments, shares and commercial property. These may be outside the UK." 
				var RiskTextHigh = "<strong>High risk</strong>: If you’re prepared to take high risk, it’s likely that you’re an experienced and knowledgeable investor, whose primary aim is to achieve the highest possible returns on your money, while accepting that this means taking substantial risks. High risk funds tend to be in specialised areas or in one or more countries outside the UK."
				var RiskTextToUse;
				var widthOfSlider = $("#slider").width();
				function highLightProvider(){
					$("#riskSpectrum h4").removeClass("highlightProviderMinimal highlightProviderLow highlightProviderMedium highlightProviderHigh");
					uiValue = $("#slider").slider('option','value');
					if (uiValue > riskSliderBounds[0] && uiValue < riskSliderBounds[1]){
						$("p.riskRating:contains(" + uiValue +")").parent().prev().addClass("highlightProviderMinimal");
					}
					else if(uiValue > riskSliderBounds[1] && uiValue< riskSliderBounds[2]){
						$("p.riskRating:contains(" + uiValue +")").parent().prev().addClass("highlightProviderLow");
					}
					else if(uiValue > riskSliderBounds[2] && uiValue< riskSliderBounds[3]){
						$("p.riskRating:contains(" + uiValue +")").parent().prev().addClass("highlightProviderMedium");
					}
					else if(uiValue > riskSliderBounds[3] && uiValue< riskSliderBounds[4]){
						$("p.riskRating:contains(" + uiValue +")").parent().prev().addClass("highlightProviderHigh");
					}
				}
				function snapToNearestResult(uiValue,e){
					var keycode = e.which;
					var keytype = e.type;
					// if using the mouse, snap to the nearest one
					if(keycode == 1 && keytype == "slide"){	
						var difference = 5;
						var closestStepValue;
						for(providerCounter = 0;providerCounter < riskSliderProviderValues.length;providerCounter++){
							var tempDifference = Math.abs(uiValue - riskSliderProviderValues[providerCounter]);
							if(tempDifference < difference){
								difference = tempDifference;
								closestStepValue = riskSliderProviderValues[providerCounter];
							}
						}
						// return the value for the slider to move					
						return closestStepValue;
					}
					else if((keycode == 37 || keycode == 40) && keytype == "slidestart"){
						//Left and down
						for(providerCounter = 0;providerCounter < riskSliderProviderValues.length;providerCounter++){
							if(uiValue == riskSliderProviderValues[providerCounter]){return riskSliderProviderValues[providerCounter - 1];}
						}
					}
					else if((keycode == 38 || keycode == 39) && keytype == "slidestart"){
						// Right and up	
						for(providerCounter = 0;providerCounter < riskSliderProviderValues.length;providerCounter++){
							if(uiValue == riskSliderProviderValues[providerCounter]){return riskSliderProviderValues[providerCounter + 1];}
						}
					}
				}
				function updateDescriptionArea(){
					uiValue = $("#slider").slider('option','value');
					if (uiValue < riskSliderBounds[0]){
						RiskTextToUse = "";
					}
					else if (uiValue > riskSliderBounds[0] && uiValue < riskSliderBounds[1]){
						RiskTextToUse = RiskTextMinimal;
					}
					else if(uiValue > riskSliderBounds[1] && uiValue< riskSliderBounds[2]){
						RiskTextToUse = RiskTextLow;
					}
					else if(uiValue > riskSliderBounds[2] && uiValue< riskSliderBounds[3]){
						RiskTextToUse = RiskTextMedium;
					}
					else if(uiValue > riskSliderBounds[3] && uiValue< riskSliderBounds[4]){
						RiskTextToUse = RiskTextHigh;
					}
					$("#riskDescription")
					.html("" + RiskTextToUse + "");
				}
				var riskSliderProviderValues = new Array();
				var providerCounter = 0;
				$(".riskinfo p.riskRating").each(function(){
					riskSliderProviderValues[providerCounter] = $(this).text();
					providerCounter++
				});

				$("#slider").slider({
					value: 0,
					min: minRiskRating,
					max: maxRiskRating,
					step: 0.0001,
					start: function(event, ui){
						$("#slider").slider("option","value",snapToNearestResult(ui.value,event));
						ariaAttributes();
						return false;
					},
					slide: function(event, ui){
						$("#slider").slider("option","value",snapToNearestResult(ui.value,event));
						ariaAttributes();
						highLightProvider();
						updateDescriptionArea();
						return false;
					},
					stop: function(event, ui){
						ariaAttributes();
						highLightProvider();
						updateDescriptionArea();
					}
				}).attr("role","application");
				function ariaAttributes(){
					uiValue = $("#slider").slider('option','value');
					var ariaValueText;
					if (uiValue < riskSliderBounds[0]){
						ariaValueText = "No value selected";
					}
					else if (uiValue > riskSliderBounds[0] && uiValue < riskSliderBounds[1]){
						ariaValueText = "Minimal risk fund selected";
					}
					else if(uiValue > riskSliderBounds[1] && uiValue< riskSliderBounds[2]){
						ariaValueText = "Low risk fund selected";
					}
					else if(uiValue > riskSliderBounds[2] && uiValue< riskSliderBounds[3]){
						ariaValueText = "Medium risk fund selected";
					}
					else if(uiValue > riskSliderBounds[3] && uiValue< riskSliderBounds[4]){
						ariaValueText = "High risk fund selected";
					}
					$(".ui-slider-handle").attr({
						"role":"slider",
						"aria-valuemin":minRiskRating,
						"aria-valuemax":maxRiskRating,
						"aria-valuenow":uiValue,
						"aria-valuetext":ariaValueText
					});
				}	
				function addFocusAndClickToProviders(){
					$("#riskSpectrum h4 a").click(function(){
						var setSliderValue = ($(this).parent().next().contents("p").text())				
						$("#slider").slider("option","value",setSliderValue);
						ariaAttributes();
						highLightProvider();				
						updateDescriptionArea();
						return false;	
					}).focus(function(){
						$(this).trigger("click");
					});
				}
				addFocusAndClickToProviders();
				function changeSliderStyle(){
					$("#riskSpectrum .riskinfo").hide();
					$(".ui-slider-horizontal .ui-slider-handle").css({"background-image" : "url(/_common_images/slider/slider-png32.png)","background-color" : "transparent","border": "none","cursor": "pointer","width" : "16px","height" : "37px","top": "27px","margin-left": -1*(($(".ui-slider .ui-slider-handle").width()) / 2)});
				}
				changeSliderStyle();
				function addDescriptionArea(){
					$("<p></p>").insertBefore($("#slider"))
					.html("Use the meter below to see how different products compare, and where within a risk category they are placed. You can use your mouse or tab through to see their position within the Spectrum of Risk.")
					$("<div id=\"riskDescription\"></div>").insertAfter($("#riskListRight"))
				}
				addDescriptionArea();				
				function setDefaultProvider(){
					var uiValue ;
					var H1Text = $(".riskMainArea h1").text().toLowerCase();
					if(H1Text.indexOf("low") != -1){
						uiValue = $("h3:contains('Low') ~ div:first p").text();
					}
					else if(H1Text.indexOf("minimal") != -1){
						uiValue = $("h3:contains('Minimal') ~ div:first p").text();
					}
					else if(H1Text.indexOf("medium") != -1){
						uiValue = $("h3:contains('Medium') ~ div:first p").text();
					}
					else if(H1Text.indexOf("high") != -1){
						uiValue = $("h3:contains('High') ~ div:first p").text();
					}					
					$("#slider").slider('option','value',uiValue);
					ariaAttributes()
					highLightProvider();
					updateDescriptionArea();
				}
				setDefaultProvider();

				function addSliderRiskBoundaries(){
					var pixelsLeft = ((Number(riskSliderBounds[0]) + Math.abs(minRiskRating)) / (maxRiskRating + Math.abs(minRiskRating)))*widthOfSlider;				
					var widthOfSection = (((Number(riskSliderBounds[1]) + Math.abs(minRiskRating)) / (maxRiskRating + Math.abs(minRiskRating)))*widthOfSlider) - pixelsLeft;
					// add the bounds zone to slider area
					$("<div class=\"riskBoundZone\"></div>").appendTo($("#slider"))
					.css({"width":Math.ceil(widthOfSection),"left":pixelsLeft});					
					// add the gradients actual slider area
					$("<div class=\"riskGradients\"></div>").appendTo($("div.riskBoundZone:last"))
					.css({"width":Math.ceil(widthOfSection)});
					// add the text to the area				
					$("<div class=\"riskText\"></div>").appendTo($("div.riskBoundZone:last")).text("Minimal");
					pixelsLeft = ((Number(riskSliderBounds[1]) + Math.abs(minRiskRating)) / (maxRiskRating + Math.abs(minRiskRating)))*widthOfSlider;				
					widthOfSection = (((Number(riskSliderBounds[2]) + Math.abs(minRiskRating)) / (maxRiskRating + Math.abs(minRiskRating)))*widthOfSlider) - pixelsLeft;
					// add the bounds zone to slider area
					$("<div class=\"riskBoundZone\"></div>").appendTo($("#slider"))
					.css({"width":Math.ceil(widthOfSection),"left":pixelsLeft});
					// add the gradients actual slider area
					$("<div class=\"riskGradients\"></div>").appendTo($("div.riskBoundZone:last"))
					.css({"width":Math.ceil(widthOfSection)})
					.gradient({from: 'F2F8FB',to: 'E5F1F6',direction: 'vertical'});
					// add the text to the area				
					$("<div class=\"riskText\"></div>").appendTo($("div.riskBoundZone:last")).text("Low");	
					pixelsLeft = ((Number(riskSliderBounds[2]) + Math.abs(minRiskRating)) / (maxRiskRating + Math.abs(minRiskRating)))*widthOfSlider;				
					widthOfSection = (((Number(riskSliderBounds[3]) + Math.abs(minRiskRating)) / (maxRiskRating + Math.abs(minRiskRating)))*widthOfSlider) - pixelsLeft;
					// add the bounds zone to slider area
					$("<div class=\"riskBoundZone\"></div>").appendTo($("#slider"))
					.css({"width":Math.ceil(widthOfSection),"left":pixelsLeft});				
					// add the gradients actual slider area
					$("<div class=\"riskGradients\"></div>").appendTo($("div.riskBoundZone:last"))
					.css({"width":Math.ceil(widthOfSection)})
					.gradient({from: 'D5E9F1',to: 'ABD2E3',direction: 'vertical'});
					// add the text to the area				
					$("<div class=\"riskText\"></div>").appendTo($("div.riskBoundZone:last")).text("Medium");
					pixelsLeft = ((Number(riskSliderBounds[3]) + Math.abs(minRiskRating)) / (maxRiskRating + Math.abs(minRiskRating)))*widthOfSlider;				
					widthOfSection = (((Number(riskSliderBounds[4]) + Math.abs(minRiskRating)) / (maxRiskRating + Math.abs(minRiskRating)))*widthOfSlider) - pixelsLeft;
					// add the bounds zone to slider area
					$("<div class=\"riskBoundZone\"></div>").appendTo($("#slider"))
					.css({"width":Math.ceil(widthOfSection),"left":pixelsLeft});
					// add the gradients actual slider area
					$("<div class=\"riskGradients\"></div>").appendTo($("div.riskBoundZone:last"))
					.css({"width":Math.ceil(widthOfSection)})
					.gradient({from: 'A6D0E3',to: '4DA1C6',direction: 'vertical'});	
					// add the text to the area				
					$("<div class=\"riskText\"></div>").appendTo($("div.riskBoundZone:last")).text("High");	
					// add the risk rating bounds (the vertical lines)
					var riskSliderBoundCounter = 0;
					for(riskSliderBoundCounter;riskSliderBoundCounter < riskSliderBounds.length;riskSliderBoundCounter++){
						//var pixelsLeft = (riskSliderBounds[riskSliderBoundCounter] / maxRiskRating)*widthOfSlider;
						var pixelsLeft = ((Number(riskSliderBounds[riskSliderBoundCounter]) + Math.abs(minRiskRating)) / (maxRiskRating + Math.abs(minRiskRating)))*widthOfSlider;
						$("<b></b>").appendTo($("#slider")).css({"left":pixelsLeft,"border-left":"1px solid #004499","display":"block","width":"1px","height":"62px","position":"absolute","top":"15px"});
					}
				}
				addSliderRiskBoundaries();
				function addSliderMarkers(){
					for(providerCounter = 0;providerCounter < riskSliderProviderValues.length;providerCounter++){
						var pixelsLeft = ((Number(riskSliderProviderValues[providerCounter]) + Math.abs(minRiskRating)) / (maxRiskRating + Math.abs(minRiskRating)))*widthOfSlider;
						$("<b class=\"sliderMarker\"></b>").appendTo($("#slider")).css({"left":Math.floor(pixelsLeft)});
					}
				}
				addSliderMarkers();
				function addSliderRail(){				
					$("<div id=\"sliderRail\"></div>").appendTo($("#slider")).css({"width":widthOfSlider});				
				}
				addSliderRail();
				$(document).pngFix();
			}
		}
    }
addEvent(window, 'load', riskSpectrum, false);
function riskFundTables(){
	if (jQueryUsed){
		//start
		//splits an alt/title string at the ':' character- taking the first bit as the title and the rest as content
		function AltToHtml(strAlt){
			var html, tmp
			html = "<h4>" + strAlt + "</h4>";
			tmp = strAlt.split(':');
			if (tmp.length>=2){
				html = "<h4>" + tmp[0] + "</h4>"
				for (var i=1; i<tmp.length; i++){html += "<p>" + tmp[i] + "</p>"}
			}
			return html;
		}
		/* add a tooltip div to the page */
		$("body").append("<div id=\"riskTooltip\"></div>");
		/* on mouse over, take either the alt or title text (whats avail?) and update tooltip content, position and show */
		$("#fundRiskTableLegend dl dt , .risktip").mouseover(function(){
				var tipTitle = $(this).attr("title");
				var tipAlt = $(this).attr("alt");
				var tipContent = "";				
				if(!tipAlt || tipAlt.length<=0){tipContent=tipTitle;}
				if(!tipTitle || tipTitle.length<=0){tipContent=tipAlt;}
				$("#riskTooltip").html(AltToHtml(tipContent));
				var tipHeight = parseInt($("#riskTooltip").height());
				var tipWidth = parseInt($("#riskTooltip").width());
				var tipBorder = parseInt($("#riskTooltip").css("border-width").replace("px",""));
				var dtLeft = parseInt($(this).offset().left);
				var dtTop = parseInt($(this).offset().top);		
				$("#riskTooltip").css("left", dtLeft-(tipWidth/2));
				$("#riskTooltip").css("top",  dtTop-tipHeight-8); 				
				$("#riskTooltip").show();
		});
		/* on mouse out, hide and clear tip content */
		$("#fundRiskTableLegend dl dt , .risktip").mouseout(function(){
			$("#riskTooltip").hide();
			$("#riskTooltip").html("");
		});		
	}
}
addEvent(window, 'load', riskFundTables, false);
