var currentSection = null;
var currentSubSection = null; // set this to null...may reset it later...
var swap = (document.images)?true:false;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function preLoad(section) {
	var lFlag = '_e.';
	if (document.location.href.indexOf('-f.') != -1 || document.location.href.indexOf('_f.') != -1) {
		lFlag = '_f.';
	}
	
	// Preload section-specific navigation images
	if (section == "about"){
		MM_preloadImages('http://www.fptt-pftt.gc.ca/images/leftNav/about/history2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/about/vision2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/about/program2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/about/annual2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/about/benefits2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/about/join2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/about/advisory2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/about/partners2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/about/techtransfer2' + lFlag + 'gif')
	} else if (section == "success"){
		MM_preloadImages('http://www.fptt-pftt.gc.ca/images/leftNav/success/awards2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/success2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/success/awards20042' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/success/awards20032' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/success/awards20022' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/success/awards20012' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/success/awards20002' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/success/awards19992' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/success/awards19982' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/success/century2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/success/links2' + lFlag + 'gif')
	} else if (section == "resources"){
		MM_preloadImages('http://www.fptt-pftt.gc.ca/images/leftNav/resources/publications2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/resources2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/resources/fptt-documents2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/resources/non-fptt-documents2' + lFlag + 'gif','http://www.fptt-pftt.gc.ca/images/leftNav/resources/resources2' + lFlag + 'gif')
	} else if (section == "business"){
		MM_preloadImages('http://www.fptt-pftt.gc.ca/images/leftNav/business/members2' + lFlag + '.gif','http://www.fptt-pftt.gc.ca/images/leftNav/business2' + lFlag + '.gif')
	} else if (section == "members"){
		MM_preloadImages('http://www.fptt-pftt.gc.ca/images/leftNav/members/agenda2' + lFlag + '.gif','http://www.fptt-pftt.gc.ca/images/leftNav/eoactivity2' + lFlag + '.gif','http://www.fptt-pftt.gc.ca/images/leftNav/membership2' + lFlag + '.gif','http://www.fptt-pftt.gc.ca/images/leftNav/whatsnew2' + lFlag + '.gif','http://www.fptt-pftt.gc.ca/images/leftNav/proceedings2' + lFlag + '.gif','http://www.fptt-pftt.gc.ca/images/leftNav/agora2' + lFlag + '.gif')
	}	
	
	// Preload all main navigation images		
	MM_preloadImages(
		'http://www.fptt-pftt.gc.ca/images/leftNav/home2' + lFlag + 'gif',
		'http://www.fptt-pftt.gc.ca/images/leftNav/about2' + lFlag + 'gif',
		'http://www.fptt-pftt.gc.ca/images/leftNav/training_resources2' + lFlag + 'gif',
		'http://www.fptt-pftt.gc.ca/images/leftNav/federal2' + lFlag + 'gif',
		'http://www.fptt-pftt.gc.ca/images/leftNav/success2' + lFlag + 'gif',
		'http://www.fptt-pftt.gc.ca/images/leftNav/resources2' + lFlag + 'gif',
		'http://www.fptt-pftt.gc.ca/images/leftNav/business2' + lFlag + 'gif',
		'http://www.fptt-pftt.gc.ca/images/leftNav/news2' + lFlag + 'gif',
		'http://www.fptt-pftt.gc.ca/images/leftNav/faq2' + lFlag + 'gif',
		'http://www.fptt-pftt.gc.ca/images/leftNav/listserv2' + lFlag + 'gif');
	
	// possibly highlight a side navigation item
	// try to determine the subfolder for third state highlight
	if (swap) {
		var currentSectionArray = new Array('about', 'training', 'training_resources', 'fedlabs', 'success', 'resources', 'business', 'news', 'faq', 'listserv', 'members', 'agora');
		for (var z = 0; z < currentSectionArray.length; z++) {
			if (document.location.href.indexOf('/' + currentSectionArray[z] + '/') != -1) {
				currentSection = currentSectionArray[z];
				break;
			}
		}
		
		var subArray_about = new Array('history', 'vision', 'program', 'annual', 'benefits', 'join', 'advisory', 'partners', 'techtransfer');
		var subArray_training = new Array('internship', 'workshops', 'university', 'management', 'add');
		var subArray_success = new Array('awards', 'objectives', 'awards2004', 'awards2003', 'awards2002', 'awards2001', 'awards2000', 'awards1999', 'awards1998', 'century', 'links');
		var subArray_business = new Array('membersOpp');
		var subArray_members = new Array('whatsnew', 'membership', 'eoactivity', 'agenda', 'proceedings','agora');
		
		if (currentSection == 'training' || currentSection == 'resources') {
			currentSection = 'training_resources';
		}
				
		if (!currentSection) {
			currentSection = 'home';
		}
		else if (currentSection == 'about' || currentSection == 'training' || currentSection == 'success' || currentSection == 'business' || currentSection == 'members') {
			for (var z = 0; z < eval('subArray_' + currentSection).length; z++) {
				if (document.location.href.indexOf('/' + currentSection + '/' + eval('subArray_' + currentSection)[z] + '/') != -1) {
					currentSubSection = eval('subArray_' + currentSection)[z];
					break;
				}
			}
		}
		
	}
	
	if (swap && currentSection != 'agora') {
		document.images[currentSection].src = 'http://www.fptt-pftt.gc.ca/images/leftNav/' + currentSection + '2' + lFlag + 'gif';
		
		if (currentSubSection) {
			document.images[currentSubSection].src = 'http://www.fptt-pftt.gc.ca/images/leftNav/' + currentSection + '/' + currentSubSection + '2' + lFlag + 'gif';
		}
	}
}
