// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 
// Coded by Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
// If want to use this code, feel free to do so, but please leave this message intact.
//
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// --- version date: 01/24/03 ---------------------------------------------------------

// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Cross-Browser Functions

var dom = document.getElementById;
var iex = document.all;
var ns4 = document.layers;

function addEvent(event,method){
	this[event] = method;
	if(ns4) this.captureEvents(Event[event.substr(2,event.length).toUpperCase()]);
}
function removeEvent(event){
	this[event] = null;
	if(ns4) this.releaseEvents(Event[event.substr(2,event.length).toUpperCase()]);
}
function getElement(name,nest){
	nest = nest ? "document."+nest+"." : "";
	var el = dom ? document.getElementById(name) : iex ? document.all[name] : ns4 ? eval(nest+"document."+name) : false;
	el.css = ns4 ? el : el.style;
	el.getTop = function(){return parseInt(el.css.top) || 0};
	el.setTop = function(y){el.css.top = ns4 ? y: y+"px"};
	el.getHeight = function(){return ns4 ? el.document.height : el.offsetHeight};
	el.getClipHeight = function(){return ns4 ? el.clip.height : el.offsetHeight};
	el.hideVis = function(){el.css.visibility="hidden"};
	el.addEvent = addEvent;
	el.removeEvent = removeEvent;
	return el;
}
function getYMouse(e){
	return iex ? event.clientY : e.pageY;
}

document.addEvent = addEvent;
document.removeEvent = removeEvent;

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Scroller Class

