
function ajax(url, method) { 
	var http_request = false;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest(); 
	} else if (window.ActiveXObject) {
		http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	http_request.onreadystatechange = function (){
		if (http_request.readyState == 4) { 
			if (http_request.status == 200) { 
				method(http_request.responseText); 
			} else { 
				alert('There was a problem with the request.'); 
			} 
		} 
	}
	if(url.indexOf('?') > 0) {
		url += "&time=" + (new Date).getTime();
	} else {
		url += "?time=" + (new Date).getTime();
	}
	http_request.open('GET', url, true); 
	http_request.send(null); 
}
/////////////////////////////////////////////////////////////////////
// Testimonials:                                                   //
// type: the testimonial type (see testimonials file)              //
// id: id of object to display in on page                          //
// time: time that each testimonial stays on the screen at one time//
// display: the display type, see displayType object               //
/////////////////////////////////////////////////////////////////////
var displayType = {Fade:0,Scroll:1,Flip:2,One:3};
function Testimonial(type,id,time,display) {
	if(time == null) time = 7000;
	ajax("http://www.washburn.edu/ao/style/testimonials.php?type="+type,function(response) {
				if(display == null) display = displayType.Flip;
				if(display == displayType.Fade || display == displayType.Flip) {
					startTestimonials(response,id,time, display, true); // true: for random testimonials
				} else if (display == displayType.Scroll) {
					startScrollingTestimonials(response,id,time);
				} else {
					var tests = eval("("+response+")");
					document.getElementById(id).innerHTML = unescape(tests[0][0]);
					document.getElementById(id).className = tests[0][1];
				}
			});
}
function startScrollingTestimonials(testimonials, object, time) {
	document.getElementById(object).style.overflow = 'hidden';
	privateStartScrollingTestimonials(testimonials, object, time, 0);
}
function privateStartScrollingTestimonials(testimonials, object, time, i) {
	var obj = document.getElementById(object);
	var tests = eval("(" + testimonials + ")");
	if(tests.length > 0) {
		if(! tests[i]) i = 0;
		var j = 1;
		var childName = '';
		if(document.getElementById(object).childNodes.length == 0) {
			while(document.getElementById('test' + j)) {
				j++;
			}
			childName = 'test' + j;
			obj.innerHTML = "<div style='position:relative' id='" + childName + "'></div>";
		} else {
			childName = object;
		}
		var obj2 = document.getElementById(childName);
		obj2.style.left = obj.offsetWidth;
		obj2.innerHTML= "<div class='" + tests[i][1] + "'>" + unescape(tests[i][0]) + "</div>";
		scroll2(object, ('test' + j), obj.offsetWidth, obj2.offsetWidth * -1, i, testimonials,time);
	} else {
		obj.innerText = "More To Come";
	}
	obj = null;
	tests = null;
}
function scroll2(object, obj, j,to,i, testimonials,time) {
	var container = document.getElementById(object);
	var textObj = document.getElementById(obj);
	var to2 = -1 * textObj.offsetWidth;
	moveTo2(obj,j,to2,i,testimonials,time,object);
}
function moveTo2(obj,j,to,i,testimonials,time,object) {
	if(j == to) {
		privateStartScrollingTestimonials(testimonials,obj,time,(i+1));
	} else {
		document.getElementById(obj).style.left = j + 'px';
		j--;
		setTimeout('scroll2("'+object+'","'+obj+'",'+j+','+to+','+i+',\''+testimonials+'\','+time+')',time);
	}
}
function startTestimonials(testimonials, object, time, display, rand) {
	privateStartTestimonials(testimonials,object,time,0, display, rand);
}
function privateStartTestimonials(testimonials, object, time, i, display, rand) {
	var obj = document.getElementById(object);
	var tests = eval("(" + testimonials + ")");
	if(tests.length > 0) {
		if(i > tests.length || (! tests[i])) {
			i = 0;
		}
		if(display == 0) {
			opacity(object,100,0,1000, tests[i]);
		} else { 
			if(rand) {
				i = Math.round( ( Math.random() * (tests.length - 1) ) );
			}
			document.getElementById(object).innerHTML = "<div class='" + tests[i][1] + "'>" + unescape(tests[i][0]) + "</div>";
		}
		setTimeout('privateStartTestimonials(\''+testimonials+'\',\''+object+'\','+time+','+(i+1)+','+display+','+rand+')',time);
	} else {
		obj.innerText = "More To Come";
	}
	obj = null;
	tests = null;
}
function opacity(id, opacStart, opacEnd, millisec, text) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
	var timer = 0;
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "', '"+text+"',"+opacEnd+","+opacStart+","+millisec+")",(timer * speed * 2));
			timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++) {
            setTimeout("changeOpac(" + i + ",'" + id + "', '"+text+"',"+opacEnd+","+opacStart+","+millisec+")",(timer * speed * 2));
			timer++;
        }
    }
}
function changeOpac(opacity2, id,text,end,start,millisec) {
    var object = document.getElementById(id);
    object.style.opacity = (opacity2 / 100);
    object.style.MozOpacity = (opacity2 / 100);
    object.style.KhtmlOpacity = (opacity2 / 100);
    object.style.filter = "alpha(opacity=" + opacity2 + ")";
	if(text != null && (opacity2 == 0)) {
		object.innerHTML = text;
		opacBack(id,end,start,millisec);
	}
} 
function opacBack(id, opacStart, opacEnd, millisec) {
    var timer = 0;
    var speed = Math.round(millisec / 100);
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed * 2));
			timer ++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++) {
            setTimeout("changeOpac(" + (i+1) + ",'" + id + "')",(timer * speed * 2));
			timer ++;
        }
    }
}
////////////////////////////////////////////
// Button Creation                        //
// style: array with                      //
// 		  all three images with optional  //
//        optional css style for button   //
////////////////////////////////////////////
var buttonStyles = {darkBlue:["images/darkblue.gif","images/darkblue_hover.gif","images/darkblue_down.gif","100px","41px","darkblueButton"],
					blank:["images/","images/","images/","0px","0px",""]
				   };
