//projectview.js
//if(document.all) //test conditions.
// path problems: use ~ to indicate absolute path relative to server root?


var menudone = 0;

function BuildMenu()
{
    var dmenu = prj.document.getElementById("dynamic");
    dmenu.appendChild(prj.document.createTextNode(prjname));
    dmenu.appendChild(prj.document.createElement('br'));
   	dmenu.appendChild(prj.document.createElement('br'));

    for(i=0; i < menuindexes; i++)
	{
	    mitem[i]=prj.document.createElement('a');
	    
	    mitem[i].appendChild(prj.document.createTextNode(menuitem[i]));
	    mitem[i].href="#";
	    mitem[i].target="_parent";
	    mitem[i].id=("index"+i);
	    mitem[i].onclick = function() {
		ind = this.id.substring(5);
		launchIndex(ind);
		return false; 
	      }
	    
	    dmenu.appendChild(mitem[i]);
	    dmenu.appendChild(prj.document.createElement('br'));
	}
    menudone=1;
}

function initialize()
{
    BuildMenu();
    if(menudone)
    setPage(0,0);
}

window.onload = initialize;

function launchIndex(mindex) { setPage(indexpage[mindex],1); }

function showPosition(pagenum)
{
 //italicise our current nav position based on pagenum

for(i = 0; i < menuindexes; i++)
 {
  if(pagenum >= indexpage[i] && pagenum < indexpage[i+1]) j = i; 
 }

 for(i = 0; i < menuindexes; i++)
 {
   if(i == j) mitem[i].className = 'current';
   else mitem[i].className = '';
 }
 pnum = pagenum + 1;
 pageid = pnum.toFixed(0) + " of " + pages.toFixed(0);
 prj.document.getElementById("Location").innerHTML = pageid;
}

function pathCheck(pathstr)
{
    cpath = document.URL;
    if(pathstr.match(prjpath))
	return pathstr;
    else
	{
	    return (prjpath+"/"+pathstr);
	}
}

function setPage(page,spsrc)
{
  pagenum = page;
  notes.location.href = urls[pagenum]; //works in FFX 
  prj.document.images["big"].src = images[pagenum];
}

function backfix(page)
{
    if(menudone)
	{
	    pagenum = page;
	    prj.document.images["big"].src = images[pagenum]; //ie problem.
	    showPosition(pagenum);
	}
}

function nextPage() 
{
    if (pagenum < (pages - 1))
       pagenum = pagenum + 1;
    //console.log("pagenum: %d",pagenum);
    setPage(pagenum,1);  //this should be executing.
}

function backPage() 
{
    if(pagenum > 0)
        pagenum = pagenum - 1;
    setPage(pagenum,1);
}


