var slideshowcontainer;
window.addEvent('domready',function(){
	
	if ($('slideshow'))
		slideshow_init($('slideshow'));

},'javascript');

function slideshow_init(s) {
	images = $$('#slideshow img');
	
	slideshowcontainer = new Element('div',{id:'slideshowcontainer'}).inject(s);
	slideshowcontainer.adopt(images);
	slideshowcontainer.setStyles({
		'width' : 820 * images.length,
		'left' : 0,
		'top' : 0,
		'height' : 545,
		'position' : 'absolute'
	});
	slideshowcontainer.set('tween',{'link':'ignore', 'transition':Fx.Transitions.Expo.easeInOut});
	images.setStyle('float','left');

	prevarr = new Element('img',{ src: '../images/prevarr.png', alt: 'Immagine precedente', id: 'slideshowprevarr' }).inject(s);
	nextarr = new Element('img',{ src: '../images/nextarr.png', alt: 'Immagine successiva', id: 'slideshownextarr' }).inject(s);
	
	prevarr.setStyle('opacity',.33).addEvents({
		'mouseenter':function(){this.tween('opacity',.75);},
		'mouseleave':function(){this.tween('opacity',.33)},
		'click':slideshowprev
	});
	nextarr.setStyle('opacity',.33).addEvents({
		'mouseenter':function(){this.tween('opacity',.75);},
		'mouseleave':function(){this.tween('opacity',.33)},
		'click':slideshownext
	});
}

function slideshowprev() {
	x = slideshowcontainer.getStyle('left').toInt();
	newx = x-820;
	if(newx<820-slideshowcontainer.getStyle('width').toInt())
		newx = 0;
	slideshowcontainer.tween('left',newx);
}

function slideshownext() {
	x = slideshowcontainer.getStyle('left').toInt();
	newx = x+820;
	if(newx>0)
		newx = 820-slideshowcontainer.getStyle('width').toInt();
	slideshowcontainer.tween('left',newx);
}
