//GLOBAL VARIABLES			
	//SELECT TO LIST LINKS - (transform select box into ul list)
		var isMSIE = (navigator.userAgent.indexOf("MSIE")!=-1);
		var isMACIE = (isMSIE && navigator.userAgent.indexOf("Mac")!=-1);
		var isSAFARI = (navigator.userAgent.indexOf("Safari")!=-1);
	
		var objSelectToList;
		var objLastTd = null;
		var objSelectToListSpanPlus= null;
		
	//HOVERS AND COLOURS
		var strTImgPath = 'images/t_images/';
		var strButtonHoverBgColour = "#FF0008";
		var strButtonHoverColour = "#ffffff";
		var strPlusHover = "#2385AC";
		var strTdHover = "#2486AB";
		
	// simon - include jquery.
	document.write('<script type="text/javascript" src="/javascript/jquery-1.2.6.min.js"></scr' + 'ipt>'); 

		function addEvent(obj,strEventType,strFunction){//,objA,objB
		//idea from: http://ejohn.org/projects/flexible-javascript-events/
		//note: mac ie is temperamental - multiple calls to append element might ne unstable
			var arrParams = new Array();
			var intInc = 0;
			for(var i = 3; i < addEvent.arguments.length; ++i){
				//this won't work - strFunction  = strFunction.replace(/\)/,",'arguments["+i+"]')");
				//neither will this - strFunction  = strFunction.replace(/\)/,",arguments["+i+"])");										
				
				//but this will work. For some reason you can't send function.arguments to another function,
				//but if i set a variable to equal the argument then it does work
				arrParams[intInc] = addEvent.arguments[i];
				strFunction  = strFunction.replace(/\)/g,",arrParams["+intInc+"])");
				++intInc;
			}
			if(document.attachEvent){//msie
				strFunction  = strFunction.replace(/\'evt\'/,'window.event');
				obj.attachEvent("on"+strEventType,function(){eval(strFunction);},true);
			}else if(document.addEventListener){//mozilla
				strFunction  = strFunction.replace(/\'evt\'/,'evt');
				obj.addEventListener(strEventType,function(evt){eval(strFunction)},true);
			}else{
				if(isMACIE){//macie
					strFunction  = strFunction.replace(/\'evt\'/,'window.event');
				}else{//?
					strFunction  = strFunction.replace(/\'evt\'/,'evt');
				}
				eval('obj.on'+strEventType+' = ' + function(evt){eval(strFunction)});
			}
		}
		function hover(evt,isOn,obj){			
			obj.style.color = (isOn)?strPlusHover:"";
		}
		function selectThis(evt,strValue,objSelect,objTd){
			evt=(evt)?evt:window.event;
			if(objSelect){
				objSelect.value = strValue;
				
				//ACTIVATE THE SELECT BOX ONCHANGE EVENT
				var strOnChange = objSelect.getAttribute("onchange");	
				if(strOnChange){
					if(isMSIE){
						strOnChange = "" + strOnChange;
						strOnChange=strOnChange.substring(strOnChange.indexOf("{")+1,strOnChange.indexOf("}"));
						strOnChange=strOnChange.replace(/^[\s]*/,"");						
					}
					//strOnChange = strOnChange.replace(/this\.value/,"'"+objSelect.value+"'");
					//EITHER ABOVE OR BELOW
					strOnChange = strOnChange.replace(/this/,'objSelect');
					//alert("strOnChange=" + strOnChange)
					eval(strOnChange);
				}
				//HIGHLIGHT TD AND CHECKFORMS SWITCH BUTTON
				//selectItem(evt,objSelect,objTd)
				return false;
			}
		}
		function updateSpan(evt,strLiContent,objSelect,objTd){
			
			evt=(evt)?evt:window.event;
			//SET LI TAG TO UPDATE OPTION BOX WHEN CLICKED
			objSelectToListSpanPlus = null;
			var objSpans = objTd.getElementsByTagName("span");
			for(var i = 0; i < objSpans.length; ++ i){
				if(objSpans[i].className =="plus"){
					objSelectToListSpanPlus = objSpans[i];
					break;
				}
			}
			if(objSelectToListSpanPlus){
				if(isMSIE){
					strLiContent=(strLiContent!="")?strLiContent:"&nbsp;";
				}//RECALCULATE				
				objSelectToListSpanPlus.innerHTML = strLiContent;
			}
			
		}
		function goTo(strLink){
			location.href=strLink;
		}		
		function SelectToList(evt,obj,isShow){
			evt=(evt)?evt:window.event;			
		//SELECT TO LIST
			//note: mac ie is temperamental - multiple calls to append element might cause browser to crash
			if(isShow){
				if(SelectToList.arguments.length > 3){
					objTd = SelectToList.arguments[3];			
	
				//1) clear selectToListLinks from last td element before recreating
					if(objLastTd){
						var objTdDivs = objLastTd.getElementsByTagName("div");
						for(var i = 0; i < objTdDivs.length;++i){
							if(objTdDivs[i].className=="selectToListLinks"){
								//clear all appended elements from objSelectToList
								if(objSelectToList.getElementsByTagName("ul").length){
									//this seems to stop IE 5 from continuing to work after first click
									//objSelectToList.removeChild(objSelectToList.getElementsByTagName("ul")[0]);
									//objSelectToList.removeChild(objSelectToList.getElementsByTagName("div")[0]);
									
									//this works much faster
									objSelectToList.innerHTML = "";
								}
								
								//clear objSelectToList from last td
								objLastTd.removeChild(objTdDivs[i]);
								if(!isMSIE && !isSAFARI){
								//solve flicking problem for mozilla
									document.body = document.body;
								}
							}
						}
					}
				//2) copy td select box as list into objSelectToList
					var objUL = document.createElement('ul');		
					
					//get select box inside td
					var objSelect = objTd.getElementsByTagName('select')[0];
					var objOptions = objSelect.options;
					var strSelectId = objSelect.id;
					//extra data from select box options and build list from options
					
					//START FROM 1, dont include empty value
					var intStart = (objOptions[0].value=="")?1:0;
					for (var i=intStart; i<objOptions.length; i++) {						
						var strLiValue = objOptions[i].value;
						var strLiContent = objOptions[i].innerHTML;
						objLi = document.createElement('li');
						strText = "" + objOptions[i].text;
						objLi.innerHTML = strText;
						
						objLi.innerHTML = (strText=="")?'[unselect]':strText;
						addEvent(objLi,"click","selectThis('evt','"+strLiValue+"');updateSpan('evt','"+strLiContent+"')",objSelect,objTd);
						addEvent(objLi,"mouseover","hover('evt',1)",objLi);
						addEvent(objLi,"mouseout","hover('evt',0)",objLi);
						
						objUL.appendChild(objLi);
					}
					//copy ul into objSelectToList
					objSelectToList.appendChild(objUL);
	
					//create extra element for ie to clear float
					var objClear = document.createElement('div');
					objClear.setAttribute("class","endfloat");
					if(isMSIE){
						objClear.className = "endfloat";
					}
					objSelectToList.appendChild(objClear);
				
				//3) determine whether to display div above or below span
					if(isMSIE){
						var intScreenH = parseInt(document.body.clientHeight);//IF VALUE IS ZERO - set css * html body{height:100%}
						var intScreenW = parseInt(document.body.clientWidth);
					}else{
						var intScreenH = parseInt(window.innerHeight);
						var intScreenW = parseInt(window.innerWidth);
					}
					//object line height 13px plus
					var intLines = objOptions.length;//dynamic - dependent on how many in select box
					var intLineHeight = 13;
					var intObjHeight = (intLines * intLineHeight);
	
					//SAFARI treats clientY as pageY (pageY is the Y position relative to the top chrome including the height of the scroll)
					var intPosH = parseInt(evt.clientY);
					intPosH = (isSAFARI)?intPosH  - document.body.scrollTop:intPosH;
					
					var intSpace = 30;
					isDisplayAbove = ((intObjHeight + intPosH + intSpace) >= intScreenH)?1:0;
					
				//4) append div to td element adjusting margins appropriate to display above or below						
					/*
					if(isDisplayAbove){
						intObjHeight = (isMSIE)?intObjHeight + 14:intObjHeight - 8;
						if(isMSIE){
							objSelectToList.style.marginTop = ("-" + intObjHeight + "px");
						}else{
							objSelectToList.style.marginTop = ("-" + intObjHeight + "px");
						}
						if(!isMSIE && !isSAFARI){
							//solve flicking problem for mozilla after changing the dom
							document.body = document.body;
						}
						objTd.appendChild(objSelectToList);
					}else{
						if(isMSIE){
							objSelectToList.style.marginTop = "0px";
						}else{
//objSelectToList.style.marginTop = "19px";
						}
						if(!isMSIE && !isSAFARI){
							//solve flicking problem for mozilla after changing the dom
							document.body = document.body;
						}
						
						objTd.appendChild(objSelectToList);
					}
					*/
					objTd.appendChild(objSelectToList);
					
				}				
				
				//5) make objSelectToList visible
				objSelectToList.style.visibility = 'visible';
				
				//create variable to equal the last td element that was created
				//if this function is called again, the last objSelectToList must be removed before recreating
				objLastTd = objTd;
	
			}else if(!isShow){
				//cant remove element because it causes div to dissappear in firefox when rolling from span to div, even if adjacent to or on top of.
				objSelectToList.style.visibility = 'hidden';
			}
		}
		
							
		function onloadFunctions(){			
			//SELECT TO LIST
			if(!isMACIE){//too much appending causes mac ie to crash
			
				//2) create div element - objSelectToList
				//note: this needs to have been already declared as a global variable for SelectToList
				objSelectToList = document.createElement('div');
				objSelectToList.setAttribute("class","selectToListLinks");
				if(isMSIE){
					objSelectToList.className = "selectToListLinks";
				}
				
				//3) attach events to div element - objSelectToList
				addEvent(objSelectToList,"mouseover","SelectToList('evt',objSelectToList,1)");
				addEvent(objSelectToList,"mouseout","SelectToList('evt',objSelectToList,0)");
				addEvent(objSelectToList,"click","SelectToList('evt',objSelectToList,0)");
				
				//4) loop all divs
				var objAllDivs = document.getElementsByTagName("div");
				for (var i = 0; i < objAllDivs.length; ++i){
					if(objAllDivs[i].className == 'selectToList'){
						//5) add mouseover all all divs with class = selectToList in order to display - objSelectToList
						addEvent(objAllDivs[i],"click","SelectToList('evt',objSelectToList,1)",objAllDivs[i].parentNode);
						addEvent(objAllDivs[i],"mouseover","hover('evt',1)",objAllDivs[i]);
						addEvent(objAllDivs[i],"mouseout","hover('evt',0)",objAllDivs[i]);
					}
				}
			}
			
			// SIMON - load the countdown onload here also, if we load it in the "<body onload=" html tag then we orphan this.
			//countdown(year,month,day,hour,minute);
			
			// the sliding menus functionality - register handlers etc.
			collapsing_nav();
		}
		onload = onloadFunctions;	
		
		
////////////////// COLLAPSING MENUS - jquery ///////////////////////////		
// infinite depth lists.

//var PAGE_GROUP = "NO_PAGE_GROUP_DEFINED"; // A global variable to hold the page group - set on each actual page.

	function collapsing_nav() {
		
// REMOVE ALL THIS - SET THE APPROPRIATE STYLE ON THE ACTUAL PAGE.
//		//alert("wp1 start");		
		//$("#collapsing-nav li").find("ul").hide();
//
//	var sPath = window.location.pathname;
//	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
//	//alert(sPage);
//
//	// Find the page and open the appropriate menu.
//	if( 
//		(sPage == "tq_markets.shtml") 
//		|| 
//		(sPage == "tq_services.shtml") 
//		|| 
//		(sPage == "tq_clearing.shtml")
//		||
//		(sPage == "tq_trading.shtml")
//		||
//		(sPage == "tq_calendar.shtml")
//		||
//		(sPage == "tq_referencedata.shtml")
//		||
//		(sPage == "tq_tariff_download.shtml")
//		||
//		(sPage == "tq_vendors.shtml")
//		||
//		(sPage == "tq_newproducts_services.shtml")
//
//	)
//	{
//		//alert( "page group is GGGGGG" );
//		$("#trading_on_turquoise_group").show();
//		$("#inner_trading_on_turquoise_group").show();		
//	}
//	else if(
//		(sPage == "tq_tailor_made_contracts.shtml")
//	){
//		//turquoise_derivatives
//		//alert( "page group is GGGGGG" );
//		$("#turquoise_derivatives_products").show();
//		$("#inner_turquoise_derivatives_products").show();		
//		
//	}
//	else if(
//		(sPage == "tq_russia.shtml")
//		||
//		(sPage == "klkjlkj")
//		||
//		(sPage == "tq_russia_trading_hours.shtml")
//		||
//		(sPage == "tq_russia_expiry_cycles.shtml")
//	){
//		//turquoise_derivatives
//		//alert( "page group is GGGGGG" );
//		$("#turquoise_derivatives_products").show();
//		$("#inner_turquoise_derivatives_products").show();
//		$("#russia_and_IOB").show();		
//	}
		
//		$("body").addClass("enhanced");
	//	$("#collapsing-nav li:first").addClass("selected");
	//	$("#collapsing-nav li").not(":first").find("ul").hide();
	
		
	//$("#collapsing-nav > li").find("ul").hide(); // simon - taken from line above - hide all submenus to start with.

	// simon - try to expand appropriate menu items for the page we are on.
	//var pagegroup = $("body").attr('class'); // this is a bit crude - assumes only one class for the body element.
	
//	if( pagegroup	== "trading_on_turquoise_group" )
//	{
//		//alert("good xyzpage .." + pagegroup + "..");
//		$("#trading_on_turquoise_group").slideDown("fast");
//		$("#inner_trading_on_turquoise_group").slideDown("fast");		
//	}
//	else if( PAGE_GROUP	== "who_we_are_group" )
//	{		
//		alert("pagegroup is .." + PAGE_GROUP + "..");
//		$("#whowearegroup").slideDown("fast");
//	}
//	else if( pagegroup	== "all_menus_collapsed" )
//	{		
//		// do nothing - leave menus in collapsed state.
//	}
//	else if( pagegroup	== "membership_group" )
//	{		
//		$("#membership_group").slideDown("fast");
//		$("#inner_membership_group").slideDown("fast");		
//	}
//	else
//	{
//		alert("page menu category not recognised .." + pagegroup + "..");
//	}
	
	
	
//all_menus_collapsed	



		
$(".secondsp").click(function()
{
	//alert("wp55 - secondsp");
	$(this).parent().addClass("selected");
	if ($(this).parent().find("ul").is(":visible")) 
	{
		// Compress menu if it is already uncompressed.
		//alert("wp351111");

				$(this).removeClass("selectedsecondsp");
				$(this).addClass("secondsp");

		$(this).parent().removeClass("selected");
		$(this).parent().find("ul").slideUp("fast");
	}
	else 
	{
		$(".selectedsecondsp").addClass("secondsp");
		$(".selectedsecondsp").removeClass("selectedsecondsp");
				$(this).removeClass("secondsp");
				$(this).addClass("selectedsecondsp");

		
		$(this).parent().children().slideDown("fast"); // revealing only direct child ULs, not all nested ULs
		// simon. we want to un-highlight any anchors if we have clicked on (an so highlighted) a span.
		$("#collapsing-nav a").css("color", "#666667");
	}
});		
		
//$("#collapsing-nav li span").click(function() 
$(".topsp").click(function() 
{
	//alert("wp66 - topsp");
	if ($(this).parent().find("ul").is(":visible")) 
	{
		// Compress menu if it is already uncompressed.
		//alert("wp1111");
		$(this).parent().removeClass("selected");
		//$(this).parent().removeClass("topsp");
		
		$(this).removeClass("selectedtopsp");
		$(this).addClass("topsp");
		
		$(this).parent().find("ul").slideUp("fast");
		
	}
	else 
	{
		//alert("wp2");
						
		// added by simon - we want single menu expanded.		
		$("#collapsing-nav ul").slideUp("fast");
		
		//$("#collapsing-nav ul").slideUp("fast");
		// Simon - we want to keep the selected span item as coloured for "selected", however, first we set all top level span items to "unselected" colour scheme then
		// set the single span item we want coloured as "selected".
		$(".selectedtopsp").addClass("topsp");
		$(".selectedtopsp").removeClass("selectedtopsp");
		
		
		//$("#collapsing-nav > li").removeClass("selected");

		//$(this).parent().addClass("selected");
		$(this).removeClass("topsp");
		$(this).addClass("selectedtopsp");
		
		$(this).parent().children().slideDown("fast"); // revealing only direct child ULs, not all nested ULs
	}
});


}

//$(collapsing_nav);
		
		
		

