﻿var wins=new Array();

// get background image

window.onload=function switchback(){	// switches background image to be used

	var backgrounds;
	var captions;
	
	if(document.getElementById("main_body").offsetHeight <= 845){

		backgrounds=new Array("ultor", "castor", "vespasian", "doric", "pantheon", "ulpian");
		captions=new Array("Corinthian capital from the temple of Mars Ultor, Rome, dedicated 2 BC",
										"Detail of Corinthian capital from the temple of Castor and Pollux, Rome, Tiberian rebuilding of 6 AD",
										"Pediment of the temple of Vespasian, Rome, dedicated 81 AD",
										"Detail of Doric column from the temple of Mars Ultor, Rome, dedicated 2 BC",
										"Pediment of the Pantheon, Hadrianic reconstruction, c. 125 AD",
										"Fragment from the Basilica Ulpia, Rome, completed c. 100 AD" );
										
		}	
		else{
		
				backgrounds=new Array("ultor", "castor_cu", "vespasian_cu", "pantheon_cu", "ulpian_cu");
				captions=new Array("Corinthian capital from the temple of Mars Ultor, Rome, dedicated 2 BC",
										"Detail of Corinthian capital from the temple of Castor and Pollux, Rome, Tiberian rebuilding of 6 AD",
										"Pediment of the temple of Vespasian, Rome, dedicated 81 AD",
										"Pediment of the Pantheon, Hadrianic reconstruction, c. 125 AD",
										"Fragment from the Basilica Ulpia, Rome, completed c. 100 AD" );
		
		
		}
	var randomnumber=Math.floor(Math.random()*backgrounds.length);
	document.getElementById("main_body").className=backgrounds[randomnumber];
	document.getElementById("main_body").title=captions[randomnumber];
	

	activateother();	
	check_footnotes();
	
}

function activateother(){

	var rot = document.getElementById('role_other_text');
	
	if(rot){
	
		rot.onfocus = function(){document.getElementById('role_other').checked = "checked"};
	
	}
	
	var oot = document.getElementById('org_other_text');
	
	if(oot){
	
		oot.onfocus = function(){document.getElementById('org_other').checked = "checked"};
	
	}
	

}

function open_window (url, title, wnum) { 

	title = title.replace(/\s/g, "");

	var height; var width; var top; var left; var spacer; menu="no"; height=400; width=400;
	spacer=25;

	switch(wnum){

		// by default, windows appear as quarters of the browser 
		// after the first four windows, they cover the entire width fo the browser, 
		// and appear beneath these first four

		case 1: top=spacer; left=spacer; break;

		case 2: top=spacer; left=(spacer*2)+width; break;

		case 3: top=(spacer*3)+height; left=spacer; break;

		case 4: top=(spacer*3)+height; left=(spacer*2)+width; break;
		
		case 22:
			width=window.document.width;
			height=window.document.height;
			top=100;
			left=100;
			menu="yes";
		break;

		default: width*=2; wab=wnum-3; // = 'windows above'
		top=(spacer*wab)+(height*wab); left=spacer;

}

	var parstring="'toolbar="+menu+",width="+width+",height="+height+",screenX="+top+",screenY="+left+",top="+top+",left="+left+",resizable=yes,location=no,directories=no, status=no, menubar=no,scrollbars=yes,copyhistory=no'";
	var newWindow=window.open(url, title, parstring);
	wins.push(newWindow);

	for(var i=0; i<wins.length; i++){
	
		if(wins[i].window){
		
			wins[i].window.focus();
			
		}
		
	}
	
		this.window.blur();
} 

function show_note(el){

	el = document.getElementById(el);
	el.style.visibility = 'visible';

}

function hide_note(el){

	el = document.getElementById(el);
	el.style.visibility = 'hidden';

}

function check_footnotes(){

	var supers = document.getElementsByTagName('SUP');
	
	for(var i = 0; i < supers.length; i++){
	
		var spr = supers[i];
	
		if(spr.parentNode.className == "footnote"){
			
			spr.onclick = show_grammar_note;
	
		}
	
	}
	
}	
	
function show_grammar_note(){

	var ftnt = this.parentNode;
	
	var fw = ftnt.parentNode.offsetWidth;
	
	var divs = ftnt.getElementsByTagName('DIV');
	
	var cntnt = divs[0];
	
	cntnt.style.width = fw;
	cntnt.style.display = 'block';
	
	this.onclick = hide_grammar_note;
	
}
	
function hide_grammar_note(){
	
	var ftnt = this.parentNode;
	
	var divs = ftnt.getElementsByTagName('DIV');
	
	var cntnt = divs[0];

	cntnt.style.display = 'none';	
		
	this.onclick = show_grammar_note;
		
}

