// JavaScript Document

function experimentHeader(exp)
{
    document.write('<br> <p class="head">Experiment ');
	if ( exp < 10 ) document.write('0');
	document.write(exp,':<br>');
	document.write(expInfo[exp][expInfoTitle]);
	document.write('<br>');
	document.write(expInfo[exp][expInfoLocation]);
    document.write('<p class="subhead">');
	document.write(expInfo[exp][expInfoRecordings]);
}

function experimentKeywords(exp)
{
    document.write('<p align="justify" class="normal"><em>Keywords</em>: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ');
	if ( expInfo[exp][expInfoKeywords] )
		document.write(expInfo[exp][expInfoKeywords]);
	else if ( expInfo[exp][expInfoKeyword] )
		document.write(expInfo[exp][expInfoKeyword]);

    document.write('</p>');
}

function hrefExperiment(exp,text)
{
	var zero = '';
	if ( exp < 10 )
		zero = '0';
	
	var hrefExp = "'hrefExp"+zero+exp+"'";
	var setTip  = '"setExperimentTip('+exp+', '+hrefExp+')"';
	document.write('<a href="../experiments/exp',zero,exp,'SubStart.html"');
	document.write(' target="mainFrame" class="normal"');
	document.write(' onMouseOver=',setTip);
	document.write(' onClick=selectExperiment(',exp,')');
//	document.write(' );');
	document.write(' id=',hrefExp,'> Experiment ', zero, exp, ' (', expInfo[exp][expInfoTitle],')</a>');
}

function linkExperiment(exp)
{
	var zero = '';
	if ( exp < 10 )
		zero = '0';
	
	var linkExp = "'linkExp"+zero+exp+"'";
	var setTip  = '"setExperimentTip('+exp+', '+linkExp+')"';
	document.write('<a href="../experiments/exp',zero,exp,'SubStart.html"');
	document.write(' target="mainFrame" class="normal"');
	document.write(' onMouseOver=',setTip);
	document.write(' onClick=selectExperiment(',exp,')');
//	document.write(' id=',linkExp,'>&gt; Experiment ',zero,exp,'</a><br>');
	document.write(' id=',linkExp,'>&gt; ',zero,exp,' ',expInfo[exp][expInfoTitle],'</a><br>');
}

function experimentArchiveHeader(exp)
{   var zero = '';
	if ( exp < 10 )
		zero = '0';
	var linkExp = "'linkExp"+zero+exp+"'";
	var setTip  = '"setExperimentTip('+exp+', '+linkExp+')"';
	document.write('<p>&nbsp;</p><p class="head">');
	document.write('<a href="../experiments/exp',zero,exp,'SubStart.html"');
	document.write(' target="mainFrame"');
	document.write(' onMouseOver=',setTip);
	document.write(' );');
//	document.write('<a href="../experiments/exp',zero,exp,'SubStart.html" target="mainFrame">');
	document.write(' id=',linkExp,'>');
	document.write('Experiment ');
	if ( exp < 10 ) document.write('0');
	document.write(exp,':</a><br>');
	document.write(expInfo[exp][expInfoTitle]);
	document.write('<br></p><p>&nbsp;</p>');
}

function experimentTip(exp)
{
	var info    = expInfo[exp];
	var comment = info[expInfoTitle];
	var tip     = info[expInfoTip];
	var keyword = info[expInfoKeyword];
		
	if ( tip )
		return tip;
	else
	{   tip = info[expInfoLocation];
		if ( tip )
			comment = comment + "\n" + tip;

		if ( keyword )
			comment = comment + "\n" + keyword;
	}
	
	return comment;
}

function setExperimentTip(exp,id)
{
    var elem   = document.getElementById(id);
	var tip    = experimentTip( exp );
	if ( elem )
	{	elem.title = tip;
//		elem.setToolTipText( tip );
//elem.tips.value = tip;
     }
}

function drawExperiments(exp)
{
	var i;
	var selected = parent.parent.document.expSelected;
	var elem, text, comment, tip;
	
	for ( i = 1, elem = parent.leftFrame.document.getElementById("exp"+i);
		  elem;
		  i++,   elem = parent.leftFrame.document.getElementById("exp"+i) )
	{
		var info      = expInfo[i];
		var comment   = info[expInfoTitle];
		var extension = info[expInfoLocation];
	
		if ( i < 10 )
			text = "0"+i + ' ' + info[expInfoTitle];
		else
			text = i + ' ' + info[expInfoTitle];
			
		while ( text.length < 20 )
			text = text + ' ';
		
		comment = text;
		
		if ( extension )
			comment = comment + '<br>' + extension;

		elem.title = experimentTip( i );
		
		if ( i == exp )
		{	elem.style.color="black";
			elem.style.background ="#aaaaaa";
			elem.parentNode.parentNode.style.background ="#aaaaaa";
			if ( comment )
				elem.innerHTML = comment;
			else
				elem.innerHTML = text;
		}
		else if ( i == selected )
		{   elem.style.color="#00FFC5";
			elem.style.background ="black";
			elem.parentNode.parentNode.style.background ="black";
			elem.innerHTML = text;
		}
		else
		{   elem.style.color   ="white";
			elem.style.background ="black";
			elem.parentNode.parentNode.style.background ="black";
			elem.innerHTML = text;
		}
	}
}

function selectExperiment(exp)
{
//    selectMenu(2,parent);
	parent.parent.document.expSelected = exp;
	drawExperiments();
}

function loadExperiment(exp)
{
	var expPage;

	selectExperiment( exp );

    if ( navigator.appName == "Microsoft Internet Explorer" )
    {
		if ( exp < 10 )
			expPage = "../experiments/exp0"+exp+".html";
		else
			expPage = "../experiments/exp"+exp+".html";
	
		window.open( expPage, "rightFrame" );
	}
}


