 
/*																  *\
 * A tiny highlight javascript built on Prototype & script.aculo.us *
 * suweller.com - mit licenced - 2009 - Keep licence intact		 *
\*																  */
var highlighter = {
	 // change highlight every x seconds
	sleep_time: 7,

	container: null,
	current: null,

	init: function(e, sleep_time) {
	highlighter.container = $(e);
	if (highlighter.container) {
			highlighter.current = highlighter.container.getElementsBySelector('.this')[0];
			if (highlighter.current) {
				highlighter.sleep_time = this.sleep_time;
				$A($(e).descendants).each(function(d) {
					hide(d);
				});
			} else {
				highlighter.current = highlighter.container.firstDescendant();
				highlighter.current.addClassName('this');
			}
			new PeriodicalExecuter(highlighter.cycle, highlighter.sleep_time);
		} else throw Error('id=\'highlighter\' not found');
	},

	cycle: function() {
		var new_hl;
		if (highlighter.current.next() == null) {
			new_hl = $(highlighter.container).firstDescendant();
		} else {
			new_hl = $(highlighter.current.next() );
		}
		new Effect.Parallel([
			new Effect.Fade( highlighter.current,	{ sync: true, duration: 1.0}),
			new Effect.Appear( new_hl,		{ sync: true, duration: 1.0}) 
		], { 
			duration: 1.0,
			delay: 0,
			afterFinish: function() {
				highlighter.current.toggleClassName('this');
				new_hl.toggleClassName('this');
				new_hl.setStyle({display: 'block'});
				highlighter.current = new_hl;
			}
		});
	}
}

