﻿function GetXHO() {
	var xmlHttp;

	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
    		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) {
			xmlHttp = false;
		}
	}
	@end @*/

	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
		xmlHttp = new XMLHttpRequest();
	}
	return xmlHttp;
}

function $(el) {
  return document.getElementById(el);
}

function OI(obj) {
  var msg = Array();
  
  for (p in obj) {
    msg[msg.length] = p;
  }
  msg = msg.join(", ");
  alert(msg);
}
function getX(e) {
  var x = 0;
  while(e) {
    x += e.offsetLeft;
    e = e.offsetParent;
  }
  return x;
}
 
function OpenWindow(url, height, width, scrollable) {
    if (!height) height = 300;
    if (!width) width = 300;
    scrollable = scrollable ? ",scrollbars" : "";
    var win = window.open(url, "", "resizable=1,toolbar=0,location=0,status=0,menubar=0" + scrollable + ",width=" + width + ",height=" + height);
    win.focus();
}

function CascadedStyle(el, cssproperty, csspropertyNS){
    if (el.currentStyle) return el.currentStyle[cssproperty];
    else if (window.getComputedStyle) return window.getComputedStyle(el, "").getPropertyValue(csspropertyNS);
}

var drops = new Array();
var ad = null;
var ht = null;
var o = null;
function LoadDrops() {
	var t = $("top-menu");
	o = $("outer");
	var a_a = t.getElementsByTagName('a');
	for (var x=0;x<a_a.length;x++) {
		var a = a_a[x];
		var d = $('d' + a.id.substring(1));
		if (!d) continue;
		a.drop = d.id;
		a.onmouseover = function() {
			var d = $(this.drop);
			if (ad) {
				if (ad !== d) {
					if (ht) window.clearTimeout(ht);
					//alert("Cancelling delayed hide, and doing it immediately");
					ad.style.display = "none";
					ad = null;
				} else {
					if (ht) window.clearTimeout(ht);
				}
			}
		    var styleProp = "width";
            var width = CascadedStyle(d, "width", "width");
            if (!width) width = "175px";
		    width = parseInt(width.replace('px', ''));
		    var boundary = o.offsetLeft + o.offsetWidth;
		    if (this.offsetParent.offsetLeft + width > boundary) {
		        d.style.left = (boundary - width)+ "px";
		    } else {
		        d.style.left = (this.offsetParent.offsetLeft)+ "px";
		    }
		    d.style.top = (this.offsetParent.offsetTop + this.offsetParent.offsetHeight) + "px";
		    d.style.display = "block";
		    ad = d;
		}
		a.onmouseout = function() {
			//alert("start hide");
			var d = $(this.drop);
			ht = window.setTimeout("HideDrop()", 250);
		}
		var over = function() {
			if (!ht) return;
			window.clearTimeout(ht);
			//alert("cancel hide");
		}
		d.onmouseout = function() {
			if (!ad) return;
			if (ht) window.clearTimeout(ht);
			ht = window.setTimeout("HideDrop()", 250);
		}
		d.onmouseover = over;
		var e = d.getElementsByTagName('*');
		for (var y=0;y<e.length;y++) {
			e[y].onmouseover = over;
		}		
	}
}
function HideDrop() {
	if (!ad) return;
	//alert("Doing delayed Hide");
	ad.style.display = "none";
	ad = null;
}

function InitSearch() {
    var sb = $("tbSearch");
    
    sb.onfocus = function() {
        if (sb.value.toLowerCase() == "search...") sb.value = "";    
    }
    sb.onblur = function() {
        if (sb.value == "") sb.value = "Search...";
    }
    sb.onkeypress = Search;
}
function Search(e) {
    var d = "http://www.drexel.edu/search.aspx?q=";
    var keyCode;
    var source;
    
    if (!e) var e = window.event;
    
    keyCode = e.keyCode ? e.keyCode : e.charCode;
    source = e.srcElement ? e.srcElement : e.target;
    
    if (keyCode == 13) {
        location.href = d + escape(source.value);
        return false;
    }
}
function SearchClick() {
	var d = "http://www.drexel.edu/search.aspx?q=";
	var sb = $("tbSearch");
	location.href = d + escape(sb.value);
}
function InitHovers() {
    window.setTimeout("SetHovers()", 500);
}
function SetHovers() {
    var img_a = document.getElementsByTagName("img");
    if (!img_a) return;
    for (var x=0;x<img_a.length;x++) {
        var i = img_a[x];
        if (i.src.indexOf("blank.gif") == -1 && i.className.indexOf("hover") != -1) {
            i.onmouseover = function() {
                var arr = this.src.split(".");
                arr[arr.length-2] += "-over"; 
                this.src = arr.join(".");
            }
            i.onmouseout = function() {
                this.src = this.src.replace("-over.", ".");
            }
        }
    }
}

var _LoadEventFunctions = Array();

function AddLoadEvent(func) {
	_LoadEventFunctions[_LoadEventFunctions.length] = func;	
}
function LoadEvents() {
	for (var x=0;x<_LoadEventFunctions.length;x++) {
		var func = _LoadEventFunctions[x];
		func();	
	}
}

AddLoadEvent(LoadDrops);
AddLoadEvent(InitSearch);

window.onload = LoadEvents;