/*-------------------------------------------------
Link hover
-------------------------------------------------*/

document.addEvent('domready', function(){
	
	// Link hover	
$each($$('#indexlist li a h5'), function(el) {
	var original = el.getStyle('color');
	var morph = new Fx.Morph(el,{ 'duration':'500', link:'cancel' });
	el.addEvents({
		'mouseenter' : function() { morph.start({ 'color': '#900' }) },
		'mouseleave' : function() { morph.start({ 'color': original }) }
	});
});


// Insight red hover	
$each($$('div#insights a'), function(el) {
	var morph = new Fx.Morph(el,{ 'duration':'500', link:'cancel' });
	el.addEvents({
		'mouseenter' : function() { el.getChildren('img').morph({ 'opacity': 1 }); el.getChildren('span').morph({ 'opacity': 0 }); },
		'mouseleave' : function() { el.getChildren('img').morph({ 'opacity': 0.2 });el.getChildren('span').morph({ 'opacity': 1 }); }
	});
});


});



/*-------------------------------------------------
Slideshow
-------------------------------------------------*/
// http://davidwalsh.name/create-a-simple-slideshow-iii

var ACGSlideShow = new Class({
	options: {
		showDuration: 5000,
		showTOC: true,
		tocLeftIndent: 520, // 6 images 440, 4 images 420, 2 images 400
		tocWidth: 5,
		tocClass: 'toc',
		tocActiveClass: 'toc-active'
	},
	Implements: [Options,Events],
	initialize: function(container,elements,options) {
		//settings
		this.container = $(container);
		this.elements = $$(elements);
		this.currentIndex = 0;
		this.interval = '';
		if(this.options.showTOC) this.toc = [];
		
		//assign
		this.elements.each(function(el,i){
			if(this.options.showTOC) {
				this.toc.push(new Element('a',{
					text: i+1,
					href: '#',
					'class': this.options.tocClass + '' + (i == 0 ? ' ' + this.options.tocActiveClass : ''),
					events: {
						click: function(e) {
							if(e) e.stop();
							this.stop();
							this.show(i);
						}.bind(this)
					},
					styles: {
						 left: (this.options.tocLeftIndent + (i + 1) * (this.options.tocWidth + 10)) 
					}
				}).inject(this.container));
			}
			if(i > 0) el.set('opacity',0);
		},this);
		//events
		this.container.addEvents({
			mouseenter: function() { this.stop(); }.bind(this),
			mouseleave: function() { this.start(); }.bind(this)
		});

	},
	show: function(to) {
		this.elements[this.currentIndex].fade('out');
		if(this.options.showTOC) this.toc[this.currentIndex].removeClass(this.options.tocActiveClass);
		this.elements[this.currentIndex = ($defined(to) ? to : (this.currentIndex < this.elements.length - 1 ? this.currentIndex+1 : 0))].fade('in');
		if(this.options.showTOC) this.toc[this.currentIndex].addClass(this.options.tocActiveClass);
	},
	start: function() {
		this.interval = this.show.bind(this).periodical(this.options.showDuration);
	},
	stop: function() {
		$clear(this.interval);
	}
});
