/*****************************************************
* ypSlideOutMenu
* Code from  www.youngpup.net
* --youngpup--  3/04/2001
*
* Modified by City of Madison, Wisconsin
* 			  Department of Information Services
*			  4/14/2006
*****************************************************/
IE = document.all?1:0;
NAV6 = document.getElementById?1:0;

nav=(navigator.appName.indexOf("Netscape") != -1)?1:0; 
ie2=(navigator.userAgent.indexOf("MSIE") != -1)?1:0;
v4=(parseInt(navigator.appVersion)>=4)?1:0;
ie=(document.all && v4)?1:0;
ie4=(nav || document.getElementById)?1:0;
ns=(document.layers && v4)?1:0;
nc=(!ie && document.getElementById)?1:0;

// prints code necessary for sliding dropdown menu of agencies
function writeAgency(){
	
	agencies = new Array;             
	agencies[1] = new Array("Assessor","http://www.cityofmadison.com/assessor/") 
	agencies[2] = new Array("Attorney","http://www.cityofmadison.com/attorney/") 
	agencies[3] = new Array("Building Insp &amp; Code Enforcement","http://www.cityofmadison.com/BI/bihome.html") 
	agencies[4] = new Array("Civil Rights","http://www.cityofmadison.com/dcr/") 
	agencies[5] = new Array("Clerk","http://www.cityofmadison.com/clerk/")
	agencies[6] = new Array("Common Council","http://www.cityofmadison.com/council/")
	agencies[7] = new Array("Community Development Block Grants","http://www.cityofmadison.com/cdbg/") 
	agencies[8] = new Array("Community &amp; Economic Development","http://www.cityofmadison.com/planning/cedu.html")
	agencies[9] = new Array("Community Services","http://www.cityofmadison.com/commserv/index.html")
	agencies[10] = new Array("Engineering","http://www.cityofmadison.com/engineering/")
	agencies[11] = new Array("Finance","http://www.cityofmadison.com/finance/")
	agencies[12] = new Array("Fire","http://www.cityofmadison.com/fire/")
	agencies[13] = new Array("Golf","http://www.cityofmadison.com/golf/")
	agencies[14] = new Array("Housing","http://www.cityofmadison.com/housing/")
	agencies[15] = new Array("Human Resources","http://www.cityofmadison.com/HR/")
	agencies[16] = new Array("Information Technology","http://www.cityofmadison.com/IT/")
	agencies[17] = new Array("Library","http://www.madisonpubliclibrary.org/") 
	agencies[18] = new Array("Madison City Channel","http://www.cityofmadison.com/citychannel/")
	agencies[19] = new Array("Mayor's Office","http://www.cityofmadison.com/mayor/")
	agencies[20] = new Array("Metro Transit","http://www.cityofmadison.com/metro/")
	agencies[21] = new Array("Monona Terrace","http://www.mononaterrace.com/")
	agencies[22] = new Array("Municipal Court","http://www.cityofmadison.com/MunicipalCourt/")
	agencies[23] = new Array("Parking","http://www.cityofmadison.com/parkingutility/")
	agencies[24] = new Array("Parks","http://www.cityofmadison.com/parks/")
	agencies[25] = new Array("Planning &amp; Development","http://www.cityofmadison.com/planning/index.html")
	agencies[26] = new Array("Planning","http://www.cityofmadison.com/planning/plan.html")
	agencies[27] = new Array("Police","http://www.cityofmadison.com/police/")
	agencies[28] = new Array("Public Health <br>Madison &amp; Dane County","http://www.publichealthmdc.com/")
	agencies[29] = new Array("Public Works","http://www.cityofmadison.com/business/PW/")
	agencies[30] = new Array("Senior Center","http://www.cityofmadison.com/seniorcenter/")
	agencies[31] = new Array("Streets","http://www.cityofmadison.com/streets/")
	agencies[32] = new Array("Traffic Engineering","http://www.cityofmadison.com/trafficEngineering/")
	agencies[33] = new Array("Treasurer","http://www.cityofmadison.com/Treasurer/")
	agencies[34] = new Array("Water Utility","http://www.cityofmadison.com/water/")
	
	document.write('<div style="visibility:hidden;" id="agencyContainer" align="left">');
	document.write('<div style="visibility:inherit;overflow:auto;z-index:500" id="agencyContent" class="menuCont">');
	document.write('<div style="visibility:inherit;z-index:500" class="options">');
	
	for (var i=1;i<agencies.length;i++){
		document.write('<a class="menu" href="'+agencies[i][1]+'">'+agencies[i][0]+'</a>')
	}
	
	document.write('</div></div></div>')  
}

// prints code necessary for sliding dropdown menu of contact us links
function writeContact(){
	contact = new Array;
	contact[1] = new Array("Mayor","http://www.cityofmadison.com/mayor/")              
	contact[2] = new Array("City Council","http://www.cityofmadison.com/council/contact/") 
	contact[3] = new Array("City Staff &amp; Agencies","http://www.cityofmadison.com/contact/")
	
	document.write('<div style="visibility:hidden;" id="contactContainer" align="left">');
	document.write('<div style="visibility:inherit;overflow:auto;z-index:500" id="contactContent" class="menuCont">');
	document.write('<div style="visibility:inherit;z-index:500" class="options">');
	
	for (var i=1;i<contact.length;i++){
		document.write('<a class="menu" href="'+contact[i][1]+'">'+contact[i][0]+'</a>')
	}
	
	document.write('</div></div></div>')  
}

