// JavaScript Document
//*************************************SWAP IMAGE**********************************************//
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//***************************GENERAL FUNCTIONS ********************************
//returns the base of the page
function getBase(){
	var base = "http://ghetto.galim.org.il/rus/";
	return	base;
}
//returns the current section's name according to the URL
function getSection(){
	var section = (document.URL.slice(getBase().length).split("/"))[0];
	return section;
}
function getBrowser(){
	var browser;
	if(navigator.appName.search("Netscape")!=-1)
		browser = "Firefox";
	if (navigator.userAgent.search("MSIE 7.0")!= -1)
		browser = "IE7";
	if (navigator.userAgent.search("MSIE 6.0") != -1)
		browser = "IE6";
	return browser;
}
//returns the current activity's name according to the URL
function getActivity(){
	if(document.URL.search("photo") != -1)
		return "photo";
	if(document.URL.search("testimony") != -1)
		return "testimony";
	if(document.URL.search("writing") != -1)
		return "writing";
	if(document.URL.search("draw") != -1)
		return "draw";
	if(document.URL.search("object") != -1)
		return "object";
	if(document.URL.search("poem") != -1)
		return "poem";
}
//set the document's title according the section and returns the title
function setWindowTitle(){
	current = getSection();
	
	var titles = new Array("Отличительный знак","Заточение и изоляция","Скученность в гетто","Голод в гетто","Дети-контрабандисты","Детский труд","Повзрослевшие дети","Школы в гетто","Детские газеты","На крыльях фантазии","Детские игры","Театр в гетто","Бар\бат-мицва в гетто","Ханука в гетто","Семейные лагеря","Партизаны","О сайте","Словарь понятий");
	var sections = new Array("mark","isolation","crowded","hunger","smugglers","work","older","school","newspapers","wings","games","theater","mitzvah","hanukkah","families","partizans","about","concepts");
	
	for(i=0;i<sections.length;i++){
		if(sections[i] == current){	
			document.title = titles[i];
			return titles[i];
		}
	}
}
//set the title of the section in the header
function setSectionTitle(){
	document.getElementById("sectionLink").href = getBase() + getSection() + "/";
	document.getElementById("sectionTitle").src = "images/hl_"+ getSection() + ".gif";
	alt = setWindowTitle();	
	document.getElementById("sectionTitle").alt = alt;
	document.getElementById("sectionTitle").title = alt;
}
//place the relevant butttons in the sectionMenu box
function setActivityBtns(){
	//hold the possible buttons that can appear
	var activities = new Array("photo","testimony","writing","draw","object","poem" );
	//hold the alternative texts of each button
	var alt = new Array("Фотографии","Свидетельства","На бумаге","Живопись","Предмет","Поэзия" );
	//hold the buttons that should appear in the current section
	var btns=new Array();
	var sec = getSection();
	switch(sec){
		case "work":
			btns[0]="testimony";
			btns[1]="photo";
			btns[2]="writing";
			btns[3]="draw";
			break    
		case "theater":
			btns[0]="photo";
			btns[1]="draw";
			btns[2]="writing";
			break
		case "hunger":
			btns[0]="testimony";
			btns[1]="photo";
			btns[2]="writing";
			btns[3]="object";
			break	
		case "isolation":
			btns[0]="photo";
			btns[1]="testimony";
			btns[2]="writing";
			btns[3]="draw";
			btns[4]="object";
			break
		case "wings":
			btns[0]="draw";
			btns[1]="writing";
			btns[2]="object";
			btns[3]="poem";
			break
		case "crowded":
			btns[0]="photo";
			btns[1]="testimony";
			btns[2]="writing";
			btns[3]="draw";
			break
		case "smugglers":
			btns[0]="photo";
			btns[1]="draw";
			btns[2]="poem";
			btns[3]="writing";
			btns[4]="testimony";
			break
		case "games":
			btns[0]="photo";
			btns[1]="writing";
			btns[2]="object";
			btns[3]="draw";
			break
		case "mark":
			btns[0]="testimony";
			btns[1]="writing";
			btns[2]="photo";
			btns[3]="object";
			btns[4]="draw";
			break
		case "older":
			btns[0]="writing";
			btns[1]="photo";
			btns[2]="poem";
			btns[3]="testimony";
			btns[4]="draw";
			break
		case "school":
			btns[0]="testimony";
			btns[1]="photo";
			btns[2]="writing";
			btns[3]="draw";
			btns[4]="object";
			break
		case "newspapers":
			btns[0]="draw";
			btns[1]="writing";
			btns[2]="poem";
			break	
		case "mitzvah":
			btns[0]="writing";
			btns[1]="object";
			break
		case "hanukkah":
			btns[0]="photo";
			btns[1]="writing";
			btns[2]="object";
			break
		case "partizans":
			btns[0]="photo";
			btns[1]="writing";
			btns[2]="testimony";
			btns[3]="poem";
			btns[4]="object";
			break
		case "families":
			btns[0]="photo";
			btns[1]="writing";
			btns[2]="testimony";
			break
			
		default:
			//alert("Can not place activity buttons! The section " + sec + " is not defined.");
	}

	var key = new Array();
	for(i=0;i<btns.length;i++){
		for(j=0;j<activities.length;j++){
			if (btns[i] == activities [j])
				key[i] = j;
		}
	}
	
	var str = "";
	var currAct = getActivity();
	
	for(i=0;i<btns.length;i++){
		if(btns[i] == currAct)
			str += "<div><a href=\"" + sec + "/" + btns[i] + ".html\" ><img id=" +"\"activityBtn" + i + "\" src=" + "\"images/" +  btns[i] + "_on.gif\" alt=" + "\"" + alt[key[i]] + "\" /></a></div>";  
		else
			str += "<div><a href=\"" + sec + "/" + btns[i] + ".html\" " + "onmouseout=\"MM_swapImgRestore()\" " + "onmouseover=\"MM_swapImage('activityBtn" + i + "',' ','images/" + btns[i] + "_on.gif',1)\"><img id=" +"\"activityBtn" + i + "\" src=" + "\"images/" +  btns[i] + "_off.gif\" alt=" + "\"" + alt[key[i]] + "\" /></a></div>";  
	}
	document.getElementById("sectionMenu").innerHTML = str;
	
}
//onclick event fot the Site Map button
function showSiteMap(){
	document.getElementById("siteMap").style.display = "block";
}
function closeFlashWindow()
{
  document.getElementById("siteMap").style.display = "none"; 
}
// pops up a modeless dialog
function popupTerm(letter)
{ 
	var link = "http://ghetto.galim.org.il/rus/concepts/.index.html?" + letter;
	window.open ( link ,"an2", "toolbar=no,member=no,location=no,directories=no,scrollbars=yes,status=no,copyhistory=no,left=200,top=100,resizable=no,height=430,width=400");
	//showModelessDialog( link, window ,"dialogHeight:430px;dialogWidth:400px;help:no;status:no;resizable: no;dialogLeft:350;dialogTop:200; "); 
}


