ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 500
ypSlideOutMenu.hideDelay = 500
ypSlideOutMenu.minCPUResolution = 10

// constructor
function ypSlideOutMenu(id, dir, left, top, width, height)
{
	this.ie  = document.all ? 1 : 0
	this.ns4 = document.layers ? 1 : 0
	this.dom = document.getElementById ? 1 : 0

	if (this.ie || this.ns4 || this.dom) {
		this.id			 = id
		this.dir		 = dir
		this.orientation = dir == "left" || dir == "right" ? "h" : "v"
		this.dirType	 = dir == "right" || dir == "down" ? "-" : "+"
		this.dim		 = this.orientation == "h" ? width : height
		this.hideTimer	 = false
		this.aniTimer	 = false
		this.open		 = false
		this.over		 = false
		this.startTime	 = 0

		// global reference to this object
		this.gRef = "ypSlideOutMenu_"+id
		eval(this.gRef+"=this")

		// add this menu object to an internal list of all menus
		ypSlideOutMenu.Registry[id] = this

		var d = document
		d.write('<style type="text/css">')
		d.write('#' + this.id + 'Container { visibility:hidden; ')
		d.write('left:' + left + 'px; ')
		d.write('top:' + top + 'px; ')
		d.write('overflow:hidden; }')
		d.write('#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; ')
		d.write('width:' + width + 'px; ')
		d.write('height:' + height + 'px; ')
		d.write('clip:rect(0 ' + width + ' ' + height + ' 0); ')
		d.write('}')
		d.write('</style>')

		this.load()
	}
}

ypSlideOutMenu.prototype.load = function() {
	var d = document
	var lyrId1 = this.id + "Container"
	var lyrId2 = this.id + "Content"
	var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
	if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
	var temp

	if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
	else {
		this.container	= obj1
		this.menu		= obj2
		this.style		= this.ns4 ? this.menu : this.menu.style
		this.homePos	= eval("0" + this.dirType + this.dim)
		this.outPos		= 0
		this.accelConst	= (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen 

		// set event handlers.
		if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')")
		this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')")

		//set initial state
		this.endSlide()
	}
}

ypSlideOutMenu.showMenu = function(id)
{
	window.status = id
	var reg = ypSlideOutMenu.Registry
	var obj = ypSlideOutMenu.Registry[id]
	
	if (obj.container) {
		obj.over = true

		// close other menus.
		for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu)

		// if this menu is scheduled to close, cancel it.
		if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }

		// if this menu is closed, open it.
		if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
	}
}

ypSlideOutMenu.hideMenu = function(id)
{
	// schedules the menu to close after <hideDelay> ms, which
	// gives the user time to cancel the action if they accidentally moused out
	var obj = ypSlideOutMenu.Registry[id]
	if (obj.container) {
		if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
		obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
	}
}

ypSlideOutMenu.hide = function(id)
{
	var obj = ypSlideOutMenu.Registry[id]
	obj.over = false

	if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
	
	// flag that this scheduled event has occured.
	obj.hideTimer = 0

	// if this menu is open, close it.
	if (obj.open && !obj.aniTimer) obj.startSlide(false)
}

ypSlideOutMenu.prototype.startSlide = function(open) {
	this.open = open
	if (open) this.setVisibility(true)
	this.startTime = (new Date()).getTime()	
	this.aniTimer = window.setInterval(this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution)
}

ypSlideOutMenu.prototype.slide = function() {
	var elapsed = (new Date()).getTime() - this.startTime
	if (elapsed > ypSlideOutMenu.aniLen) this.endSlide()
	else {
		var d = Math.round(Math.pow(ypSlideOutMenu.aniLen-elapsed, 2) * this.accelConst)
		if (this.open && this.dirType == "-")		d = -d
		else if (this.open && this.dirType == "+")	d = -d
		else if (!this.open && this.dirType == "-")	d = -this.dim + d
		else										d = this.dim + d

		this.moveTo(d)
	}
}

