//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://blogs.adelphi.edu/florence/',
	'http://www.adelphi.edu/commencement/video.php'
  ),
  new Array(
  	'http://blogs.adelphi.edu/florence/',
	'http://www.adelphi.edu/commencement/video.php'
  ),
  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/'    
  ),
  new Array(
    'http://students.adelphi.edu/gettingstarted/'
  ),
new Array(
		'http://www.adelphi.edu/youngwriters/',
		'http://alumni.adelphi.edu/reunions/',
	'http://aupac.adelphi.edu'
  ),

new Array(
	'http://www.adelphi.edu/success/',
	'http://www.adelphi.edu/success/',
	'http://www.adelphi.edu/success/',
	'http://www.adelphi.edu/success/'
  )
);

//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/img.florence2011.jpg',
   'img/img.commencement2011_videos.jpg'
  ),
  new Array(    
    'img/arrow.yellow.gif',
	'img/arrow.yellow.gif'
  ),
  new Array(  	
	'img/img.parenting.jpg',
	'img/img.elc.jpg',
    'img/img.linpl.jpg'
  ),
  new Array(
	'img/arrow.teal.gif',
	'img/arrow.orange.gif',
    'img/arrow.teal.gif'
  ),
  new Array(
    'img/img.gettingstarted.jpg'
  ),
  new Array(
    'img/arrow.red.gif'
  ),
 new Array(
	'img/artsevents_hoffman2011.jpg',
	'img/alumni-reunions.gif',
	'img/img.aupac-dec.gif'
	),
 new Array(
	'img/success/0.jpg',
	'img/success/1.jpg',
	'img/success/2.jpg',
	'img/success/3.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(
	'Featured Blog: Reflections in Florence',
	'115th Commencement - Click for Videos'
  ),
  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'
  ),
  new Array(
    '>'
  ),
 new Array(  
		'Alice Hoffman Young Writers Retreat',
		'Aumni Reunions',
	'Adelphi Performing Arts'
  ),
 new Array(  
	'Aim High',
	'Change is Good',
	'Break Out of Your Shell',
	'Don\'t Fear Success'
  )
);

//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
}

