/*
 * 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 = 3 		// numero di thumb da visualizzare nel layer
	var wImgTh = 202 	// larghezza signola thumb comprensiva di margie
	var time = 300		// tempo animazione
	
	var n = 0
	var i = 0
	var stopBt = true
	var slider = new Fx.Scroll('boxTh', {duration: time, transition: Fx.Transitions.Expo.easeInOut})
	slider.set(0, 0)
	
	var a = $$('#imgTh a')
	a.each(function(item, index){
		i = index-nThumb+1
		w = ((wImgTh+5)*(index+1))+'px'

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

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

	var btRx = $$('.next')
	btRx.addEvent('click', $lambda(false))
	btRx.addEvent('click', function(){
		if (stopBt) {
			stopBt = false
			if (n<i) {							
				n++
				slider.toElement('imgTh'+n)
			} else {
				n=0
				slider.toElement('imgTh'+n)
			}
			activeBt.delay(time)
		}
	})

	var btSx = $$('.prev')
	btSx.addEvent('click', $lambda(false))
	btSx.addEvent('click', function(){
		if (stopBt) {
			stopBt = false
			if (n>0) {
				n--	
				slider.toElement('imgTh'+n)
			} else {
				n=i
				slider.toElement('imgTh'+n)
			}
			activeBt.delay(time)
		}
	})
	
	function activeBt() {
		stopBt = true
	}
	
	

}
window.addEvent('domready', mooslider)

