

// ------------------------------- raft / floater --------------
//
// given xxx.htm, reads it into hidden iframe,
//  and created mini-slide-show to loop through each
//  div under the 'main' div in the xxx.htm file

var raft = new Object(); 

function startFloat(src,id,mode)
{
	// id -- what div to pick up from the src htm
	if (typeof id == UNDEF) id = 'main';

	// mode -- should the child divs of the id div 
	//  be shown individually (divs) or all together (all)
	if (typeof mode == UNDEF) mode = 'divs';

	raft.contentId = id;	// store for later use
	raft.mode = mode;
	raft.base    = document.getElementById('floater');
	raft.main    = document.getElementById('fl_content');
	raft.prev    = document.getElementById('fl_prev');
	raft.next    = document.getElementById('fl_next');


	// now load xxx.htm into the iframe called TempFrame

	var f = document.getElementById('TempFrame');
	f.src = src;

	// TempFrame must have onLoad to call copyToFloat
}

function getIframeDocument(f)
{
	var idoc = f.contentWindow || f.contentDocument;
	if (idoc.document) idoc = idoc.document;
	return idoc;
}




function copyToFloat()
{
	var f = document.getElementById('TempFrame');
	if (typeof f.src == UNDEF || f.src == '') return;

if(d)console.log('copyToFloat',raft);
	var idoc = getIframeDocument(f);

	var main = idoc.getElementById(raft.contentId);
	if (!main){ 
		return;
	}

	if (raft.mode == 'all'){
		raft.main.innerHTML = main.innerHTML;
		raft.base.style.display = 'block';
		return;
	}

	// want to step through sequence of divs
	var arr = new Array();
	var kid = main.firstChild;
if(d)console.log('kid', kid);
	while (kid){
		if (kid.tagName == 'DIV') arr.push(kid);
		kid = kid.nextSibling;
if(d)console.log('kid', kid);
	}
	raft.pageArr = arr;
	raft.pageNum = 0;
	showRaftPage(0);
}


function showRaftPage(incr)
{
if(d)console.log('showRaft incr=',incr,raft);

	raft.pageNum += incr;
	var i = raft.pageNum;

	// copy contents of the curr 'page' into raft.main
	var arr = raft.pageArr;
	raft.main.innerHTML = arr[i].innerHTML;

	// adjust visibility of prev/next navigation
	if (i>0) raft.prev.style.visibility = 'visible';
	else     raft.prev.style.visibility = 'hidden';

	if (i+1<arr.length) raft.next.style.visibility = 'visible';
	else                raft.next.style.visibility = 'hidden';

	raft.base.style.display = 'block';

}

function hideRaft()
{
if(d)dbg('<li>hiding raft');
	document.getElementById('floater').style.display = 'none';
}

