// control.js 
//
// This file "controls" the div location and behavior using CBE (www.cross-browser.com)
// and other javascript function used throughout the site.
//

if (top.location != document.location) top.location = document.location;

document.write("<s"+"cript type='text/javascript' src='./js/cbe_core.js'></s"+"cript>");
document.write("<s"+"cript type='text/javascript' src='./js/cbe_event.js'></s"+"cript>");
document.write("<s"+"cript type='text/javascript' src='./js/cbe_slide.js'></s"+"cript>");
//document.write("<s"+"cript type='text/javascript' src='./js/cbe_util.js'></s"+"cript>");
//document.write("<s"+"cript type='text/javascript' src='./js/cbe_debug.js'></s"+"cript>");

var menuAnchor, floatingMenu, centerColumn, rightColumn, centerTitle;

//sTitle is used to get the page title used in the init() function to load or not load the 
// initImgRotation() script on pages.

var sTitle = document.title;
sTitle = sTitle.toLowerCase();

function windowOnload()
{
  //menuAnchor = document.getElementById('centerTitleImage').cbe; //using the center logo
  floatingMenu = document.getElementById('floatingMenu').cbe;
  centerTitle = document.getElementById('centerTitle').cbe;
  centerColumn = document.getElementById('centerColumn').cbe;
  rightColumn = document.getElementById('rightColumn').cbe;

  createpage();

  window.cbe.addEventListener("scroll", slidingMenuListener);
  window.cbe.addEventListener('resize', winResizeListener, false);
  
  setTimeout("init()", 0);
}

function createpage(){
  with (floatingMenu) {
	resizeTo(130,450);
	//moveTo(2, menuAnchor.pageY());
	moveTo(2,5);
	show();
  }
  with (centerTitle) {
	width(document.cbe.width() - floatingMenu.width() - 10);
	moveTo(2 + floatingMenu.width() + 3, 5);
	show();
  }
  with (centerColumn) {
	width(document.cbe.width() - floatingMenu.width() - rightColumn.width() - 10);
	moveTo(2 + floatingMenu.width() + 3, centerTitle.height() + 5);
	show();
  }
  with (rightColumn) {
	moveTo(document.cbe.width() - rightColumn.width() - 5, centerTitle.height() + 5);
	show();
  }
}

function init() {
  // Check if page should use the image rotation script
  if (sTitle.toLowerCase().indexOf('home') != -1)
		initImgRotation();
}	

function slidingMenuListener()
{
  floatingMenu.slideTo(2, 5 + document.cbe.scrollTop(), 800);
}

function winResizeListener() {
	if (is.opera || is.nav4) window.location.replace(window.location.href);
	else createpage();
}



// IMAGE ROTATOR //
/*
  This code is from Dynamic Web Coding 
  at http://www.dyn-web.com/
  Copyright 2001-3 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  Permission granted to use this code 
  as long as this entire notice is included.
*/

// arrays for images to rotate
var imgAr = new Array();
imgAr[0] = new Array("campus1_210x150.jpg","greathouse1_210x150.jpg","students1_200x150.jpg","greathouse2_210x150.jpg","outreach1_200x150.jpg");

// preload the images
if (document.images) {
	var rImg = new Array();
	for (var i=0; i<imgAr.length; i++) {
    rImg[i] = new Array();
    for (var j=0; j<imgAr[i].length; j++) {
      rImg[i][j] = new Image(); 
		  rImg[i][j].src = "images/" + imgAr[i][j];
    	// NOTE: the path to the images!
    	// change it as needed, or include path in imgAr items and remove it here.    
    }
  }
}

function initImgRotation() {
  // create rotating image objects here 
  // arguments: image name, rotation speed, array number
  new rotateImgObj('img1',4000,0);

// no need to edit code below this line!
///////////////////////////////////////////////////////////////////////////////////////
  for (var i=0; i<rotateImgObj.ar.length; i++) {
     rotateImgObj.ar[i].timer = setTimeout(rotateImgObj.ar[i].obj + ".rotate()",3000);  
  }
}

rotateImgObj.ar = new Array(); // holds all rotating image objects defined
// constructor for rotating image objects
function rotateImgObj(nm,s,num) {
  this.speed = s; this.num = num; this.ctr=0; this.timer=0;  
  this.imgObj = document.images[nm];
  this.obj = nm + "object"; eval(this.obj + "=this");
  rotateImgObj.ar[rotateImgObj.ar.length] = this;
}

rotateImgObj.prototype.rotate = rotateImg;
// controls rotation
function rotateImg() {
  if (this.ctr < rImg[this.num].length-1) this.ctr++;
  else this.ctr = 0;
  this.imgObj.src = rImg[this.num][this.ctr].src;
  this.timer = setTimeout(this.obj + ".rotate()",this.speed);
}

function WriteEmail(sEmail, sHost, sName){
  var email, emailhost, name;
  document.write("<a href=" + "mail" + "to:" + sEmail + "@" + sHost+ ">" + sName + "</a>");
}


