// funzioni per slide
$(function(){
	// creazione
	if(document.getElementById('Tab0')!=null) {
		$('.SlideTab').tabSwitch('create',{width: 510, height: 210},function(){
			startAutoSwitch();
		});
	}
	
	// spostamento con indici
	$('.tabSelect').click(function(e){
		$('.SlideTab').tabSwitch('moveTo',{index: parseInt($(this).attr('rel'))});
		e.preventDefault(); // evita lo scroll della pagina dopo il click su #
		stopAuto();
		ForcePlay();
	});
	
	// spostamento con avanti/indietro
	$('.Nav').click(function(e){
		$('.SlideTab').tabSwitch('moveStep',{step: parseInt($(this).attr('rel'))});
		e.preventDefault();
		stopAuto();
		ForcePlay();
	});
	
	
	$('.tabType').click(function(){
		var Obj=$(this);
		$('.SlideTab').tabSwitch('destroy');
		$('.SlideTab').tabSwitch('create', {type: Obj.attr('rel'), width: 510, height: 210});
		
		// quando si cambia il tipo, resetta l'auto
		//startAutoSwitch();
	});
	
	$('.tabToggle').click(function(e){
		var Obj=$(this);
		$('.SlideTab').tabSwitch('destroy');
		$('.SlideTab').tabSwitch('create', {type:'toggle',toggle: Obj.attr('rel'), width: 510, height: 210});
		
		// quando si cambia il tipo, resetta l'auto
		//startAutoSwitch();
	});
	
	$('.tabAuto').click(function(e){
		e.preventDefault();
		startAutoSwitch();
	});
	
});

var startAutoSwitch = function(){
	$('.SlideTab').tabSwitch('toggleAuto',{interval: 8000});
	if($('.SlideTab').tabSwitch('isAuto')==true) {
		document.getElementById('ID_BTN_SLIDE_PS').src='images/btn_slide_stop.gif';
	} else {
		document.getElementById('ID_BTN_SLIDE_PS').src='images/btn_slide_play.gif';
	}
}
var stopAuto = function(){
	$('.SlideTab').tabSwitch('stopAuto', {interval: 1000});
}
var ForcePlay = function() {
	document.getElementById('ID_BTN_SLIDE_PS').src='images/btn_slide_play.gif';
}

// le immagini delle slide partono display none, poi su onLoad si visualizzano, per evitare disturbi nel caricamento
function ShowSlide() {
	i=0;
	while((m=document.getElementById('Tab'+i))!=null) {
		m.style.display='inline';
		i++;
	}
}