var contextPath = "";

function setContextPath(value) {
	contextPath = value;
}

function getContextPath() {
	
	return contextPath;
}
// Fonction fontSizeChange: augmente ou diminue la taille de la police

 function fontSizeChange(changeType) {
 	var maxTextSize = 3;
 	var minTextSize = -2;
	var docFontSizeElement=document.getElementById("docFontSize");
	var textSize=new Number(docFontSizeElement.value);
	var changeTypes=new Array("Small","Big");
	var texteSizeString=new Array;
	texteSizeString[-2]="Small2";
	texteSizeString[-1]="Small1";
	texteSizeString[0]="";
	texteSizeString[1]="Big1";
	texteSizeString[2]="Big2";
	texteSizeString[3]="Big3";
	if(changeType == "Small") {
	 	textSize -= 1;	 
	 } else { 
	 	textSize += 1;		 
	 }
	docFontSizeElement.value=textSize;
	var listeDiv=document.getElementsByName("mainhelp");

	for (var i=0; i<listeDiv.length; i++)
		{
			if (listeDiv[i].className!=""){
				var newClass=listeDiv[i].className;
				for (var t=0; t<changeTypes.length; t++)
				{
					if (newClass.indexOf(changeTypes[t])>=0 ){
						newClass=newClass.substring(0,newClass.indexOf(changeTypes[t]));
					}
				}
				newClass+= texteSizeString[textSize];
				listeDiv[i].className=newClass;
			}
		}


	if (textSize>=maxTextSize){
		displayFontSizeAction("Big",false);
		displayFontSizeAction("Small",true);
			
	}
	if  (textSize<=minTextSize){
		displayFontSizeAction("Big",true);
		displayFontSizeAction("Small",false);		
	}
	
}

function displayFontSizeAction(changeType,link){
		if (link){
			document.getElementById("docFont"+changeType).style.display="inline";
			document.getElementById("docFont"+changeType+"Img").style.display="none";
		}else{
			document.getElementById("docFont"+changeType).style.display="none";
			document.getElementById("docFont"+changeType+"Img").style.display="inline";
		}
}				
				
	function showPictoLabel(theLabel){
	document.getElementById('pictoLabel').innerHTML=theLabel;
}

function iecompattest(){ 
	//return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body 
	return document.documentElement 
}

function FloatDiv(idDiv, startX, startY)
{
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	
	function ml(id)
	{
		alert('mlstart');
		var el=d.getElementById(id); 
		//el.style.visibility="visible"; 
		if(d.layers)el.style=el; 
		el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";}; 
		el.x = startX;
		alert(el.x);
		//if (verticalpos=="fromtop") 
		el.y = startY; 
		/*else{ 
			el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight; 
			el.y -= startY; 
		} */
		
		alert('mlend');
		return el; 	
	}
	
	window.stayTopLeft=function(){ 
		//if (verticalpos=="fromtop"){ 
			var pY = ns ? pageYOffset : iecompattest().scrollTop; 
			ftlObj.y += (pY + startY - ftlObj.y)/8; 
		/*} else{ 
			var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight; ftlObj.y += (pY - startY - ftlObj.y)/8; 
		} */
		ftlObj.sP(ftlObj.x, ftlObj.y); 
		setTimeout("stayTopLeft()", 10); 
	} 
	
	ftlObj = ml(idDiv); 
	alert('calling stayTopLeft');
	stayTopLeft();
	alert('done stayTopLeft');
}

function FloatTopDiv(idDiv, startX, startY)
{
	function ml(id)
	{
		var el= doc_get( id );
		if(document.layers) el.style=el;
  		el.sP= function(x,y){this.style.left=x+'px';this.style.top=y+'px';}
		el.x = startX;
		el.y = startY;
		return el;
	}
	window.stayTopLeft=function()
	{
		var pY;
		switch(MODE) {
			case 'IE6': pY = document.body.scrollTop; break;
			default: pY = pageYOffset;
		}
		 
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml(idDiv);
	stayTopLeft();
}


function leftmenu_off() {
  document.getElementById('astd.leftmenu').style.display = 'none';
  document.getElementById('nav_tab').src           = leftmenu_images['show']; //'/gfx/show_nav.png';
  document.getElementById('nav_tab').title         = 'Show left menu';
  setCookie("hidden","1",null,null,".ebi.ac.uk",null);
}

function leftmenu_on() {
  document.getElementById('astd.leftmenu').style.display = 'block';
  document.getElementById('nav_tab').src           = leftmenu_images['hide']; //'/gfx/hide_nav.png';
  document.getElementById('nav_tab').title         = 'Hide left menu';
  setCookie("hidden","0",null,null,".ebi.ac.uk",null);
}

function leftmenu_toggle() {
  if (document.getElementById('astd.leftmenu').style.display == 'none'){
    leftmenu_on();
  } else {
    leftmenu_off();
  }  
}  

// set the Cookie
function setCookie(name,value,expires,path,domain,secure) {
  document.cookie = name + "=" +escape(value) +
  ( (expires) ? ";expires=" + expires.toGMTString() : "") +
   ";path=/" + 
  ( (domain) ? ";domain=" + domain : "") +
  ( (secure) ? ";secure" : "");
}

// grab the Cookie
function getCookie(name) {
  var start = document.cookie.indexOf(name+"=");
  var len   = start+name.length+1;
  if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
  if (start == -1) return null;
  var end = document.cookie.indexOf(";",len);
  if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len,end));
}

