/*
 * mooSlider 1.0 - Javascript Image Slider with mootools 1.2
 * By Mario Zambon (http://www.urbangap.com)
 * Copyright (c) 2008 cody urbangap
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/

function mooslider() {
	
	var nThumb = 1 		// numero di thumb da visualizzare nel layer
	var wImgTh = 241 	// larghezza signola thumb comprensiva di margie
	var time = 300		// tempo animazione
	
	var n = 0
	var i = 0
	var opc = 0.3
	var stopBt = true
	var slider = new Fx.Scroll('boxCont', {duration: time, transition: Fx.Transitions.Expo.easeInOut})
	var btSx = $$('div.prev').setStyle('display', 'block')
	var btRx = $$('div.next').setStyle('display', 'block')
	
	slider.set(0, 0)
	btSx.set('opacity', opc).setStyle('cursor', 'default')
	
	
	

	
	var a = $$('#boxAll .box')
	a.each(function(item, index){
		i = index-nThumb+1
		w = ((wImgTh)*(index+1))+'px'

		var id = 'boxAll'+index
		item.setProperty('id', id)
	})

	if(i==0) {
		btRx.set('opacity', opc).setStyle('cursor', 'default')
	}

	$('boxAll').set('styles', {'width': w});				

	btRx.addEvent('click', $lambda(false))
	btRx.addEvent('click', function(){
		if (stopBt) {
			stopBt = false
			if (n<i) {							
				n++
				slider.toElement('boxAll'+n)
				btRx.set('opacity', 1).setStyle('cursor', 'pointer')
				btSx.set('opacity', 1).setStyle('cursor', 'pointer')
			} if(n==i) {
				btRx.set('opacity', opc).setStyle('cursor', 'default')
			}
			activeBt.delay(time)
		}
	})

	btSx.addEvent('click', $lambda(false))
	btSx.addEvent('click', function(){
		if (stopBt) {
			stopBt = false
			if (n>0) {
				n--	
				slider.toElement('boxAll'+n)
				btRx.set('opacity', 1).setStyle('cursor', 'pointer')
				btSx.set('opacity', 1).setStyle('cursor', 'pointer')
			} if(n==0) {
				btSx.set('opacity', opc).setStyle('cursor', 'default')
			}
			activeBt.delay(time)
		}
	})
	
	function activeBt() {
		stopBt = true
	}

}
window.addEvent('domready', mooslider)

