/*
	CET Virtual Library™

	Centre for Educational Technology,
	Ramat-Aviv, Israel.
	http://lib.cet.ac.il/

	ITEM.JS
*/

function up_to_caption (el)
{
	var p = el.parentElement
	if ( p.tagName == 'H4' || p.tagName == 'BODY' )
		return p;
	
	return up_to_caption(p)
}

function document_onclick() {
	
	show_chapter_list(0, 'hidden')
	
	if ( window.event.srcElement.name == "paragraph" )
	{
		on_chapter(window.event.srcElement)
	}
	
	
}


/**
* chapter list processing
*/
function on_chapter (el)
{
	var p = up_to_caption(el)

	createChapterList (p)
	
	var offset = p.offsetTop + el.offsetHeight + rowItemView.offsetTop
	
	show_chapter_list (offset, 'visible')
	
	
}

function show_chapter_list(offset, isshow)
{	
	if ( offset > 0 )
		chaptersList.style.posTop = offset + 250
	
	//if ( isshow == 'visible' )
	//	setTimeout("chaptersList.style.visibility = '" + isshow + "'", 150)
	//else
		chaptersList.style.visibility = isshow	
}

function on_chapter_out(el)
{
	el.style.textDecoration = ''
}

function on_chapter_over(el)
{
	el.style.textDecoration = 'underline'
}

function goto_chapter(el)
{
	
	var index = new Number(el.name)
	
	var el = document.all(index)	
		
	show_chapter_list (index, 'hidden')
	
	el.scrollIntoView(true)
}

function createChapterList (el)
{
	var hlist = document.getElementsByTagName ("H4")	
	var htmlstrr = ""
	
	for ( i = 0; i < hlist.length; i++ )
	{		
		if( hlist[i].sourceIndex == el.sourceIndex)
			htmlstrr += "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr class='cslChapterListItemH'><td width='16px'><img src='http://lib.cet.ac.il/images/combo/pop_arrow.gif' width='16' height='15'></td><td>" + hlist[i].innerText + "</td></tr></table>"
		else
			htmlstrr += "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr class='cslChapterListItem'><td width='16px'></td><td onmouseout='on_chapter_out(this)' onmouseover='on_chapter_over(this)' onclick='goto_chapter(this)' name='" + hlist[i].sourceIndex + "'>" + hlist[i].innerText + "</td></tr></table>"
	}
	
	chaptersList1.innerHTML = htmlstrr
}

function on_biblio(id, el)
{
	var div1 = document.all(id)
	var div2 = document.all(id + "back")
	
	var v = 'visible'
	if ( div1.style.visibility == 'visible' )
		v = 'hidden'
	
	div1.style.posTop = rowItemView.offsetTop + el.offsetHeight
	div2.style.posTop = rowItemView.offsetTop + el.offsetHeight
	div1.style.posLeft = el.offsetWidth
	div2.style.posLeft = el.offsetWidth
	
	div1.style.visibility = v
	div2.style.visibility = v
}

function on_biblio_click (el)
{
	var div1 = document.all(el.id)
	var div2 = document.all(el.id + "back")
	
	div1.style.visibility = 'hidden'
	div2.style.visibility = 'hidden'
}