var MENU_HTML;

function menu_swapmain(root_path, workbench_path) {
d = new dTree('d', root_path);
		d.add(0,-1,'ASTD','javascript: void(0);', 'Main menu', null, root_path +'/img/v1/icons/asterisk_orange.png', root_path +'/img/v1/icons/information.png');
		d.add(1,0,'Home',root_path +'/main.html', 'Home Page', null, root_path +'/img/v1/icons/house.png');
		d.add(2,0,'Advanced Search',root_path +'/advancedquery.html', 'Advanced Search', null, root_path +'/img/v1/icons/magnifier.png');
		d.add(3,0,'Workbench',workbench_path, 'Workbench', null, root_path +'/img/v1/icons/cog.png');		
		d.add(4,0,'Releases',root_path +'/releases.html', 'Releases', null, root_path +'/img/v1/icons/database.png');
		d.add(5,0,'Statistics','javascript:void(0);', 'Statistics', null, root_path +'/img/v1/icons/chart_curve.png', root_path +'/img/v1/icons/chart_curve.png');
	    d.add(1,5,'Human',root_path +'/statistics.html?tax=9606', 'Statistics for Homo Sapiens', null);
	    d.add(2,5,'Mouse',root_path +'/statistics.html?tax=10090', 'Statistics for Mus Musculus', null);
	    d.add(3,5,'Rat',root_path +'/statistics.html?tax=10116', 'Statistics for Rattus Norvegicus', null);
		d.add(6,0,'Download',root_path +'/download.html', 'Download', null, root_path +'/img/v1/icons/arrow_down.png');
		d.add(7,0,'Documentation',root_path +'/docs.html', 'Documentation', null, root_path +'/img/v1/icons/information.png');
		d.add(8,0,'Publications',root_path +'/publications.html', 'Publications', null, root_path +'/img/v1/icons/book_open.png');
		d.add(9,0,'Team',root_path +'/team.html', 'Team', null, root_path +'/img/v1/icons/group.png');
		d.add(10,0,'Contact',root_path +'/contact.html', 'Contact', null, root_path +'/img/v1/icons/email.png');
		//document.write(d);
		var menu = doc_get("astd.leftmenu");
		menu.innerHTML = d.toString();
		d.openAll();	
}

function menu_item(element, index, array) {
	MENU_HTML += '<li class="clickmeopen" style="display: block;"><a href="javascript:doc_anchor(\'' + element + '\')">' + element + '</a></li>';
}

function menu_sticky(objref) {
	
	var ie=document.all && !window.opera
	var dom=document.getElementById
	iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
    var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
    var docwidth=(ie)? iebody.clientWidth : window.innerWidth
    docheight=(ie)? iebody.clientHeight: window.innerHeight
    var objwidth=objref.offsetWidth
    objheight=objref.offsetHeight
    //objref.style.left=docwidth/2-objwidth/2+"px"
    objref.style.top=scroll_top+docheight/2-objheight/2+"px"

}


function menu_swapview_ebi(content_titles) {
		
		MENU_HTML = '<ul id="sidemenuid" class="sidemenu">';
		MENU_HTML += '<li class="leftmenudividersubheading">Table of Contents</li><li class="leftmenudivider"/>';
		/* content_titles.forEach(menu_item); */
		/* previous function not supported in IE */
		for (x in content_titles) {
			MENU_HTML += '<li class="clickmeopen" style="display: block;"><a href="javascript:doc_anchor(\'section_' + x + '\')">' + content_titles[x] + '</a></li>';
		}
		MENU_HTML += '</ul>';
		// replace the main menu with
		// a table of contents menu
		var menu = doc_get("astd.leftmenu");
		//alert(MENU_HTML);
		menu_sticky(menu);
		menu.innerHTML = MENU_HTML;
		//FloatTopDiv("sidemenuid",0,60);
}

function menu_swapview(content_titles) {
		
		d = new dTree('d', contextPath);
		d.add(0,-1,'Table of Contents','javascript: void(0);', 'Table of Contents', null, contextPath +'/img/v1/icons/asterisk_orange.png', contextPath +'/img/v1/icons/information.png');
		d.add(1,0,'top of the page', 'javascript:doc_anchor(\'pageTop\');', 'top of the page', null, contextPath +'/img/v1/icons/bullet_arrow_up.png');
		for (x in content_titles) {
			d.add(x+1,0,content_titles[x],'javascript:doc_anchor(\'section_' + x + '\')', content_titles[x], null,  contextPath +'/img/v1/blank.gif');			
		}
		var menu = doc_get("astd.leftmenu");
		menu.innerHTML = d.toString();
		d.openAll();

}

