

window.addEvent('domready',function() {
	//$$('div.main').fade('out');
	//$$('div.main').fadeIn(1500); 	

/*
	var splash = $$('div.incenter');
			splash.set('opacity', '0');
	var init = function()
	{
		splash.set('tween', {duration: '500'});
		splash.tween('opacity', [0.0, 1]);
	}.delay(500);
	
	var init = function()
	{
		splash.set('tween', {duration: '500'});
		splash.tween('opacity', [1.0, 0.0]);
	}.delay(3500);
	
	var main = $$('div.main');
		main.set('opacity', '0');
	var init = function()
	{
		main.set('tween', {duration: '1500'});
		main.tween('opacity', [0.0, 1]);
		show(0);
	}.delay(4000);*/
	

	
	
	var showDuration = 10000;
	var container = $('slideshow-container');
	var images = container.getElements('img');
	var tabs = $$('img.tab');
	var currentIndex = 0;
	var interval;
	var toc = [];
	var tocWidth = 20;
	var tocActive = 'toc-active';
	var last = 0;
	
	var start = function() { interval = show.periodical(showDuration); };
	var stop = function() { $clear(interval); };

	var show = function(to) {
		tabs.each(function(item, index){
    		src = tabs[last].getProperty('src');
			tabs[last].setProperty('src',src.replace('-mo',''));	
		});
		
		images[currentIndex].fade('out');
		images[currentIndex = ($defined(to) ? to : (currentIndex < images.length - 1 ? currentIndex+1 : 0))].fade('in');
		var src = tabs[currentIndex].getProperty('src');
		if(src.search('-mo') == -1)
		{
			var extension = src.substring(src.lastIndexOf('.'),src.length)
			tabs[currentIndex].setProperty('src',src.replace(extension,'-mo' + extension));	
		}
		last = currentIndex;
	};
	$$('img.tab').each(function(img,index) {
		var src = img.getProperty('src');
		var extension = src.substring(src.lastIndexOf('.'),src.length)
		img.addEvent('mouseenter', function() { 
												   img.setProperty('src',src.replace(extension,'-mo' + extension)); });
		img.addEvent('mouseleave', function() {
											if( currentIndex != index)
												img.setProperty('src',src);
												});
	});
	
	images.each(function(img,i){
		if(i > 0) { img.set('opacity',0); }
	});

	container.addEvents({
		mouseenter: function() { stop(); },
		mouseleave: function() { start(); }
	});
	$('show_0').addEvent('click', function(){
					show(0);
	});
	$('show_1').addEvent('click', function(){
					show(1);
	});
	$('show_2').addEvent('click', function(){
					show(2);
	});

	window.addEvent('load',function(){
		start();
		show(0);
	});
	

});