document.documentElement.className = 'jsEnabled_acctSelect_live';
$(document).ready(function(){
	var redirectTimer;
	$("select#sList").attr("selectedIndex", 0);
	$("select#sList").change(function(){
//----------Add / edit button URLS below: ----------//
		var URLs_AT = new Array();
			URLs_AT["Default"] = "https://secure2.fxcorporate.com/fxtr/?ib=fxcmuk_cfd_xtp";
			URLs_AT["US"] = "https://secure2.fxcorporate.com/fxtr/?ib=fxcmuk_us_xtp";
			URLs_AT["AU"] = "https://secure2.fxcorporate.com/fxtr/?ib=fxcmau_active_trader";
			
		var URLs_MT = new Array();
			URLs_MT["Default"] = "/metatrader-apply.jsp";
			
		var URLs_CFD = new Array();
			URLs_CFD["Default"] = "/cfd-account-international.jsp";
			URLs_CFD["AU"] = "http://www.forextrading.com.au/cfd-product-info.jsp";
			
		var URLs_FX = new Array();
			URLs_FX["Default"] = "/forex-account-international.jsp";
			URLs_FX["US"] = "/forex-account-us.jsp";
			URLs_FX["AU"] = "http://www.forextrading.com.au/open-an-account-international.jsp";
			
		var URLs_SB = new Array();
			URLs_SB["Default"] = "/spread-betting-account.jsp"

		var URLs_FSS = new Array();
			URLs_FSS["Default"] = "https://secure2.fxcorporate.com/fxtr/?plugin=0&locale=en_US_FSS_UK"

//----------When adding new accounts, be sure to add the reference below as well as above ---//
		var $URLs = new Array ();
			$URLs["AT"] = URLs_AT;
			$URLs["MT"] = URLs_MT;
			$URLs["CFD"] = URLs_CFD;
			$URLs["SB"] = URLs_SB;
			$URLs["FX"] = URLs_FX;
			$URLs["FSS"] = URLs_FSS;
	
			var accts = $("ul#acctBoxWrap").children("li.acctBox");		
			var customGrp = $(".customGrp");	
			var selectedCountryTitle = $("h4#selectedCountry");
			var selectedOption = $(this).children("option:selected");
			var selectedClass = $(selectedOption).attr("class");
			var theLink = $("a.goToHere");
			
			//reset all elements
			$(selectedCountryTitle).removeClass("on").text("");
			$(accts).hide();
			$(customGrp).children().hide();
			clearTimeout(redirectTimer); // clear timeout if it was set in a custom group element from a previous selection
			if (selectedOption.val() != "") {
				var acctsToShow = $(accts).filter(".for" + selectedClass);	
				//	if selected class is empty, set acctsToShow to default
				if (selectedClass == "") {
					acctsToShow = $(accts).filter(".forDefault");
					selectedClass = "Default"
				}
				else if (selectedClass != "") {
					//check for existence of div.acctBox with the the class of selectedClass
					if (acctsToShow.length != 0) {
						acctsToShow = $(accts).filter(".for" + selectedClass);
					}
					else if (acctsToShow.length == 0) {
						acctsToShow = $(accts).filter(".forDefault");
					}
				}
				// loop through each acct box
				for (var i = 0; i < acctsToShow.length; i++) {
					var currAcct = $(acctsToShow).eq(i);
					var currAcctType = $(currAcct).attr("id");
					/* if current box is NOT a custom box   */		
					if($(currAcct).attr("class").indexOf("customBox") == -1 ){
						//display customGrp elements
						var currCustomGrps = $(currAcct).find(".customGrp");
						for (var n = 0; n < currCustomGrps.length; n++){
							var thisGrp = $(currCustomGrps).eq(n).children();
							if (selectedClass == "Default") {
								$(thisGrp).filter(".for" + selectedClass).show();
							}
							else if (selectedClass != "Default"){ 
								if (($(thisGrp).filter(".for" + selectedClass).length == 0) && ($(thisGrp).filter(".not" + selectedClass).length == 0)) {
									$(thisGrp).filter(".forDefault").show();
								}
								else {
									$(thisGrp).filter(".for" + selectedClass).show();
								}
							}
						}
						//feed correct url to submit buttons
						var currBtn = $(currAcct).children("a.sBtn");
						var currAcctURLArray = $URLs[currAcctType];
						var currAcctURL = $URLs[currAcctType][selectedClass];
						if (currAcctURL == undefined) {
							currAcctURL = $URLs[currAcctType]["Default"];
						}
						$(currBtn).attr("href", currAcctURL);
						//add target blank to external URLs
						if (currAcctURL.indexOf("http") != -1) {
							$(currBtn).attr("target", "_blank");
						}
						//add margin to even boxes
						if (i%2 == 0) {
							$(currAcct).addClass("addMargin");
						}
						else if (i%2 != 0) {
							$(currAcct).removeClass("addMargin");
						}
					}
					/* if current box IS a custom box */
					else if($(currAcct).attr("class").indexOf("customBox")){
						var curRedirect = $(currAcct).find("a.redirectLink");
						if($(currAcct).length == 1 && $(curRedirect).length > 0){
							var newURL = $(curRedirect).attr("href");
							redirectTimer = setTimeout ("window.location=('"+newURL+"')",12000);
						}
					}
				}
				$(selectedCountryTitle).addClass("on").text(selectedOption.val());
				$(acctsToShow).show();
			}
	});
 }); 
// For instructions, please see: /2009_JAVA/FXCM_UK/web/js/content/acctSelect_live_instructions.doc 
//	
//	11.26.09:
//	Ammended customGrp functionality to allow exclusion of one country. ie, adding "notXX" to prevent a default element from displaying in the case of the selected country not having an associated custom element
//  1.14.10:
//  added redirectLink capabilities
//
