function adjustImage(){
	var larghezza_browser=window.getWidth();
	larghezza_browser=larghezza_browser+50;
	//alert($('img_sfondo').getSize().size.x);
	if($('img_sfondo').getSize().size.x<larghezza_browser){
	//	alert($('img_sfondo').getSize().size.x);
	//	alert(larghezza_browser);
		$('img_sfondo').style.width=larghezza_browser+'px';
	}
}

var indici_immagine=new Array();
var start_slideshow;
var stop_slideshow;

window.addEvent('avvia_slideshow',function(){
//---------------------------------------------------------
if(HB_DEBUG) alert('avvia_slideshow');

HB_ARRAY_GALLERY.each(function(element){
	if(element!=undefined){
		indici_immagine.push(element[2]);
	}
});

////////////////////////////////////////////////////////////////////////////////////////
//
// PRELOAD DELLE IMMAGINI

// funzione generica che aggiusta la dimensione dell'immagine di sfondo nel caso in cui tale immagine
// sia pił stretta dello schermo


////////////////////////////////////////////////////////////////////////////////
// OGGETTO PER LA GALLERY E LO SLIDESHOW

var slideShowObject = new Class({
initialize: function(){

// TELECOMANDO
	this.fxController=new Fx.Styles('etichetta_slideshow', {
		duration: 600,
		wait: false,
		transition: Fx.Transitions.Expo.easeOut
	});

	this.controller='NO';
	this.active=(HB_ARRAY_GALLERY.length>1)?true:false;
}
});

// METODI
slideShowObject.implement({
	setNext: function(){
		HB_GALLERY_LOCK=true;
		if(HB_GALLERY_SELECTED==HB_ARRAY_GALLERY.length-1){
			HB_GALLERY_SELECTED=-1;
		}
		HB_GALLERY_SELECTED++;
		//alert(HB_ARRAY_GALLERY[HB_GALLERY_SELECTED]);
		if(HB_ARRAY_GALLERY[HB_GALLERY_SELECTED]==undefined) {
			this.setNext();
		} else{
			HB_GALLERY_IMAGE=HB_ARRAY_GALLERY[HB_GALLERY_SELECTED][1];
			window.fireEvent('aggiorna_miniatura');
			window.fireEvent('new_img');
		}
		// nuovo codice
		//HB_GALLERY_IMAGE=HB_ARRAY_GALLERY[HB_GALLERY_SELECTED][1];
		//HB_GALLERY_LOCK=true;

	},

	showNext: function(){
		if(HB_SLIDESHOW_LOCK) IMMAGINI.setNext();
		// nuovo codice
		
	},

	showPrevious: function(){
		HB_SLIDESHOW_LOCK=true;
		IMMAGINI.setPrevious();
		// nuovo codice
		//window.fireEvent('new_img');
	},

	showController: function(){
		if(this.active){
			this.controller='SI';
			this.fxController.start({'top': 240});
		}
	},

	hideController: function(){
		if(this.active){
			this.controller='NO';
			this.fxController.start({'top': 260});
		}
	}

});

var IMMAGINI = new slideShowObject();

start_slideshow=function(){
	IMMAGINI.showNext();
}

window.addEvent('mostra_telecomando',function(){
//---------------------------------------------------------
if(HB_DEBUG) alert('mostra_telecomando');
	if(IMMAGINI.controller=='NO') IMMAGINI.showController();
//---------------------------------------------------------
});

/*$('chiudi_testo').addEvent('click',function(){
//---------------------------------------------------------
if(HB_DEBUG) alert('mostra_telecomando');
	IMMAGINI.showController();
//---------------------------------------------------------
});*/

$('etichetta_contenuti').addEvent('click',function(){
	if(!HB_GALLERY_LOCK) IMMAGINI.hideController();
});

$('slideshow_forward').addEvent('click',function(){
	if((!HB_SLIDESHOW_LOCK)&&(!HB_GALLERY_LOCK)){
		HB_SLIDESHOW_LOCK=true;
		IMMAGINI.showNext();
		//IMMAGINI.setNext();
	}
});

$('slideshow_stop').addEvent('click',function(){
	HB_SLIDESHOW_LOCK=false;
	//clearTimeout(HB_SLIDESHOWINTERVAL);
});


//---------------------------------------------------------
});