var buttonStyle = function(style) {
	if (style.length == 5 || style.length == 6) {
		this.style = style;
		this.newButton = function(displayText, url, pre) {
			if(displayText.constructor.toString().indexOf("Array") != -1) {
				this.displayText = displayText[0];
				this.url = displayText[1];
			} else {
				this.displayText = displayText;
				this.url = url;
			}
			return new Button(this.displayText, this.url, this.style, pre);
		};
	} else {
		this.newButton = function(displayText, url, pre) {
			alert("cannot create button instance, check to make sure the button style is formatted correctly.");
		}
	}
}
var Button = function(displayText, url, style, pre) {
	this.displayText = displayText;
	this.url = url;
	this.style = style;
	var linkpre = pre;
	if(url.substr(0,4) == "http" || url.substr(0,3) == "www") {
		linkpre = "";
	}
	this.pre = pre;
	this.linkpre = linkpre;
	this.toHTML = function(name, hide) {
		var html = "";
		if(name!="") {
			html = "<table><tr><td height='" + style[4] + "' width='" + style[3] + "' background='" + pre + style[0] + "'";
			if(style.length == 6) {
				html += " class='" + style[5] + "'";
			}
			html += " onmouseover='javascript:this.background=\"" + pre + style[1] + "\";" + (hide? "showSubMenu(\""+name+"\");" : "") + "'";
			html += " onmousedown='javascript:this.background=\"" + pre + style[2] + "\"'";
			html += " onmouseup='javascript:this.background=\"" + pre + style[1] + "\";document.location=\"" + linkpre + this.url + "\"';";
			html += " onmouseout='javascript:this.background=\"" + pre + style[0] + "\";" + (hide? "hideSubMenu(\""+name+"\");" : "") + "'>";
			html += "<a href='" + linkpre + this.url + "'";
			html += " onmouseover='javascript:this.parentNode.background=\"" + pre + style[1] + "\"'";
			html += " onmousedown='javascript:this.parentNode.background=\"" + pre + style[2] + "\"'";
			html += " onmouseup='javascript:this.parentNode.background=\"" + pre + style[1] + "\"'";
			html += " onmouseout='javascript:this.parentNode.background=\"" + pre + style[1] + "\"'>" + this.displayText + "</a>";
			html += "</td></tr></table>";
			//var subMenu = "<div id='"+name+"'>" + getHTML(this.subMenu,name, hide) + "</div>";
			//html += subMenu;
		}
		return html;
	}
	this.subMenu = null;
}
function getHTML(menu, name, hide) {
	var html = "";
	if(menu != null) {
			html = _getHTML(menu, name, hide);
	}
	return html;
}
function _getHTML(menu, name, hide) {
	var html = "<div id='"+name+"SubMenu' class='subMenu" + (hide? "" : "Show") + "' "+ (hide? "onmouseover='showSubMenu(\""+name+"\")' onmouseout='hideSubMenu(\""+name+"\")'" : "") + ">";
	var color = ["#4981CE","white"]; // different colors to alternate if you need for the sub links
	for(var i = 0; i < menu.length; i++) {
		if(menu[i]) {
			html += "<div style='background-color:"+color[i%color.length]+"' onclick='document.location=\"" + menu[i].url + "\"'><a href='../" + menu[i].url + "'>" + menu[i].displayText + "</a></div>";
		}
	}
	html += "</div>";
	return html;
}
var timer = null;
var lastName = "";
function showSubMenu(name) {
	if(lastName == "") {
		lastName = name;
	}
	if(timer || lastName != name)
		clearTimeout(timer);
	var obj = document.getElementById(name+"SubMenu");
	if(obj) {
		obj.className = "subMenuShow";
	}
	lastName = name;
}
function hideSubMenu(name) {
	timer = setTimeout("_hideSubMenu('"+name+"')",50);
}
function _hideSubMenu(name, degree) {
	var obj = document.getElementById(name+"SubMenu");
	if(obj)
		obj.className = "subMenu";
}

function adminProEvent(title,description) {
	var html = '<table width="550" cellpadding="5" cellspacing="0" style="border: 1px solid #ddaaaa"><tr><td valign="top"><p><strong><font color="#000000" face="Arial, Helvetica, sans-serif">' + title + '<br>';
	html += '</font></strong><font color="#000000" size="2" face="Arial, Helvetica, sans-serif">' + description + '</font></td></tr></table><br />';
	return html;
}
function openWindow(url, height, width) {
	window.open(url,"_blank","height="+height+",width="+width+",scrollbars=yes");
}
Object.prototype.left = function() {
	var curleft = 0;
	var obj = this;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
		} while (obj = obj.offsetParent);
	}
	return curleft;
}
Object.prototype.top = function() {
	var curtop = 0;
	var obj = this;
	if (obj.offsetParent) {
		do {
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return curtop;
}
String.prototype.getAlphaOnly = function() {
	var r = "";
	for(var i = 0; i < this.length; i++) {
		r += (this.substr(i,1).search(/[A-Za-z]/) >= 0) ? this.substr(i,1) : "";
	}
	return r;
}