// 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_full="http://www.sykacek.net/";
base_site_part="http://sykacek.net/";
var allids=new Array("home", "research", "pubs", "downl", "misc", "cv");
var alltexts=new Array("Home", "Research", "Publications", "Downloads", "Teaching", "CV");
var allpages=new Array("index.html", "research.html", "pubs.html", "downloads.html", "teaching.html",
"cv.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", "res_three");
// 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", "mcabf");
// and corresponding layer indices
var res_connector=new Array(0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 3);

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

// teaching.html
// layers
var tch_layers=new Array("tch_zero");
// entry points (i.e. defied "jump" points)
var tch_linkentries=new Array("", "compbio", "fspmalec", "mlbin", "bayeslife");
// and corresponding layer indices
var tch_connector=new Array(0, 0, 0, 0, 0);

// research seminar (index.html at the bi site)
// layers
var sem_layers=new Array("sem_zero", "sem_one");
// entry points (i.e. defied "jump" points)
var sem_linkentries=new Array("", "current", "past", "future", "sem_001", "topics", "location", "announce");
// and corresponding layer indices
var sem_connector=new Array(0, 0, 0, 0, 0, 1, 1, 1);

// 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+"%";
	var layerf=document.getElementById("navig_foot");
	if(layerf){
	  newprc=parseFloat(layerf.style.left)-0.5;
	  layerf.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+"%";
	var layerf=document.getElementById("navig_foot");
	if (layerf){
	  newprc=parseFloat(layerf.style.left)+0.5;
	  layerf.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.
        // alert(link);
	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_full || link==base_site_part)){ // test for http://www.sykacek.net/
		found=0;
	}
	// We first test, whether we have to toggle the menu colors at all. This is the case if the background
	// in the ccell found is not lit up yet.
	//Ccell=parent.menu_disp.document.getElementById(allids[found]);
	//if (Ccell.style.backgroundColor != "#d0d0ff" && Ccell.style.backgroundColor != "rgb(208, 208, 255)"){
	    
	    // 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 resetmenu(menuwnd){
	// reset the menu style (i.e. background colour) since 
	// we are going to display an external link in the main frame.
	// turn all entries off first
	for(var i=0; i<allpages.length; i++){
		var Ccell=menuwnd.document.getElementById(allids[i]);
		Ccell.style.backgroundColor="#8080FF";
	}
	currpos=-1;
}

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" && Ccell.style.backgroundColor != "rgb(208, 208, 255)"){
		// 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;	      
}