ypSlideOutMenu.prototype.endSlide = function() {
	this.aniTimer = window.clearTimeout(this.aniTimer)
	this.moveTo(this.open ? this.outPos : this.homePos)
	if (!this.open) this.setVisibility(false)
	if ((this.open && !this.over) || (!this.open && this.over)) {
		this.startSlide(this.over)
	}
}

ypSlideOutMenu.prototype.setVisibility = function(bShow) { 
	var s = this.ns4 ? this.container : this.container.style
	s.visibility = bShow ? "visible" : "hidden"
}
ypSlideOutMenu.prototype.moveTo = function(p) { 
	this.style[this.orientation == "h" ? "left" : "top"] = p
}
ypSlideOutMenu.prototype.getPos = function(c) {
	return parseInt(this.style[c])
}

//functions to change image on homepage

    
//menu data
function getMenuData()
{
	document.write(

        '<DIV id=menu1Container>' +
        '    <DIV id=menu1Content class="menucenter">' +
        '        <TABLE cellSpacing=0 border=0 width="66">' +
        '            <TR>' +
     
        '            </TR>' +
        '        </TABLE>' +
        '    </DIV>' +
        '</DIV>' +
		
        '<DIV id=menu2Container>' +
        '    <DIV id=menu2Content class="menucenter">' +
        '        <TABLE cellSpacing=0 border=0 width="176">' +
        '            <TR>' +
        '                <TD vAlign=center height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/current/undergrad/default.htm" class="menuoptions">' +
        '                        &nbsp;Undergraduate Program' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '            <TR>' +
        '                <TD vAlign=center height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/current/graduate/default.htm" class="menuoptions">' +
        '                        &nbsp;Masters Program' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '            <TR>' +
        '                <TD vAlign=center height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/current/graduate/phd.htm" class="menuoptions">' +
        '                        &nbsp;Ph.D. Program' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '            <TR>' +
        '                <TD vAlign=center height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/current/courseind.htm" class="menuoptions">' +
        '                        &nbsp;Courses Offered' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '        </TABLE>' +
        '    </DIV>' +
        '</DIV>' +
		
        '<DIV id=menu3Container>' +
        '    <DIV id=menu3Content class="menucenter">' +
        '        <TABLE cellSpacing=0 border=0 width="176">' +
        '            <TR>' +
        '                <TD vAlign=center height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/admissions/undergrad/default.htm" class="menuoptions">' +
        '                        &nbsp;Undergraduate Program' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '            <TR>' +
        '                <TD vAlign=center height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/admissions/graduate/default.htm" class="menuoptions">' +
        '                        &nbsp;Graduate Program' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '            <TR>' +
        '                <TD vAlign=center height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/admissions/application/default.htm" class="menuoptions">' +
        '                        &nbsp;Application Information' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '        </TABLE>' +
        '    </DIV>' +
        '</DIV>' +

		
		
		

        '<DIV id=menu4Container>' +
        '    <DIV id=menu4Content class="menucenter">' +
        '        <TABLE cellSpacing=0 border=0 width="165">' +
        '            <TR>' +
        '                <TD vAlign=center height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/Research/RAreas-Labs.htm" class="menuoptions">' +
        '                        &nbsp;Research Areas & Labs' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '            <TR>' +
        '                <TD vAlign=center height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/Research/Cent-Inst.htm" class="menuoptions">' +
        '                        &nbsp;Centers & Institutes' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '            <TR>' +
        '                <TD vAlign=center height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/Research/TechReports.htm" class="menuoptions">' +
        '                        &nbsp;Technical Reports' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '        </TABLE>' +
        '    </DIV>' +
        '</DIV>' +
		
		
		'<DIV id=menu5Container>' +
        '    <DIV id=menu5Content class="menucenter">' +
        '        <TABLE cellSpacing=0 border=0 width="140">' +
        '            <TR>' +
        '                <TD vAlign=center height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/people/people.asp" class="menuoptions">' +
        '                        &nbsp;CS Faculty' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '            <TR>' +
        '                <TD vAlign=center height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/people/people.asp?type=staff" class="menuoptions">' +
        '                        &nbsp;CS Staff' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +      
        '        </TABLE>' +
        '    </DIV>' +
        '</DIV>' +


        '<DIV id=menu6Container>' +
        '    <DIV id=menu6Content class="menucenter">' +
        '        <TABLE cellSpacing=0 border=0 width="146">' +
        '            <TR>' +
        '                <TD vAlign=center align="left" height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/facultyresources/" target="_blank" class="menuoptions">' +
        '                        &nbsp;Faculty Resources' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '            <TR>' +
        '                <TD vAlign=center align="left" height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/resources/studentresources.htm" class="menuoptions">' +
        '                        &nbsp;Student Resources' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
		'            <TR>' +
        '                <TD vAlign=center align="left" height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/photogallery/" target="_blank" class="menuoptions">' +
        '                        &nbsp;Photo Gallery' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
		'            <TR>' +
        '                <TD vAlign=center align="left" height=20 onmouseover="this.bgColor=\'#FFDE5B\';" ' +
        '                    onmouseout="this.bgColor=\'\'">' +
        '                    <a href="http://www.cs.usc.edu/resources/reservation.htm" class="menuoptions">' +
        '                        &nbsp;Room Reservation' +
        '                    </a>' +
        '                </TD>' +
        '            </TR>' +
        '        </TABLE>' +
        '    </DIV>' +
        '</DIV>' +
        
     
        
        '<DIV id=menu7Container>' +
        '    <DIV id=menu7Content class="menucenter">' +
        '        <TABLE cellSpacing=0 border=0 width="66">' +
        '            <TR>' +
   
        '            </TR>' +
        '        </TABLE>' +
        '    </DIV>' +
        '</DIV>'
	);
}