ScrollObj = function(speed, dragHeight, trackHeight, trackObj, upObj, downObj, dragObj, contentMaskObj, contentObj){
	this.speed = speed;
	this.dragHeight = dragHeight;
	this.trackHeight = trackHeight;
	this.trackObj = getElement(trackObj);
	this.upObj = getElement(upObj);
	this.downObj = getElement(downObj);
	this.dragObj = getElement(dragObj);
	this.contentMaskObj = getElement(contentMaskObj);
	this.contentObj = getElement(contentObj,contentMaskObj);
	this.obj = contentObj+"Object";
	eval(this.obj+"=this");
	
	this.trackTop = this.dragObj.getTop();
	this.trackLength = this.trackHeight-this.dragHeight;
	this.trackBottom = this.trackTop+this.trackLength;
	this.contentMaskHeight = this.contentMaskObj.getClipHeight();
	this.contentHeight = this.contentObj.getHeight();
	this.contentLength = this.contentHeight-this.contentMaskHeight;
	this.scrollLength = this.trackLength/this.contentLength;
	this.scrollTimer = null;
	
	if(this.contentHeight <= this.contentMaskHeight){
		this.dragObj.hideVis();
	}else{
		var self = this;
		this.trackObj.addEvent("onmousedown", function(e){self.scrollJump(e);return false});
		this.upObj.addEvent("onmousedown", function(){self.scroll(self.speed);return false});
		this.upObj.addEvent("onmouseup", function(){self.stopScroll()});
		this.upObj.addEvent("onmouseout", function(){self.stopScroll()});
		this.downObj.addEvent("onmousedown", function(){self.scroll(-self.speed);return false});
		this.downObj.addEvent("onmouseup", function(){self.stopScroll()});
		this.downObj.addEvent("onmouseout", function(){self.stopScroll()});
		this.dragObj.addEvent("onmousedown", function(e){self.startDrag(e);return false});
		if(iex) this.dragObj.addEvent("ondragstart", function(){return false});
	}
}
ScrollObj.prototype.startDrag = function(e){
	this.dragStartMouse = getYMouse(e);
	this.dragStartOffset = this.dragObj.getTop();
	var self = this;
	document.addEvent("onmousemove", function(e){self.drag(e)});
	document.addEvent("onmouseup", function(){self.stopDrag()});
}
ScrollObj.prototype.stopDrag = function(){
	document.removeEvent("onmousemove");
	document.removeEvent("onmouseup");
}
ScrollObj.prototype.drag = function(e){
	var currentMouse = getYMouse(e);
	var mouseDifference = currentMouse-this.dragStartMouse;
	var dragDistance = this.dragStartOffset+mouseDifference;
	var dragMovement = (dragDistance<this.trackTop) ? this.trackTop : (dragDistance>this.trackBottom) ? this.trackBottom : dragDistance;
	this.dragObj.setTop(dragMovement);
	var contentMovement = -(dragMovement-this.trackTop)*(1/this.scrollLength);
	this.contentObj.setTop(contentMovement);
}
ScrollObj.prototype.scroll = function(speed){
	var contentMovement = this.contentObj.getTop()+speed;
	var dragMovement = this.trackTop-Math.round(this.contentObj.getTop()*(this.trackLength/this.contentLength));
	if(contentMovement > 0){
		contentMovement = 0;
	}else if(contentMovement < -this.contentLength){
		contentMovement = -this.contentLength;
	}
	if(dragMovement < this.trackTop){
		dragMovement = this.trackTop;
	}else if(dragMovement > this.trackBottom){
		dragMovement = this.trackBottom;
	}
	this.contentObj.setTop(contentMovement);
	this.dragObj.setTop(dragMovement);
	this.scrollTimer = window.setTimeout(this.obj+".scroll("+speed+")",25);
}
ScrollObj.prototype.stopScroll = function(){
	if(this.scrollTimer){
		window.clearTimeout(this.scrollTimer);
		this.scrollTimer = null;
	}
}
ScrollObj.prototype.scrollJump = function(e){
	var currentMouse = getYMouse(e);
	var dragDistance = currentMouse-(this.dragHeight/2);
	var dragMovement = (dragDistance<this.trackTop) ? this.trackTop : (dragDistance>this.trackBottom) ? this.trackBottom : dragDistance;
	this.dragObj.setTop(dragMovement);
	var contentMovement = -(dragMovement-this.trackTop)*(1/this.scrollLength);
	this.contentObj.setTop(contentMovement);
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Misc Functions

function fixNetscape4(){
	if(ns4origWidth != window.innerWidth || ns4origHeight != window.innerHeight){
		window.location.reload();
	}	
}
if(document.layers){
	ns4origWidth = window.innerWidth;
	ns4origHeight = window.innerHeight;
	window.onresize = fixNetscape4;
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||
//		Tabs switch
// ||||||||||||||||||||||||||||||||||||||||||||||||||
function moveScrubber(whichLayer, newTop) {
	if (document.getElementById) {
		document.getElementById(whichLayer).style.top = newTop;
	}
	else if (document.all) {
		document.all[whichlayer].style.left = newTop;
	}
	else if (document.layers) {
		document.layers[whichLayer].left = newTop;
	}
}
//<div id="news_holder_dg" style="position:absolute; left:156px; top:15px; z-index:4; cursor:pointer;"> 
function hideLayer(whichLayer) {
	//var whichLayer = iniStep;
	if (document.getElementById) {
		// this is the way the standards work
		document.getElementById(whichLayer).style.display = "none";
	}
	else if (document.all) {
		// this is the way old msie versions work
		document.all[whichlayer].style.display = "none";
	}
	else if (document.layers) {
		// this is the way nn4 works
		document.layers[whichLayer].display = "none";
	}
}
function showLayer(whichLayer) {	
	if (document.getElementById) {
		document.getElementById(whichLayer).style.display = "block";		
	}
	else if (document.all) {
		document.all[whichlayer].style.display = "block";
	}
	else if (document.layers) {
		document.layers[whichLayer].display = "block";
	}
}
function sortLayer(whichLayer, newZ) {
	if (document.getElementById) {
		document.getElementById(whichLayer).style.zIndex = newZ;
	}
	else if (document.all) {
		document.all[whichlayer].style.zIndex = newZ;
	}
	else if (document.layers) {
		document.layers[whichLayer].zIndex = newZ;
	}
}
function classLayer(whichLayer, newClass) {
	if (document.getElementById) {
		document.getElementById(whichLayer).className = newClass;
	}
	else if (document.all) {
		document.all[whichlayer].className = newClass;
	}
	else if (document.layers) {
		document.layers[whichLayer].className = newClass;
	}
}


function loadBox(loadWith){
	newHTML = document.getElementById(loadWith).innerHTML;
	document.getElementById('news_holder_content').innerHTML = newHTML;
	setTimeout('createScroll()',5);
	
	if(loadWith == "home_welcome_text"){
		classLayer('tab_news', 'tab_off');
		classLayer('tab_welcome', 'tab_on');
	} else {
		classLayer('tab_news', 'tab_on');
		classLayer('tab_welcome', 'tab_off');
	}
	moveScrubber("news_holder_dg","15px")
}
function createScroll(){
	news_scroll	= new ScrollObj(10,21,124,"news_holder_tk","news_holder_up","news_holder_dn","news_holder_dg","news_holder_mask","news_holder_content");
}
function initTabs(){
	//switch_updates
	document.getElementById('tab_welcome').onclick = new Function('loadBox("home_welcome_text"); classLayer("tab_news", "tab_off"); classLayer("tab_welcome", "tab_on");');
	document.getElementById('tab_news').onclick = new Function('loadBox("home_news_text"); classLayer("tab_news", "tab_on"); classLayer("tab_welcome", "tab_off");');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function launchExp(url) {
	var height = 480;
	var width = 640;
	var name = "expwindow";
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;
    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;
    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  newwin = window.open(url, name, str + ',scrollBars=no,resizable=no');
  if(parseInt(navigator.appVersion) >= 4) {
    setTimeout('newwin.focus();',250);
  }
}

function launchWindow(url, height, width) {
	var name = "expwindow";
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;
    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;
    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  newwin = window.open(url, name, str + ',scrollBars=no,resizable=no');
  if(parseInt(navigator.appVersion) >= 4) {
    setTimeout('newwin.focus();',250);
  }
}

function launchMotorSports(url, height, width) {
	var name = "motorSportswindow";
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;
    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;
    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  newwin = window.open(url, name, str + ',scrollBars=yes,resizable=no');
  if(parseInt(navigator.appVersion) >= 4) {
    setTimeout('newwin.focus();',250);
  }
}

function launchCommencement2006(url, height, width) {
	var name = "commencement2006window";
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;
    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;
    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  newwin = window.open(url, name, str + ',scrollBars=no,resizable=no');
  if(parseInt(navigator.appVersion) >= 4) {
    setTimeout('newwin.focus();',250);
  }
}

function launchReclaimTheGame(url, height, width) {
	var name = "ReclaimTheGamewindow";
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;
    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;
    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  newwin = window.open(url, name, str + ',scrollBars=no,resizable=no');
  if(parseInt(navigator.appVersion) >= 4) {
    setTimeout('newwin.focus();',250);
  }
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// My Abbey Experience Function - Rotates Student images and links to video interface

var numFeatures = 9;
var randFeature = (Math.round(Math.random()*(numFeatures)) + 1);
function showFeature(){
	document.write('<img src="/assets/images/experience/exp_tout-text'+randFeature+'.gif" name="expToutText" width="170" height="312" border="0" id="expToutText" />');
}
