function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// Horizontal drop down menu
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

// Vertical slide out menu
sfHoverVert = function() {
	if (document.getElementById("flyoutNavLeft")) {
		var sfEls = document.getElementById("flyoutNavLeft").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHoverVert);

// I want to menu
iwtSfHover = function() {
	if (document.getElementById("iwtNav")) {
		var sfEls = document.getElementById("iwtNav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", iwtSfHover);

// show/hide elements
function showHide(divId, speed) {
	
	var div = document.getElementById(divId);
	
	if (div.style.display == 'none') {
		Effect.BlindDown(div, {duration: speed});
	} else {
		Effect.BlindUp(div, {duration: speed});
	}
	
}

function showDiv(divId) {
	
	var div = document.getElementById(divId);
	
	if (div.style.display == 'none') {
		Effect.BlindDown(div, {duration: 0});
	}
	
}

function hideDiv(divId) {
	
	var div = document.getElementById(divId);
	
	if (div.style.display != 'none') {
		Effect.BlindUp(div, {duration: 0});
	} 
	
}

function stickyNav(navItem) {
	button = document.getElementById(navItem);
	if (button.className == "") {
		button.setAttribute("class", "mainNavActive");
	} else {
		button.setAttribute("class", "");
	}
}

// Show the "shader" div and adjuct the zIndex of elements
function shadeBG(ev) {
	el = (ev.target) ? ev.target : ev.srcElement;
	// affected elements
	var mainNavigation = document.getElementById("mainNavigation");
	var iWantToMenu = document.getElementById("iWantToMenu");
	var shader = document.getElementById("shader");
	
	// Close the fader
	if (shader.style.opacity > 0) {
		if (el.tagName != "A") {
			// Set zIndex of elements
			iWantToMenu.style.zIndex = "1";
			var t=setTimeout("document.getElementById('shader').style.height = '0%'",500);
			var t=setTimeout("document.getElementById('shader').style.width = '0px'",500);
			// Fade shader
			new Effect.Opacity('shader', { 
			  duration: 0.5,
			  transition: Effect.Transitions.sinoidal,
			  from: 0.5, 
			  to: 0.0
			});
		}
	// Show the fader
	} else {
		// Set zIndex of elements
		iWantToMenu.style.zIndex = "10";
		shader.style.zIndex = "7";
		// Change hieght and width For IE 6-
		shader.style.height = "2000px";
		shader.style.width = "888px";
		// Fade shader
		new Effect.Opacity('shader', { 
		  duration: 0.5,
		  transition: Effect.Transitions.sinoidal,
		  from: 0.0, 
		  to: 0.5
		});
	}
}

// Closes alert dialog and redirects to current URL with preferences quaery string
function switchOff(div, mode, uri) {
	new Effect.Opacity(div, { from: 0.92, to: 0.0, duration: 1 })
	var t = setTimeout("window.location = '/"+uri+"?bu="+mode+"'", 2000);
}

// Hides video player
function toggleVideoPlayer(src_element, div_id, effect){
	Effect.toggle(div_id, effect, {afterFinish:function(){
		var image = document.getElementById('toggleImage');
		var first_img = "/images/icons/collapseUp.jpg";
		var second_img = "/images/icons/collapseDown.jpg";
		var first_title = "Hide Video Player";
		var second_title = "Show Video Player";
		image.src = image.src.match(first_img) ? second_img : first_img;
		image.title = image.title.match(first_title) ? second_title : first_title;
	}});
	return true;
}

function overlayspoof() {
	
	if (document.domain == 'mayorofbaltimore.org' || document.domain == 'www.mayorofbaltimore.org') {
		var bodyid = document.getElementById('mayor');
		bodyid.style.display = 'none';
	}
	
}
addLoadEvent(overlayspoof);