//get menu
function getMenuCells()
{
    document.write(
	
		'<td valign="middle"><img src="http://www.cs.usc.edu/images/up_tri_red.gif"> </img></td>' +
        '<TD valign="middle" align="left" id="menu1" >' +
        '    <a class="menuLink"' + 
        '        onmouseover="ypSlideOutMenu.showMenu(\'menu1\');" ' +
        '        onmouseout="ypSlideOutMenu.hideMenu(\'menu1\');document.getElementById(\'menu1\').bgColor=\'\';this.style.color=\'\';" ' +
        '        href="http://www.cs.usc.edu/welcome.htm">' +       
        '        About' +
        '    </a>' +
        '</TD>' +
		
		'<td valign="middle"><img src="http://www.cs.usc.edu/images/up_tri_red.gif"> </img></td>' +
        '<TD valign="middle" align="left" id="menu2" >' +
        '    <a class="menuLink"' + 
        '        onmouseover="ypSlideOutMenu.showMenu(\'menu2\');" ' +
        '        onmouseout="ypSlideOutMenu.hideMenu(\'menu2\');document.getElementById(\'menu2\').bgColor=\'\';this.style.color=\'\';" ' +
        '        href="http://www.cs.usc.edu/current/courseind.htm">' +       
        '        Academics' +
        '    </a>' +
        '</TD>' +

	

		'<td valign="middle"><img src="http://www.cs.usc.edu/images/up_tri_red.gif"> </img></td>' +
        '<TD valign="middle" align="left" id="menu3" >' +
        '    <a class="menuLink"' + 
        '        onmouseover="ypSlideOutMenu.showMenu(\'menu3\');" ' +
        '        onmouseout="ypSlideOutMenu.hideMenu(\'menu3\');document.getElementById(\'menu3\').bgColor=\'\';this.style.color=\'\';" ' +
        '        href="http://www.cs.usc.edu/admissions/application/default.htm">' +       
        '        Admission' +
        '    </a>' +
        '</TD>' +
		
			'<td valign="middle"><img src="http://www.cs.usc.edu/images/up_tri_red.gif"> </img></td>' +
        '<TD valign="middle" align="left" id="menu4" >' +
        '    <a class="menuLink"' + 
        '        onmouseover="ypSlideOutMenu.showMenu(\'menu4\');" ' +
        '        onmouseout="ypSlideOutMenu.hideMenu(\'menu4\');document.getElementById(\'menu4\').bgColor=\'\';this.style.color=\'\';" ' +
        '        href="http://www.cs.usc.edu/Research/Cent-Inst.htm">' +       
        '        Research' +
        '    </a>' +
        '</TD>' +
		
		'<td valign="middle"><img src="http://www.cs.usc.edu/images/up_tri_red.gif"> </img></td>' +
        '<TD valign="middle" align="left" id="menu5" >' +
        '    <a class="menuLink"' + 
        '        onmouseover="ypSlideOutMenu.showMenu(\'menu5\');" ' +
        '        onmouseout="ypSlideOutMenu.hideMenu(\'menu5\');document.getElementById(\'menu5\').bgColor=\'\';this.style.color=\'\';" ' +
        '        href="http://www.cs.usc.edu/people/default.htm">' +    
        '        Faculty & Staff' +
        '    </a>' +
        '</TD>' +

		

		'<td valign="middle"><img src="http://www.cs.usc.edu/images/up_tri_red.gif"> </img></td>' +
        '<TD valign="middle" align="left" id="menu6" >' +
        '    <a class="menuLink"' + 
        '        onmouseover="ypSlideOutMenu.showMenu(\'menu6\');" ' +
        '        onmouseout="ypSlideOutMenu.hideMenu(\'menu6\');document.getElementById(\'menu6\').bgColor=\'\';this.style.color=\'\';" ' +
        '        href="http://www.cs.usc.edu/resources/default.htm">' +       
        '        Resources' +
        '    </a>' +
        '</TD>' +

		

		'<td valign="middle"><img src="http://www.cs.usc.edu/images/up_tri_red.gif"> </img></td>' +
        '<TD valign="middle" align="right" id="menu7" >' +
        '    <a class="menuLink"' + 
        '        onmouseover="ypSlideOutMenu.showMenu(\'menu7\');" ' +
        '        onmouseout="ypSlideOutMenu.hideMenu(\'menu7\');document.getElementById(\'menu7\').bgColor=\'\';this.style.color=\'\';" ' +
        '        href="http://www.cs.usc.edu/people/CSHiring.htm">' +        
        '        Jobs' +
        '    </a>' +
        '</TD>' 

    );
	
}

