// a collection of functions written by Yun-Hui Fan
// created on September 13, 2000
// last modified on October 19, 2000


function changeTitleFrameURL (filename1)
{
 var thePath;
 if (window.name == 'content')
 {
  thePath = pathOnly(parent.location.href);
  parent.browser.location.href = thePath + filename1;
 }
}

function pathOnly (inString)
{
 var lastSlash;
 var outString;
 lastSlash = inString.lastIndexOf ('/',inString.length-1);
 outString = inString.substring (0,lastSlash+1);
 return (outString);
}

var outsideWindow = null;
function openInNewWindow (theURL)
{
 if (outsideWindow && !outsideWindow.closed)
 {
  outsideWindow.focus();
  outsideWindow.location.href = theURL;
 }
 else
 {
  outsideWindow = window.open(theURL,"outsideWindow");
 }
}

//

function doStuff()
{
 if (window.name != "content")
 {
  setVariables();
  checkLocation();
 }
 showDirectories();
}

if (window.name != "content")
{
 tableWidth = 10;
 logoContent = '<a href="http://csip.ece.gatech.edu/csipindex.html" onMouseOver="window.status=\'Thanks for visiting the Center for Signal and Image Processing @ Georgia Institute of Technology!\';return true" onmouseout="window.status=\'\';return true"><center><img src="images/logo_animated.gif" width="182" height="111" border="0"></center></a>';
}
else
{
 tableWidth = 0;
}

function setVariables() 
{
 imgwidth=182;  // logo width, in pixels
 imgheight=111;  // logo height, in pixels
 if (navigator.appName == "Netscape") 
 {
  horz=".left";
  vert=".top";
  docStyle="document.";
  styleDoc="";
  innerW="window.innerWidth";
  innerH="window.innerHeight";
  offsetX="window.pageXOffset";
  offsetY="window.pageYOffset";
 }
 else 
 {
  horz=".pixelLeft";
  vert=".pixelTop";
  docStyle="";
  styleDoc=".style";
  innerW="document.body.clientWidth";
  innerH="document.body.clientHeight";
  offsetX="document.body.scrollLeft";
  offsetY="document.body.scrollTop";
 }
}

function checkLocation() 
{
 objectXY="branding";
 var availableX=eval(innerW);
 var availableY=eval(innerH);
 var currentX=eval(offsetX);
 var currentY=eval(offsetY);
 x=availableX-(imgwidth+30)+currentX;
 y=availableY-(imgheight+20)+currentY;
 evalMove();
 setTimeout("checkLocation()",10);
}

function evalMove() 
{
 eval(docStyle + objectXY + styleDoc + horz + "=" + x);
 eval(docStyle + objectXY + styleDoc + vert + "=" + y);
}


function showDirectories()
{
 var docPath = document.location.pathname;
 var theTree = new Array();
 var theDirectory = "";
 var numberOfTreeLevels = 0;
 var i;

 if (window.name == 'content')
 {
  for (i = 1; i < docPath.length;i++)
  {
   if (docPath.charAt(i) != '/')
   {
    theDirectory += docPath.charAt(i);
   }
   else
   {
    theTree[numberOfTreeLevels] = theDirectory;
    numberOfTreeLevels++;
    theDirectory = "";
   }
  }

  newTitleTemplate(theTree,numberOfTreeLevels);
 }
}

function newTitleTemplate(theLinks,numberOfLinks)
{
 var theHREF = 'http://csip.ece.gatech.edu/'; // the base
 var theDirectory = "";
 var myHeader = '<html><head><title>Directories</title></head>';
 myHeader = myHeader + '<body>';
 var myText = '<small>';
 var myEndText = '</small>';
 var myEndHeader = '</body></html>';

 if (numberOfLinks == 1)
 {
// First Level
  theHREF += theLinks[0] + '/';
  theDirectory = removeUnderscore(theLinks[0]);
  myText += '<a href=\"' + theHREF + 'index.shtml' + '\" target= \"content\"><b>' + theDirectory + '</b></a>';
 }
 else
 {
// First Level
  theHREF += theLinks[0] + '/';
  theDirectory = removeUnderscore(theLinks[0]);
  myText += '<a href=\"' + theHREF + 'index.shtml' + '\" target= \"content\">' + theDirectory + '</a>:';

// the rest
  for (i = 1; i < numberOfLinks - 1; i++)
  {
   theHREF += theLinks[i] + '/';
   theDirectory = removeUnderscore(theLinks[i]);
   myText += '<a href=\"' + theHREF + 'index.shtml' + '\" target=\"content\">' + theDirectory + '</a>:';
  }
  
  i = numberOfLinks - 1;
  theHREF += theLinks[i] + '/';
  theDirectory = removeUnderscore(theLinks[i]);
  myText += '<a href=\"' + theHREF + 'index.shtml' + '\" target= \"content\"><b>' + theDirectory + '</b></a>';
 }
 parent.browser.document.open("text/html", "replace");
 parent.browser.document.clear();
 parent.browser.document.write(myHeader + myText + myEndText + myEndHeader);
 parent.browser.document.close();
}

function removeUnderscore(inString)
{
 var outString = "";
 var i;

 for (i = 0; i < inString.length; i++)
 {
  if (inString.charAt(i) == '_')
  {
   outString += ' ';
  }
  else
  {
   outString += inString.charAt(i);
  }
 }

 return (outString);
}