//show popup window
function popup (link,winHeight,winWidth)
{
	window.open ( getBase()+link ,"an2", "toolbar=no,member=no,location=no,directories=no,scrollbars=yes,status=no,copyhistory=no,left=0,top=0,resizable=no,height="+winHeight+",width="+winWidth);
}
//*******************************************************************************
//The showPic function flip the image and the title in the presentationBox
//Variables:
//newSrc: path from the base to the picture that should appear
//newAlt: the title of the  picture that should appear
//on: an integer starting from 0 that represent the number of the button that should be "On". 
//*******************************************************************************
function showPic(newSrc, newAlt, on){
	document.getElementById("presentationBox").getElementsByTagName("img")[0].src = newSrc;
	document.getElementById("presentationBox").getElementsByTagName("img")[0].alt = newAlt;
	document.getElementById("presentationNavig").getElementsByTagName("h2")[0].innerHTML = newAlt;
	
	var btns = document.getElementById("presentationNavig").getElementsByTagName("div");
	for(i=0;i<btns.length;i++){
		if(i == on){
			btns[i].className = "pageNumOn";
			btns[i].onmouseover = "";
			btns[i].onmouseout = "";				
		}
		else{
			btns[i].className = "pageNumOff";
			btns[i].onmouseover = "pageNumOn(this)";
			btns[i].onmouseout = "pageNumOff(this)";
		
		}	
	}
}
//*******************************************************************************
//flip the content of presentationBox. The contents should appear in the HTML inside the presentationBox in sequential divs with id contentX
//Variables:
//title: the title of the content that should appear
//on: an integer starting from 0 that represent the ordinal number of the content that should appear. 
//*******************************************************************************
function flipPresentation(title,on){

		var btns = document.getElementById("presentationNavig").getElementsByTagName("div");
		for(i=0;i<btns.length;i++){
			if(i == on){
				btns[i].className = "pageNumOn";
				btns[i].onmouseover = "";
				btns[i].onmouseout = "";
				document.getElementById("content"+i).className = "display";
				document.getElementById("presentationNavig").getElementsByTagName("h2")[0].innerHTML = title;				
			}
			else{
				btns[i].className = "pageNumOff";
				btns[i].onmouseover = "pageNumOn(this)";
				btns[i].onmouseout = "pageNumOff(this)";
				document.getElementById("content"+i).className = "undisplay";	
			}	
		}
	}
//***************************DESIGN FUNCTIONS ********************************
function pageNumOn(obj){
	obj.className = "pageNumOn";
}
function pageNumOff(obj){
	obj.className = "pageNumOff";
}
//fix the link colors in IE6
function colorPageNumLinks(){
	if(document.getElementById("presentationNavig")==null)
		return;
	var x = document.getElementById("presentationNavig").getElementsByTagName("div");
	for(i=0;i<x.length;i++){
		x[i].getElementsByTagName("a")[0].style.color =  "#ffffff";
	}	
}
function fixIEselectBug() {
	var br = getBrowser();
	if( br == "IE6")
		document.body.style.height = document.documentElement.scrollHeight + 'px';
}
//replace the content of textBox
function textBox(num){
	if( num == 1){
		document.getElementById("textBox2").className = "undisplay";
		document.getElementById("textBox").className = "display";
	}
	if( num == 2){
		document.getElementById("textBox").className = "undisplay";
		document.getElementById("textBox2").className = "display";
	}	
}
