// Just a comment : to use any of the library functions
// one needs two script statements in the html file.
// The first is used with src tag to load the library.
// This must have an empty body !!!!
// The second script statement can use the functions to get 
// stuff done.

// frame control
base_site="http://www.sykacek.net/";
var allids=new Array("home", "research", "pubs", "cv", "misc");
var alltexts=new Array("Home", "Research", "Publications", "CV", "Miscellany");
var allpages=new Array("index.html", "research.html", "pubs.html", 
"cv.html", "misc.html");
var currpos=0;		// colour handling of tabs in top frame

// cv.html
var cv_layers=new Array("cv_zero");
var cv_linkentries=new Array("education", "work");
var cv_connector=new Array(0,0);

// pubs.html
var pubs_layers=new Array("pubs_zero");
var pubs_linkentries=new Array("journals", "conferences", "other");
var pubs_connector=new Array(0,0,0);

// research.html
// layers
var res_layers=new Array("res_zero", "res_one", "res_two");
// entry points (i.e. defied "jump" points)
var res_linkentries=new Array("", "prob_top", "bayes_sensf", "bayes_references", 
"bci_top", "bci_oxford", "probabilistic_bci", "adaptive_BCI", "BCI_pubs", "sleep");
// and corresponding layer indices
var res_connector=new Array(0, 0, 0, 0, 1, 1, 1, 1, 1, 2);

// software.html
// layers
var sw_layers=new Array("sw_zero");
// entry points (i.e. defied "jump" points)
var sw_linkentries=new Array("", "fspma");
// and corresponding layer indices
var sw_connector=new Array(0, 0);

// for navigator scrolling
var layerdec=10;
var steps=0.5;

// hidelayer and showlayer.
// they work in general assuming that the left layer (the one with the
// links) has id "navig" the other layers have arbitrary id and are 
// provided as argument in the onClick handler.
// slidestate controls the layer positioning (to avoid multiple shows).

var slidestate=0;
var do_theselayers = new Array();
var do_dec;

function hidelayer(mylayers, layerdec){
	do_theselayers=eval(mylayers);
	// alert(do_theselayers);
	do_dec=parseFloat(layerdec);
	if (slidestate==0){
		setTimeout("local_hide();", 20);	
		slidestate=1;
	}
}

function local_hide(){
	for (var i=0; i< do_theselayers.length; i++){
		var layer=document.getElementById(do_theselayers[i]);
		newprc=parseFloat(layer.style.width)+0.5;
		// layer.style.left=newprc+"%";
		layer.style.width=newprc+"%";
	}
	var layer=document.getElementById("navig");
	newprc=parseFloat(layer.style.left)-0.5;
	layer.style.left=newprc+"%";
	do_dec=do_dec-0.5;
	if (do_dec > 0){
		setTimeout("local_hide();", 20);
	}
}

function showlayer(mylayers, layerdec){
	// alert(mylayers);
	do_theselayers=eval(mylayers);
	do_dec=parseFloat(layerdec);
	if (slidestate==1){
		setTimeout("local_show();", 20);	
		slidestate=0;
	}
}

function local_show(){
	for (var i=0; i< do_theselayers.length; i++){
		var layer=document.getElementById(do_theselayers[i]);
		newprc=parseFloat(layer.style.width)-0.5;
		// layer.style.left=newprc+"%";
		layer.style.width=newprc+"%";
	}
	var layer=document.getElementById("navig");
	newprc=parseFloat(layer.style.left)+0.5;
	layer.style.left=newprc+"%";
	do_dec=do_dec-0.5;
	if (do_dec > 0){
		setTimeout("local_show();", 20);
	}
}

function showtopic(link, linkentries, connector, layers){
	var toactivate=layers[0]; // default layer !
	// alert(link);
	for(var i=0; i<linkentries.length; i++){
		if (link.indexOf(linkentries[i]) != -1){
			toactivate=layers[connector[i]];
	   	}
	}
	if (toactivate != ""){
	// ONLY if new layer found toggle visisbility (otherwise blank screen!)
		for(var i=0; i<layers.length; i++){
			var folder=document.getElementById(layers[i]);
			folder.style.visibility="hidden";
		}
		var folder=document.getElementById(toactivate);
		folder.style.visibility="visible";	
	}
}

function setmenu(link, menuwnd){
	// set the menu style (i.e. background colour) depending on the link
	// we are going to display in the main frame.
	var found=-1;
	for(var i=0; i<allpages.length && found==-1; i++){
   		if (link.indexOf(allpages[i]) != -1){
			found=i;
   		}
	}
	if (found==-1 && link==base_site){ // test for http://www.sykacek.net/
		found=0;
	}
	// turn all entries off first
	for(var i=0; i<allpages.length; i++){
		var Ccell=menuwnd.document.getElementById(allids[i]);
		Ccell.style.backgroundColor="#8080FF";
	}
	// now we either have found the tab id or we have another main page.
	if (found!=-1){
		var Ccell=parent.menu_disp.document.getElementById(allids[found]);
	//	allert(Ccell);
		Ccell.style.backgroundColor="#D0D0FF";
	}
	currpos=found;
}

function turnon(link){
	//parent.bottom_disp.document.write(currpos);
	var link_ref=link.href;
	var found=-1;
	for(var i=0; i<allpages.length && found==-1; i++){
  		if(link_ref.indexOf(allpages[i])!=-1){
			found=i;
  		}
	}
	var Ccell=parent.menu_disp.document.getElementById(allids[found]);
	//alert(Ccell.style.backgroundColor);
	if (Ccell.style.backgroundColor != "#d0d0ff"){
		// current active link is not the one we point to and we highlite
		link.style.color="#D0D0FF";
	}
}

function turnoff(link){
	link.style.color="#000090";
}

function inisite(newlink){
	if (parent.bottom_disp==null){ // we are linked without our frameset
		startup();	// resize the window
		// then build the frameset
 		document.write('<frameset frameborder="0" framespacing="0"'); 
  		document.write('border="0" rows="50,*,30" name="ps_frameset">');
        	document.write('<frame frameborder="0" framespacing="0"  name="menu_disp"'); 
		document.write('src="newmenu.html" marginheight="5" marginwidth="5" noresize scrolling="no">');
        	document.write('</frame>');
        	document.write('<frame frameborder="0" framespacing="0"');
        	document.write('name="bottom_disp" marginheight="5" marginwidth="5" noresize scrolling="auto"');
        	document.write('onLoad="setmenu(parent.bottom_disp.location.href, parent.menu_disp);">');
    		document.write('</frame>');
        	document.write('<frame frameborder="0" framespacing="0" src="contact.html" name="contact_disp"'); 
		document.write('marginheight="0" marginwidth="5" noresize scrolling="no">');
        	document.write('</frame>');
        	document.write('</frameset>');
		// and finally reset the location of the main frame.
		parent.bottom_disp.location=newlink;
	}
}

function startup(){
	// resizes the window and "unframes" the frame page.
	// initialize variables to defaults
	if (parent!=window) { // we are framed!
      		window=top;   // we set it to be the top window.
	}
	H_size=790;
	V_size=630;
	// finally resize browser window such that the frameset makes sense
	window.resizeTo(H_size, V_size);
	//alert(window.opener);
}

function redirect(url){	
// redirects to url by changing window.location.
      window.location=url;	      
}

