var swell_menu = {
	apply_hover: function(id, active_classes) {
		var menu_element = $(id);
		if ( menu_element) {
			$A($(id).childElements()).each(function(item) {
				item.observe("mouseover", function() {
					swell_menu.over(item, active_classes);
				});
				item.observe("mouseout", function() {
					swell_menu.out(item, active_classes);
				});
			});
		} else {
			throw Error('Could not set up swell.hover. id=\''+id+'\' not found');
		}
	},
	over: function(e, active_classes) {
		var siblings = $(e).siblings();
		siblings.each(function(item) {
			$A(active_classes).each(function(active_class) {
				if ( item.hasClassName(active_class) ) {
					item.toggleClassName(active_class);
					item.toggleClassName(active_class+'_swell');
				}
			});
		});
	},
	out: function(e, active_classes) {
		$A(active_classes).each(function(active_class) {
			var active_class_swell = active_class + '_swell';
			$(e).siblings().each(function(item) {
				if ( item.hasClassName(active_class_swell)  ) {
					item.toggleClassName(active_class_swell);
					item.toggleClassName(active_class);
				}
			});
		});
	}
}
/*																  *\
 * 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;
			}
		});
	}
}
/* * * * * * * * * * * * * * * * * * * * *\
 * A tiny slideshow javascript		   *
 * built on Prototype & script.aculo.us  *
 * suweller.com - mit licenced - 2009	*
 * Keep licence intact & in place		*
\* * * * * * * * * * * * * * * * * * * * */
var slideshow = {
	container: null,
	shows: null,
	contains: null,
	height: null,

	init: function(id) {
			var slides = $(id);

			if (slides) {
				slides.insert({before: '<a class=\'prev\' onclick=\'slideshow.prev("' + id + '")\'><i>prev</i></a>'});
				slides.insert({before: '<div class=\'slideshow\'></div>'});
				slides.insert({after:  '<a class=\'next\' onclick=\'slideshow.next("' + id + '")\'><i>next</i></a>'});

				slideshow.container = slides.previous();
				slideshow.container.writeAttribute('shows', 1);
				slideshow.container.writeAttribute('contains', slides.childElements().size() );
			
				slideshow.container.insert({ top: slides});
				slideshow.container.setStyle({
					position: 'relative',
					height: $(id).getStyle('height'),
					overflow:'hidden'});
			} else {
		throw new Error(id  + ' does not exist');
		}
		}, 

	slide: function(id) {
		slideshow.container	= $(id).up('.slideshow');
		slideshow.height	= Number(slideshow.container.getStyle('height').replace('px',''));
		slideshow.shows		= Number(slideshow.container.readAttribute('shows'));
		slideshow.contains	= Number(slideshow.container.readAttribute('contains'));
	},

	prev: function(id) {
		slideshow.slide(id);
		if (slideshow.shows > 1) {
			new Effect.Move($(id), {
				queue: { position: 'end', scope: 'suweller_slideshow', limit: 3 },
				duration:0.8,
				transition: Effect.Transitions.spring,
				x: 0,
				y: slideshow.height,
				mode: 'relative',
				beforeStart: function() {
					slideshow.container.writeAttribute('shows', slideshow.shows - 1);
				}
			});
		}
	},
	next: function(id) {
		slideshow.slide(id);
		if (slideshow.shows < slideshow.contains) {
			new Effect.Move($(id), {
				queue: { position: 'end', scope: 'suweller_slideshow', limit: 3 },
				duration:0.8,
				transition: Effect.Transitions.spring,
				x: 0,
				y: -slideshow.height,
				mode: 'relative',
				beforeStart: function() {
					slideshow.container.writeAttribute('shows', slideshow.shows + 1);
				}
			 });
		}
	}
}