function rePosx(){
	var IE = document.all?true:false
	var tempX
	if (IE) { 
		tempX = document.all.agencyName.offsetLeft 
		if(tempX == 0){
			tempX = ((document.body.offsetWidth/2) - 210)
		}
		return tempX
	} else if(NAV6){  
		tempX = document.getElementById('agencyName').offsetLeft
		return tempX 
	} else {
		return true 
	}
}

function rePosy(){
var IE = document.all?true:false
var tempY
if (IE) { 
  tempY = document.all.agencyName.offsetTop 
  if(tempY == 0){return tempY + 20}
  else {return tempY -177
  }
   
} else if(NAV6) {  
  tempY = document.getElementById('agencyName').offsetTop
  return tempY - 177
} else { 
  return true
  }
}

ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 250
ypSlideOutMenu.hideDelay = 0
ypSlideOutMenu.minCPUResolution = 10

ypSlideOutMenu.styleMod = '';

function ypSlideOutMenu(id, dir, left, top, width, height, parentid, degrade, debug)
{

	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.degrade = degrade;
		this.debug = debug;
		this.sliding = false;
		this.id = id
		this.parentid = parentid
		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
		this.gRef = "ypSlideOutMenu_"+id
		eval(this.gRef+"=this")
		ypSlideOutMenu.Registry[id] = this
		
		this.initleft = left
		this.inittop = top
		this.initwidth = width
		this.initheight = height
		this.showcount = 0;

		ypSlideOutMenu.styleMod += '#' + this.id + 'Container { visibility:hidden; ';
		ypSlideOutMenu.styleMod += 'left:' + left + 'px; ';
		ypSlideOutMenu.styleMod += 'z-index:500; ';
		ypSlideOutMenu.styleMod += 'top:' + top + 'px; ';
		ypSlideOutMenu.styleMod += 'overflow:hidden; }';
		ypSlideOutMenu.styleMod += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; ';
		ypSlideOutMenu.styleMod += 'height:' + height + 'px; ';
		ypSlideOutMenu.styleMod += 'width:' + width + 'px; ';
		ypSlideOutMenu.styleMod += 'z-index:500; ';
		ypSlideOutMenu.styleMod += 'clip:rect(0 ' + width + ' ' + height + ' 0); ';
		ypSlideOutMenu.styleMod += '}  ';
		
		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)
	if (!obj1 || !obj2) {
		window.setTimeout(this.gRef + ".load()", 1000);
	} else {
		this.container = obj1
		this.menu = obj2
		this.style = this.ns4 ? this.menu : this.menu.style
		// SEE NOTE ABOVE.  The following function call for the 31 menus bug.
		//this.setStyle()
		this.homePos = eval("0" + this.dirType + this.dim)
		this.outPos = 0
		this.accelConst = (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen 
		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 + "')")
		this.endSlide()
	}
}

ypSlideOutMenu.showMenu = function(id, e)
{

	var reg = ypSlideOutMenu.Registry
	var obj = ypSlideOutMenu.Registry[id]
	if (obj.container) {
//		if (obj.ie) alert('showing: ' + id);
		obj.over = true
		if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }
		obj.showcount++;
		if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
	}
	if (obj.ns4) obj.menu.routeEvent(Event.MOUSEOVER);
}

ypSlideOutMenu.hideMenu = function(id, e)
{
	var obj = ypSlideOutMenu.Registry[id]
	if (obj.container) {
//		if (obj.ie) alert('hiding: ' + id);
		if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
		obj.showcount--;
		obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
	}
	if (obj.ns4) obj.menu.routeEvent(Event.MOUSEOUT);
}

ypSlideOutMenu.hide = function(id) {
	var obj = ypSlideOutMenu.Registry[id]
	var reg = ypSlideOutMenu.Registry
	obj.over = false
	if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
	obj.hideTimer = 0
	var close = true;
	for (menu in reg) {
		// for each child, if either
		//  1. the child is open or
		//  2. the child is closing (but hasn't closed yet)
		// then we don't close this menu.
		var pid = ypSlideOutMenu.Registry[menu].parentid
		if (pid == id) {
			if (ypSlideOutMenu.Registry[menu].open) close = false;
			if (!ypSlideOutMenu.Registry[menu].open && ypSlideOutMenu.Registry[menu].sliding) close = false;
		}
	}
	if (obj.open && !obj.aniTimer && close && !obj.showcount) obj.startSlide(false);
}


ypSlideOutMenu.prototype.startSlide = function(open) {
	this.open = open
	if (open) this.setVisibility(true)
	this.startTime = (new Date()).getTime() 
	this.sliding = true;
	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)
	this.sliding = false;
	if (((this.open && !this.over) || (!this.open && this.over)) && (!this.parent || this.parent.open)) {
		this.startSlide(this.over)
	} else {
		var overchild = false;
		var reg = ypSlideOutMenu.Registry
		for (menu in reg) {
			var pid = ypSlideOutMenu.Registry[menu].parentid
			if (pid == this.id) overchild = ypSlideOutMenu.Registry[menu].over ? true : overchild		
		}
//		if (!overchild && this.parentid && !ypSlideOutMenu.Registry[this.parentid].over) ypSlideOutMenu.hideMenu(this.parentid);
		if (!overchild && this.parentid && !ypSlideOutMenu.Registry[this.parentid].over) ypSlideOutMenu.hide(this.parentid);
	}
}

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])
}


