﻿//timedlinkimg.js - rotates linked images on an interval.
//Written by Kenneth G. Franqueiro.
//Tested in IE6/IE7/FF2/O9/Swift 0.2 (WebKit)

/* Changelog:
v2.1.1 [2007-06-26 16:00]:
* Added a third array for alt attribute.  This could easily
  be used for title as well if we wanted.
v2.1 [2007-06-26 15:21]:
* When a user hovers over one of the linked images, it will
  not cycle; it basically "skips beats" until the user moves
  the mouse away.
* onload functionality is now bound from within this js file.
  MAKE SURE you REMOVE onload="cyclestats();" from
  your body tag if you're upgrading from v1.
  v2 has also been retroactively edited to work this way.
* Added this nifty changelog \o/
v2 [2007-06-26 13:37]:
* The links and imgs arrays are now 2-dimensional, to allow
  having multiple rotating link/images in the same page.
  Each "inner" array represents the links/images for one display.
*/

//The elements in which these links/images will be rendered should be
//given id's "timeda0" through "timedaN" for links, and "timedimg0"
//through "timedimgN" for images, where N is one less than the total
//number of rotating link/image elements in the page
//(since 0 is the first).

//link href's. Replace these with the links you want to cycle through.
//(Remember to keep the syntax intact though.)
var links = new Array(
  new Array(  
	'http://aupac.adelphi.edu/season.php',	
	'http://blogs.adelphi.edu/',
	'http://academics.adelphi.edu/'
  ),
  new Array(	
	'http://aupac.adelphi.edu/season.php',
	'http://blogs.adelphi.edu/',
	'http://academics.adelphi.edu/'
  ),
  new Array(
	'http://www.adelphi.edu/parentinginstitute/',	
	'http://www.adelphi.edu/elc/',
	'http://www.adelphi.edu/linonprofit/'
	
  ),
  new Array(
	'http://www.adelphi.edu/parentinginstitute/',
	'http://www.adelphi.edu/elc/',
	'http://www.adelphi.edu/linonprofit/'
	
  ),
  new Array(
	'http://students.adelphi.edu/gettingstarted/',
	'http://admissions.adelphi.edu/military/',
	'http://academics.adelphi.edu/cie/'
    //'http://academics.adelphi.edu/online/',
    //'http://academics.adelphi.edu/universitycollege/'
  ),
  new Array(
    'http://students.adelphi.edu/gettingstarted/',
	'http://admissions.adelphi.edu/military/',
	'http://academics.adelphi.edu/cie/'
	//'http://academics.adelphi.edu/online/',
    //'http://academics.adelphi.edu/universitycollege/'
  ),
  new Array(
	'http://alumni.adelphi.edu/upcoming.php'
  )
);

//img src's, in corresponding order to links
//can be relative to the directory the page invoking this script
//is run from, or absolute of course.
var imgs = new Array(
  new Array(  
    'img/homepage_aupac2009.jpg',  
    'img/homepage_blogs.jpg',
    'img/homepage_bulletin.jpg'
  ),
  new Array(    
    'img/arrow.orange.gif',
    'img/arrow.red.gif',
    'img/arrow.green.gif'
  ),
  new Array(
	'img/img.parenting.jpg',
	'img/img.elc.jpg',
    'img/img.linpl.jpg'
  ),
  new Array(
	'img/arrow.teal.gif',
    'img/arrow.teal.gif',
	'img/arrow.orange.gif',
    'img/arrow.teal.gif'
  ),
  new Array(
    'img/img.gettingstarted.jpg',
	'img/homepage_military.jpg',
    'img/img.internationaled.jpg'
	//'img/img.adelphionline.jpg',
    //'img/img.unicollege.jpg'
  ),
  new Array(
	'img/arrow.red.gif',
	'img/arrow.green2.gif',
	'img/arrow.red.gif'
    //'img/arrow.green.gif',
    //'img/arrow.blue.gif'
  ),
  new Array(
	'img/artsevents_coach2009.jpg'
  )
);

//alt attributes for images, again in corresponding order to the above.
//This could easily be used for setting the title attribute as well,
//if we wanted to.
var alts = new Array(
  new Array(
	'AUPAC Season Schedule',	
	'AU Blogs',
	'Undergraduate and Graduate Bulletins'
  ),
  new Array(
	'>',
	'>',
	'>'
  ),
  new Array(
	'Institute for Parenting',
	'Alice Brown Early Learning Center',
	'Long Island Center for Nonprofit Leadership'
  ),
  new Array(
        '>',
    '>',
    '>',
    '>'
  ),
  new Array(
	'Getting Started at AU: Info for New Students',
	'Military and Enlisted Students',
	'Center for International Education'
	//'Adelphi Online',
    //'Adult Academic Programs in University College'
  ),
  new Array(
    '>',
     '>',
	'>'
	//'>',
    //'>'
  ),
  new Array(  
	'COACH events'
  )
);

//interval for the timer to run, **in milliseconds**
var interval = 5000;

//You probably don't need to edit below this line. =)
var curr = new Array(); //array tracking currently displayed items
var stop = -1; //this will be set >=0 when user hovers over an item

function init() {
  for (var i = 0; i < links.length; i++) {
    curr.push(0); //init curr element
    //set up onmouseover/out events for a's.
    var a = document.getElementById('timeda' + i);
    if (!a) return; //bail out - html isn't set up properly!
    a.onmouseover = setstop;
    a.onmouseout = resetstop;
  }
  cyclestuff(); //start cycling.
}
window.onload = init;

//function for setting the stop variable.
function setstop(e) {
  if (!e) e = window.event;
  if (!e) {
    return;
  }
  var t;
  if (e.target) t = e.target;
  else if (e.srcElement) t = e.srcElement;
  if (t.nodeType == 3) // defeat Safari bug
    t = t.parentNode;
  if (!t) {
    return;
  }
  stop = parseInt(t.id.substr(t.id.length - 1));
}

//function for resetting the stop variable.
function resetstop(e) { stop = -1; }

//function that cycles the images.
function cyclestuff() {
  for (var i = 0; i < links.length; i++) {
    if (i == stop) continue; //don't cycle this one.
    var link = document.getElementById('timeda' + i);
    if (link == null) return; //error :<
    var image = document.getElementById('timedimg' + i);
    if (image == null) return; //other error :<
    link.href = links[i][curr[i]];
    image.src = imgs[i][curr[i]];
    image.alt = alts[i][curr[i]];
    curr[i] = (curr[i] + 1) % links[i].length;
  }
  setTimeout('cyclestuff();', interval); //let's do that AGAIN!! :D
}
