function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// LIST ALL SHOW/HIDE ELEMENT IDS HERE
menus_array = new Array ('aboutctl', 'gened', 'resources');
menus_status_array = new Array ();// remembers state of switches





function showHideSwitch (theid) {						//the switcher function
  if (document.getElementById) {
  	var ddid = 'dd'+theid;
  	var dtid = 'dt'+theid;
    var switch_id = document.getElementById(ddid);
    var imgid = ddid+'Button';
    var button_id = document.getElementById(imgid);
    if (menus_status_array[ddid] != 'show') {
    		for (var loop = 0; loop <menus_array.length; loop++) 
    			{
    			other = menus_array[loop];
    				if (other != theid) {
    					var ddother = 'dd'+other;
    					var dtother = 'dt'+other;
    					document.getElementById(dtother).className = 'notcurrent';
    					document.getElementById(ddother).className = 'hideSwitch';
    					menus_status_array[ddother] = 'hide';
    				}else{
    				}
    			}
      document.getElementById(dtid).className = 'current';
      setLiWidth(ddid);
      switch_id.className = 'showSwitch';
	  menus_status_array[ddid] = 'show';
	  document.cookie = ddid+'=show';
	  
    }else{
    }
  }
}


function setLiWidth(sectionheading) {
	var currentinnerd = document.getElementById(sectionheading);
	var innermenuitems = currentinnerd.getElementsByTagName('LI');
	var howmanyitems = innermenuitems.length;
	
//	if (howmanyitems > 6) {
//		howmanyitems = Math.floor(parseInt(howmanyitems*.6));
//		}else{
//		}
//	var liwidth = Math.floor(parseInt(((500-howmanyitems*16)/howmanyitems)));
	var liwidth = 75;	
	for (i=0; i < innermenuitems.length; i++) {
		innermenuitems[i].width = liwidth + 'px';
		var itemlinks = innermenuitems[i].getElementsByTagName('A');   // this block loops through each anchor tag of each link in the innermenu to set the newly calculated lengths
			for (j=0; j < itemlinks.length; j++) {
				var it = itemlinks[j];
				it.style.width = liwidth + 'px';
			}	
		}
	
	
}

function thisPage() {

var currenturl = location.href;
var lastfour = currenturl.substr(currenturl.length-4, currenturl.length);
if (lastfour != "html") {
	currenturl = currenturl + "index.html";

}


//	if (currenturl.substr(0,35) == 'http://blogs.qc.cuny.edu/blogs/ctl/') {
//					if (currenturl.substr(35,6) == 'events') {
//						currenturl = 'http://blogs.qc.cuny.edu/blogs/ctl/events';
//						}else{
//						currenturl = 'http://blogs.qc.cuny.edu/blogs/ctl';
//						}
//					}else{
//						if (currenturl.indexOf('geac') == -1) {
//		var subdirectoryposition = currenturl.indexOf('/ctl/');
//		var subdirectorypath = currenturl.substr(subdirectoryposition+5);
//		var subdirectorypathlength = subdirectorypath.indexOf('/');
//		var subsubdirectory = subdirectorypath.substr(subdirectorypathlength+1);
//		if (subsubdirectory.indexOf('/') != -1) {
//			currenturl = currenturl.substr(0,subdirectoryposition+5) + subdirectorypath.substr(0,subdirectorypathlength+1) + 'index.html';
//			}else{
//			}
//		}else{
//		}
//					}

var motherdiv = document.getElementById('motherdiv');
var motherdivlists = motherdiv.getElementsByTagName('UL');
var verytoparray = new Array(3);

var subdirectoryposition = currenturl.indexOf('/ctl/');
var currenturllastslash = currenturl.lastIndexOf('/');
var loopchecker = false;

while (currenturl.length > subdirectoryposition) {

for (i=0; i < 3; i++) {
	verytoparray[i] = motherdivlists[i];			// finds the "verytop" class members (the first three ULs in "motherdiv)
	}

for (i=0; i < verytoparray.length; i++) {
	var verytoplinks = verytoparray[i].getElementsByTagName('A');
	var verytopid = verytoplinks[0].id;
	var bareid = verytopid.substr(2,verytopid.length-2);
	var ddid = 'dd' + bareid;
	var verytopcorrolary = document.getElementById(ddid);
	var verytopcorrolarylinks = verytopcorrolary.getElementsByTagName('A');
			for (j=0; j < verytopcorrolarylinks.length; j++) {
				var verytopcorrolarylinkurl = verytopcorrolarylinks[j].href;
				if (verytopcorrolarylinkurl == currenturl) {
					var currentpagelink = verytopcorrolarylinks[j]
					var verytopbox = verytoplinks[0];
					var verytopboxid = bareid;
					loopchecker = true;
					} else {
					}	
			if (loopchecker == true) {
				break; 
				}
			}	// end loop through subcategory items
	if (loopchecker == true) {
		break;
		}
	}	//end loop through verytops
if (loopchecker == true) {
	break;
	} else {
currenturllastslash = currenturl.lastIndexOf('/');
currenturl = currenturl.substr(0,currenturllastslash);
	}
} //end while
	if (loopchecker == true) {
					currentpagelink.style.backgroundColor = '#00e';
					//currentpagelink.style.fontStyle = 'italic';
					//currentpagelink.style.fontWeight = 'bold';			//these lines set the style on the current subheading
					
					verytopbox.style.backgroundColor = "#00e";
					//verytopbox.style.fontStyle = 'italic';
					//verytopbox.style.fontWeight = 'bold';						//these set the style on the current main heading
					
					showHideSwitch(verytopboxid);
					} else {
					
					showHideSwitch('aboutctl');
					}
			

}