// ChangeColor.js 
// Highlights Navigation
// Only works for 3 levels

// Example: obj = findObj("image1");
// On works for 3 levels
var page=getPage(); /* get id name for area needed to be changed */
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}
// * Dependencies * 
// this function requires the following snippet:
// JavaScript/readable_MM_functions/findObj

function setColor(my_array, colors)
{
  if(!colors){ // if no colors are given use assigned colors array
	var my_colors = ['#FCCC51','#003366'];
	var my_bg ='#FFFFFF';
}
else {my_colors=colors;}
var name = new String();
for(var i=0; i < my_array.length; i++){
  name=my_array[i];
  obj = findObj(name);

  //check if object has style property
  //assign property to object
   if (!obj){break;}
   else{
	   //if (obj.className) obj.className=selected;
	  if (obj.style)
	  {
	    obj.style.color=my_colors[i];
		obj.style.backgroundColor=my_bg;
	   // obj.style.fontWeight='bold';
	   
	  } 
	}
}

}
function getPage()
{
    sURL = new String;
    bits = new Array;
    var x = 0;
    var stop = 0;
    var myID =new Array("ocs");

    sURL = location.href;
    sURL = sURL.slice(8,sURL.length);
	// find the index of the first '/' in the url
	// truncate the url from after the '/' to the end of the url
    chunkStart = sURL.indexOf("/"); 
    sURL = sURL.slice(chunkStart+1,sURL.length);
    // 3 levels
	chunkStart = sURL.indexOf("/"); 
	sURL = sURL.slice(chunkStart+1,sURL.length);
     // 2 levels	
	chunkStart = sURL.indexOf("/");
	if (chunkStart == -1){
			// before quiting check if file extension (.extension)
			// instead of directory (/)
			chunkStart = sURL.indexOf(".");
		}
	// 1 level
    if (chunkStart != -1){
		bits[0] = sURL.slice(0,chunkStart)
		
		sURL = sURL.slice(chunkStart+1,sURL.length);
		chunkStart = sURL.indexOf("/");
		if (chunkStart == -1){
			// before quiting check if file extension (.extension)
			// instead of directory (/)
			chunkStart = sURL.indexOf(".");
		}
	
    	if (chunkStart != -1){
			bits[1] = sURL.slice(0,chunkStart)
		}
	 	return bits;
	} 
	else { 
		return myID
	}

 /*     if (chunkStart != -1){
	// get the index of the next "/"
	chunkStart = sURL.indexOf("/");
        bits = sURL.slice(0,chunkStart)
//academic
	 return bits;
	  }
*/
}
