//-------------------------------------------sub-menu----------------------------------------------//
//Contents for menu 1, and so on
// Fac of Med. discarded in 2009
var menu1=new Array()
menu1[0]='<a style=" background-color: #451e6d; color: #ffffff" href="../faculty-event/obstetrics-and-gynaecology.html">- Obstetrics and Gynaecology</a>'

//Contents for menu 2
//Fac of Science
var menu2=new Array()
menu2[0]='<a style=" background-color: #FAB92E; color: #ffffff" href="sci_biochemistry.html">- Department of Biochemistry</a>'
menu2[1]='<a style=" background-color: #FAB92E; color: #ffffff" href="sci_biological.html">- School of Biological Sciences</a>'
menu2[2]='<a style=" background-color: #FAB92E; color: #ffffff" href="sci_chemistry.html">- Department of Chemistry</a>'
menu2[3]='<a style=" background-color: #FAB92E; color: #ffffff" href="sci_earthsciences.html">- Department of Earth Sciences</a>'
menu2[4]='<a style=" background-color: #FAB92E; color: #ffffff" href="sci_mathematics.html">- Department of Mathematics</a>'
menu2[5]='<a style=" background-color: #FAB92E; color: #ffffff" href="sci_physics.html">- Department of Physics</a>'
menu2[6]='<a style=" background-color: #FAB92E; color: #ffffff" href="sci_statistics.html">- Department of Statistics &amp; Actuarial Science</a>'

//Contents for menu 4
// Halls
var menu4=new Array()
menu4[0]='<a style=" background-color: #ff6600; color: #ffffff" href="../hall-event/suen-chi-sun-hall.html">- Suen Chi Sun Hall</a>'
menu4[1]='<a style=" background-color: #ff6600; color: #ffffff" href="../hall-event/morrison-hall.html">- Morrison Hall</a>'
menu4[2]='<a style=" background-color: #ff6600; color: #ffffff" href="../hall-event/lee-shau-kee-hall.html">- Lee Shau Kee Hall</a>'
menu4[3]='<a style=" background-color: #ff6600; color: #ffffff" href="../hall-event/swire-hall.html">- Swire Hall</a>'
menu4[4]='<a style=" background-color: #ff6600; color: #ffffff" href="../hall-event/st-john.html">- St. John\'s College</a>'

//Contents for menu 5
var menu5=new Array()
menu5[0]='<a style=" background-color: #FAB92E; color: #ffffff" href="soc_geography.html">- Geography</a>'
menu5[1]='<a style=" background-color: #FAB92E; color: #ffffff" href="soc_journalism.html">- Journalism and Media Studies Centre</a>'
menu5[2]='<a style=" background-color: #FAB92E; color: #ffffff" href="soc_politics_and_public_administration.html">- Politics and Public Administration</a>'
menu5[3]='<a style=" background-color: #FAB92E; color: #ffffff" href="soc_psychology.html">- Psychology</a>'
menu5[4]='<a style=" background-color: #FAB92E; color: #ffffff" href="soc_socialwork.html">- Social Work and Social Administration</a>'
menu5[5]='<a style=" background-color: #FAB92E; color: #ffffff" href="soc_sociology.html">- Sociology</a>'
//menu5[5]='<a style=" background-color: #FAB92E; color: #ffffff" href="../faculty-event/cognitive-science.html">- Cognitive Science Programme</a>'


//Contents for menu 6
// Fac of Arts
var menu6=new Array()
menu6[0]='<a style=" background-color: #FAB92E; color: #ffffff" href="art_chinese.html">- School of Chinese</a>'
menu6[1]='<a style=" background-color: #FAB92E; color: #ffffff" href="art_english.html">- School of English</a>'
menu6[3]='<a style=" background-color: #FAB92E; color: #ffffff" href="art_humanities.html">- School of Humanities</a>'
menu6[4]='<a style=" background-color: #FAB92E; color: #ffffff" href="art_modern.html">- School of Modern Languages and Cultures</a>'

//Contents for menu 7
// Fac of Architecture
var menu7=new Array()
menu7[0]='<a style=" background-color: #FAB92E; color: #ffffff" href="arc_rchitecture.html">- Department of Architecture</a>'
menu7[1]='<a style=" background-color: #FAB92E; color: #ffffff" href="arc_realestate.html">- Department of Real Estate and Construction</a>'

	
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var horizontaloffset=2 //horizontal offset of menu from default location. (0-5 is a good value)

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width: 160px" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x-obj.offsetWidth < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move menu up?
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either? (position at top of viewable window then)
edgeoffset=dropmenuobj.y
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+horizontaloffset+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

	
	
	
	
	
//-------------------------------------------MAIN-menu----------------------------------------------//
function SDMenu(id) {
	if (!document.getElementById || !document.getElementsByTagName)
		return false;
	this.menu = document.getElementById(id);
	this.submenus = this.menu.getElementsByTagName("div");
	this.remember = true;
	this.speed = 3;
	this.markCurrent = true;
	this.oneSmOnly = true;
}
SDMenu.prototype.init = function() {
	var mainInstance = this;
	for (var i = 0; i < this.submenus.length; i++)
		this.submenus[i].getElementsByTagName("span")[0].onclick = function() {
			mainInstance.toggleMenu(this.parentNode);
		};
	if (this.markCurrent) {
		var links = this.menu.getElementsByTagName("a");
		for (var i = 0; i < links.length; i++)
			if (links[i].href == document.location.href) {
				links[i].className = "current";
				break;
			}
	}
	if (this.remember) {
		var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([01]+)");
		var match = regex.exec(document.cookie);
		if (match) {
			var states = match[1].split("");
			for (var i = 0; i < states.length; i++)
				this.submenus[i].className = (states[i] == 0 ? "collapsed" : "");
		}
	}
};
SDMenu.prototype.toggleMenu = function(submenu) {
	if (submenu.className == "collapsed")
		this.expandMenu(submenu);
	else
		this.collapseMenu(submenu);
};
SDMenu.prototype.expandMenu = function(submenu) {
	var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var links = submenu.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++)
		fullHeight += links[i].offsetHeight;
	var moveBy = Math.round(this.speed * links.length);
	
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight + moveBy;
		if (newHeight < fullHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "";
			mainInstance.memorize();
		}
	}, 30);
	this.collapseOthers(submenu);
};
SDMenu.prototype.collapseMenu = function(submenu) {
	var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length);
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight - moveBy;
		if (newHeight > minHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "collapsed";
			mainInstance.memorize();
		}
	}, 30);
};
SDMenu.prototype.collapseOthers = function(submenu) {
	if (this.oneSmOnly) {
		for (var i = 0; i < this.submenus.length; i++)
			if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed")
				this.collapseMenu(this.submenus[i]);
	}
};
SDMenu.prototype.expandAll = function() {
	var oldOneSmOnly = this.oneSmOnly;
	this.oneSmOnly = false;
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className == "collapsed")
			this.expandMenu(this.submenus[i]);
	this.oneSmOnly = oldOneSmOnly;
};
SDMenu.prototype.collapseAll = function() {
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className != "collapsed")
			this.collapseMenu(this.submenus[i]);
};
SDMenu.prototype.memorize = function() {
	if (this.remember) {
		var states = new Array();
		for (var i = 0; i < this.submenus.length; i++)
			states.push(this.submenus[i].className == "collapsed" ? 0 : 1);
		var d = new Date();
		d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
		document.cookie = "sdmenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/";
	}
};