//  Set the menu name to the menu in use
var menuname="index";
// Define the timerID with timeout preset
var timerID, timeout = 15000
// Defines other variables
var targetObject, targetID,theBigCookie; 

// Set when the cookie expires
var date = new Date();
date.setMinutes(date.getMinutes()+3); 
var expires = date.toGMTString();

if (navigator.appVersion < "4"){
alert("You will need a current browser (v4+) to view this menu system.\nPress 'Ok' to forward to text only version.")
window.location = "http://www.sph.unc.edu/text_index.cfm"
}

if (navigator.appName == "Netscape")
//  Determine Browser type
{  nav="nc4"; }
  else 
{ nav="ie4";  }

function startmenu(){
// Start the menu system where it last left off
if (nav == "nc4"){
show(eval("document."+readCookie(menuname)));
}
else {
show(eval(readCookie(menuname)));
}}

function readCookie(name)
{
//Declare variables.
var firstChar, lastChar;
// Get the entire cookie string.
var theBigCookie = document.cookie;
// Find the start of 'name'.
firstChar = theBigCookie.indexOf(name);
 // If you found it,
if(firstChar != -1){
// skip 'name' and '='.
firstChar = firstChar + name.length + 1;
// Find the end of the value string (i.e. the next ';').
lastChar = theBigCookie.indexOf(';', firstChar);
 if(lastChar == -1) lastChar = theBigCookie.length;
// Return thevalue.

//document.write("<font size='-3'>");
//document.write(document.cookie.indexOf('sph'));
//document.write(name);
//document.write(firstChar+"-"+lastChar);
//document.write(theBigCookie.substring(firstChar, lastChar));

return theBigCookie.substring(firstChar, lastChar);
} else{
 // If there was no cookie, return default.
return "layer0";
}
}

function clearCookie()
{
// Clears the cookie value - used to prevent
// unwanted menu apperances.
if (document.cookie.indexOf('optout') < 0){
document.cookie = menuname +"=layer0"};
 }

function show(layer)
{
// Clear timeout for the apperance of  default menu
window.clearTimeout(timerID)
// Show layer in navagator
if (nav == "nc4"){
//  Check to see if another layer is visible
if (document.menulayer == null){
// if not then make visible the layer
this.document.menulayer = layer;
document.menulayer.visibility = "visible";
//  Set the cookie for this menu
the_cookie = menuname + "=" + layer.name+";expires=" + expires;
//if (document.cookie.indexOf('optout') < 0){document.cookie = the_cookie};
// Set timeout for the default layer to appear
timerID = setTimeout("show(document.layer0)", timeout )
//  Leave the function
                                     }
// If the layer was occupied, unshow layer first
else {
unshow();
// return and show the original layer
show(layer); }
}
else {
//  If not netscape, then do the next part for IE
//  Check to see if another layer is visible
if (targetObject == null){
// if not then make visible the layer
targetID=layer.id;
targetObject=document.all(targetID);
targetObject.style.visibility="visible";
//  Set the cookie for this menu
the_cookie = menuname + "=" + layer.id;
//if (document.cookie.indexOf('optout') < 0){document.cookie = the_cookie};
// Set timeout for the default layer to appear
timerID = setTimeout("show(layer0)", timeout )
												}
else {
// return with layer removed to show the original layer
show(eval(unshow(targetID,layer)));
//  Leave the function
} }
}

function unshow(targetLayer,layername) {
// Hide the previously exposed layer
if (nav == "nc4") {
// Unshow for Navagator
document.menulayer.visibility = "hidden";
document.menulayer = null;
								}
else {
// Unshow for IE
targetObject=document.all(targetLayer);
targetObject.style.visibility="hidden";
targetObject = null; 
//  Leave the function
return layername.id
}//  Leave the function
}





// CREDITS:
// Simple UpNews Scroller by Urs Dudli and Peter Gehrig 
// Copyright (c) 2000 Peter Gehrig and Urs Dudli. All rights reserved.
// Permission given to use the script provided that this notice remains as is.
// Additional scripts can be found at http://www.24fun.ch.
// info@24fun.ch
// 3/15/2000

// IMPORTANT: 
// If you add this script to a script-library or script-archive 
// you have to add a hyperlink to http://www.24fun.ch on the webpage 
// where this script will be running.

// INSTALLATION:
// 1.	Delete the DIV-container with the id 'deletethisdiv'. 
//		This is the only part of this file that is not required for the script. 
//		Save the file.
// 2.	Configure the messages. Let's take a look at the first message to understand 
//		its principle: 
//		- '	Madonna Storms UK Charts' is the title. Then follows a '|'. 
//		-	Then follows the copytext 'Girl band All Saints were knocked off 
//			the top spot in the British charts on Sunday by the queen of girl 
//			power herself.' 
//		-	Then again follows a '|'. 
//		-	Then follows the link for the message: http://www.24fun.ch. 
//		As you see the '|' acts as delimiter between title, copytext and link! 
// 3.	Configure the variables below:


// The height of the scrollerbox (pixels)
var scrollerheight=250

// The width of the scrollerbox (pixels)
var scrollerwidth=250

// The distance to the left border of the window (pixels)
var scrollertop=140

// The distance to the top border of the window (pixels)
var scrollerleft=420

// The padding between the scrollerbox and the text (pixels)
var scrollerpadding=1

// The width of the scrollerbox-border (pixels)
var backgroundborder=1

// The background-colour of the scrollerbox
var scrollerbgcolor="FFFFFF"

// Font attributes of the title
var font_titleface="Verdana"
var font_titlecolor="FF0000"
var font_titlesize=1

// Font attributes of the copytext
var font_copyface="Verdana"
var font_copycolor="660000"
var font_copysize=1

// standstill between the messages (milliseconds)
var standstillfix=3000

// Do not edit below this line
var cliptop=0
var clipbottom=scrollerheight-2*scrollerpadding
var clipleft=0
var clipright=scrollerwidth

var i_message=0
var mes_joined
var mes_split
var contenttext
var contentbg

var totalheight=scrollerheight*(message.length)
var i_height=0
var step=1
var pause=20

var standstillflex=0

function initiate(){
	contenttext="<table cellpadding='0' cellspacing='0' border='0' width='"+(scrollerwidth-2*scrollerpadding)+"'>"
	contenttext+="<tr valign='top'><td height='"+scrollerheight +"'><br></td></tr>"
	for (i=0;i<=message.length-1;i++) {
		mes_joined=message[i]
		mes_split=mes_joined.split("|")
		contenttext+="<tr valign='top'><td height='"+scrollerheight+"'><a href='"+mes_split[2]+"'><font face='"+font_titleface+"' color='"+font_titlecolor+"' size='"+font_titlesize+"'>"+mes_split[0]+"</font></a><br><font face='"+font_copyface+"' color='"+font_copycolor+"' size='"+font_copysize+"'>"+mes_split[1]+"</font></td>"
	}
	contenttext+="</table>"
	
	contentbg="<table cellpadding=0 cellspacing=0 border="+backgroundborder+" width='"+scrollerwidth+"'><tr><td height='"+scrollerheight+"' bgcolor="+scrollerbgcolor+">&nbsp;</td></tr></table>"
	
	if (document.all) {
		layer0.innerHTML=contenttext
		document.all.layer0.style.posTop=scrollertop
		document.all.layer0.style.posLeft=scrollerleft
		document.all.layer0.style.clip="rect("+cliptop+" "+clipright+" "+clipbottom+" "+clipleft+")"
	}
	if (document.layers) {
		document.layer0.document.write(contenttext)
		document.layer0.document.close()
		document.layer0.top=scrollertop
		document.layer0.left=scrollerleft
		document.layer0.clip.left=clipleft
        document.layer0.clip.right=clipright
        document.layer0.clip.top=cliptop
        document.layer0.clip.bottom=clipbottom
	}
	scroll()
}

function scroll(){
	standstillflex=standstillfix
	if (document.all){
		if (i_height<scrollerheight) {
			i_height+=step
			cliptop+=step
			clipbottom+=step
			document.all.layer0.style.clip="rect("+cliptop+" "+clipright+" "+clipbottom+" "+clipleft+")"
			document.all.layer0.style.posTop-=step
			var timer=setTimeout("scroll()",pause)
		}

		else {
			if (document.all.layer0.style.posTop<=-(totalheight)) {
				document.all.layer0.style.posTop=scrollertop
				cliptop=0
				clipbottom=scrollerheight-2*scrollerpadding
				document.all.layer0.style.clip="rect("+cliptop+" "+clipright+" "+clipbottom+" "+clipleft+")"
				standstillflex=0
			}
			i_height=0
			clearTimeout(timer)
			var timer=setTimeout("scroll()",standstillflex)
		}
	}
	
		if (document.layers){
			if (i_height<scrollerheight) {
				i_height+=step
				cliptop+=step
				clipbottom+=step
				document.layer0.clip.left=clipleft
        		document.layer0.clip.right=clipright
        		document.layer0.clip.top=cliptop
        		document.layer0.clip.bottom=clipbottom
				document.layer0.top-=step
				var timer=setTimeout("scroll()",pause)
			}

		else {
			if (document.layer0.top<=-(totalheight)) {
				document.layer0.top=scrollertop
				cliptop=0
				clipbottom=scrollerheight-2*scrollerpadding
				document.layer0.clip.left=clipleft
        		document.layer0.clip.right=clipright
        		document.layer0.clip.top=cliptop
        		document.layer0.clip.bottom=clipbottom
				standstillflex=0
			}
			i_height=0
			clearTimeout(timer)
			var timer=setTimeout("scroll()",standstillflex)
		}
	}
}