//initialize menu
function initMenu(left, top)
{
	if(document.body.clientWidth > 800 )
	{
		left += (document.body.clientWidth - 800)/2;
	}

		// nav menu setup
	new ypSlideOutMenu("menu1", "top", left, top, 
		(width = document.getElementById('menu1Content').childNodes.item(0).width)
		? width : document.getElementById('menu1Content').childNodes.item(1).width, 0 * (21))
	
	new ypSlideOutMenu("menu2", "top", left +20, top-20, 
		(width = document.getElementById('menu2Content').childNodes.item(0).width)
		? width : document.getElementById('menu2Content').childNodes.item(1).width, 4 * (21))
	
	new ypSlideOutMenu("menu3", "top", left + 112, top, 
		(width = document.getElementById('menu3Content').childNodes.item(0).width)
		? width : document.getElementById('menu3Content').childNodes.item(1).width, 3 * (21))
	
	new ypSlideOutMenu("menu4", "top", left + 200, top, 
		(width = document.getElementById('menu4Content').childNodes.item(0).width)
		? width : document.getElementById('menu4Content').childNodes.item(1).width, 3 * (21))
	
	new ypSlideOutMenu("menu5", "top", left + 285, top + 20, 
		(width = document.getElementById('menu5Content').childNodes.item(0).width)
		? width : document.getElementById('menu5Content').childNodes.item(1).width, 2 * (21))

	new ypSlideOutMenu("menu6", "top", left + 405, top-20, 
		(width = document.getElementById('menu6Content').childNodes.item(0).width)
		? width : document.getElementById('menu6Content').childNodes.item(1).width, 4 * (21))

	new ypSlideOutMenu("menu7", "top", left +450 , top, 
		(width = document.getElementById('menu7Content').childNodes.item(0).width)
		? width : document.getElementById('menu7Content').childNodes.item(1).width, 0 * (21))
}