// JavaScript Document
(function(jQuery) {
	var imgList = [];
	jQuery.extend({
		preload: function(imgArr, option) {
			var setting = jQuery.extend({
				init: function(loaded, total) {},
				loaded: function(img, loaded, total) {},
				loaded_all: function(loaded, total) {}
			}, option);
			var total = imgArr.length;
			var loaded = 0;
			
			setting.init(0, total);
			for(var i in imgArr) {
				imgList.push(jQuery("<img />")
					.attr("src", imgArr[i])
					.load(function() {
						loaded++;
						setting.loaded(this, loaded, total);
						if(loaded == total) {
							setting.loaded_all(loaded, total);
						}
					})
				);
			}
			
		}
	});
})(jQuery);


var immagini=new Array();

lista = new Array();

/*lista[0]='images/menu/about.jpg';
lista[1]='images/menu/about_over.jpg';
lista[2]='images/menu/live.jpg';
lista[3]='images/menu/live_over.jpg';
lista[4]='images/menu/disco.jpg';
lista[5]='images/menu/disco_over.jpg';
lista[6]='images/menu/gallery.jpg';
lista[7]='images/menu/gallery_over.jpg';
lista[8]='images/menu/guest.jpg';
lista[9]='images/menu/guest_over.jpg';
lista[10]='images/menu/home.jpg';
lista[11]='images/menu/home_over.jpg';*/
lista[0]='images/about/foto_aboutme.png';
lista[1]='images/disco/foto_discografia.png';
lista[2]='images/gallery/foto_gallery.png';
lista[3]='images/live/foto_live.png';
lista[4]='images/guest/foto_guestbook.png';
lista[5]='images/about/tribale_aboutme.png';
lista[6]='images/disco/tribale_discografia.png';
lista[7]='images/gallery/tribale_gallery.png';
lista[8]='images/live/tribale_live.png';
lista[9]='images/guest/tribale_guestbook.png';
lista[10]='images/words/foto_words.png'
lista[11]='images/words/tribali_words.png'
lista[12]='images/words/words.png'

function cambia_lingua(language){
	if (language=='uk'){
		jQuery('#testo_ita').hide('fast');
		jQuery('#testo_eng').show('slow');
	}else{
		jQuery('#testo_ita').show('slow');
		jQuery('#testo_eng').hide('fast');
	}
}

function gallery_grid() {
	this.id = 0;
	this.path_thumb = '';
	this.path_thumb_big = '';
	this.nrows = 0;
	this.ncols = 0;
	this.nextra = 0;
	this.grid = new Array();
}

var _gallery_grid = new gallery_grid();
/*function preload(lista)
{
	 
     for (cont=0;cont<lista.length;cont++)
     {
          immagini[cont]=new Image();
          immagini[cont].src = lista[cont];
     }
}*/

function menu_anim() {
jQuery(function(){
	jQuery('#tasto_home').mouseover(function(){jQuery('#tasto_home').animate({'margin-top':10},300)});
	jQuery('#tasto_home').mouseout(function(){jQuery('#tasto_home').animate({'margin-top':0},300)});
	jQuery('#tasto_about').mouseover(function(){jQuery('#tasto_about').animate({'margin-top':10},300)});
	jQuery('#tasto_about').mouseout(function(){jQuery('#tasto_about').animate({'margin-top':0},300)});
	jQuery('#tasto_live').mouseover(function(){jQuery('#tasto_live').animate({'margin-top':10},300)});
	jQuery('#tasto_live').mouseout(function(){jQuery('#tasto_live').animate({'margin-top':0},300)});
	jQuery('#tasto_guest').mouseover(function(){jQuery('#tasto_guest').animate({'margin-top':10},300)});
	jQuery('#tasto_guest').mouseout(function(){jQuery('#tasto_guest').animate({'margin-top':0},300)});
	jQuery('#tasto_gallery').mouseover(function(){jQuery('#tasto_gallery').animate({'margin-top':10},300)});
	jQuery('#tasto_gallery').mouseout(function(){jQuery('#tasto_gallery').animate({'margin-top':0},300)});
	jQuery('#tasto_disco').mouseover(function(){jQuery('#tasto_disco').animate({'margin-top':10},300)});
	jQuery('#tasto_disco').mouseout(function(){jQuery('#tasto_disco').animate({'margin-top':0},300)});
		   });	
}

function stato_reg() {
	this.user='';
	this.pass='';
	this.nome='';
	this.cognome='';
	this.email='';
	this.notifiche=false;
}

var account_reg = new stato_reg();

function album_data() {
	this.id = 0;
	this.titolo = '';
	this.anno = 0;
	this.info = '';
	this.canzoni = new Array();
}

var _album_data = new album_data();

function disponibilita_username(username){
	if ( username == 0 ) return;
	var ajax = GetXmlHttpObject();
	ajax.open('get','check_username.php?rnd=' + Math.random() + '&username=' + username);
	ajax.onreadystatechange = function () {
		if ( ajax.readyState === 4 ){
			if ( ajax.status === 200 ) {
				if ( ajax.responseText === 'OK') {
					jQuery('#username_input').css('border-color','green');	
					jQuery('#result_username').text('Username disponibile');
					account_reg.user = username;
				}else{
					jQuery('#username_input').css('border-color','red');
					jQuery('#result_username').text('Username occupato');
				}
			}
		}
	}
	ajax.send();
}

function check_user (username){
	if ( username.indexOf(' ') != -1 ){
		jQuery('#username_input').css('border-color','red');
		jQuery('#result_username').text('Lo username non deve contenere spazi');
		return 0;
	}
	if ( username.length < 6 ) {
		jQuery('#username_input').css('border-color','red');
		jQuery('#result_username').text('Lunghezza username minima 6 caratteri');
		return 0;
	}
	if ( check_tag(username) ){
		jQuery('#username_input').css('border-color','red');
		jQuery('#result_username').text('Username non valido');
		return 0;
	}
	return username
}

function check_tag(data) {
	if ( data.indexOf('script') != -1 ){
		return true	
	}else return false;
}

function check_pass (){
	if ( jQuery('#password_reg').val().length < 6 ){
		jQuery('#password_reg').css('border-color','red');
		jQuery('#result_password').text('Password di almeno 6 caratteri');
	}else {
		jQuery('#password_reg').css('border-color','green');
		jQuery('#result_password').text('Password Valida');
		account_reg.pass = jQuery('#password_reg').val();
	}
}

function check_mail (){
	var email_exp = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
	if ( !email_exp.test(jQuery('#email_reg').val()) ){
		jQuery('#email_reg').css('border-color','red');
		jQuery('#result_email').text('Email non valida');
	}else {
		jQuery('#email_reg').css('border-color','green');
		jQuery('#result_email').text('Email Valida');
		account_reg.email = jQuery('#email_reg').val();
	}
}

function check_reg (){
	if ( account_reg.user == '' ){
		return false;
	}
	if ( account_reg.pass == '' ){
		return false;
	}
	if ( account_reg.email == '' ){
		return false;
	}
	document.getElementById('form_reg_fields').submit();
}

function reset_form(){
	jQuery('#username_input').css('border-color','#333');
	jQuery('#password_reg').css('border-color','#333');
	jQuery('#email_reg').css('border-color','#333');
	jQuery('#result_username').text('');
	jQuery('#result_password').text('');
	jQuery('#result_email').text('');
	document.getElementById('form_reg_fields').reset();	
}

function attiva_form_ev(elem){
	switch(elem){
		case 1:
			jQuery('#content_inserisci').show("slow");
			jQuery('#content_modifica').hide("slow");
			jQuery('#content_elimina').hide("slow");
			break;
		case 2:
			jQuery('#content_inserisci').hide("slow");
			jQuery('#content_modifica').hide("slow");
			jQuery('#content_elimina').show("slow");
			break;
		case 3:
			jQuery('#content_inserisci').hide("slow");
			jQuery('#content_modifica').show("slow");
			jQuery('#content_elimina').hide("slow");
			break;
	}
}

var tmp_xml;

function estrai_album(id_album){
	if ( id_album == 0 ) return;
	var ajax = GetXmlHttpObject();
	ajax.open('get','get_album_data.php?rnd=' + Math.random() + '&id=' + id_album);
	ajax.onreadystatechange = function () {
		if ( ajax.readyState === 4 ){
			if ( ajax.status === 200 ) {
				if ( ajax.responseXML ) {
					var xml_album = ajax.responseXML;
					tmp_xml = ajax.responseXML;
					//parsing XML
					/*_album_data.id = xml_album.getElementsByTagName('id')[0].childNodes[0].textContent;
					_album_data.titolo = xml_album.getElementsByTagName('titolo')[0].childNodes[0].textContent;
					_album_data.anno = xml_album.getElementsByTagName('anno')[0].childNodes[0].textContent;
					_album_data.info = xml_album.getElementsByTagName('info')[0].childNodes[0].textContent;
					for ( i = 0 ; i < xml_album.getElementsByTagName('lista')[0].childNodes.length; i++ ){
						_album_data.canzoni[i] = new Array();
						_album_data.canzoni[i]['id_song'] = xml_album.getElementsByTagName('lista')[0].childNodes[i].childNodes[0].textContent;
						_album_data.canzoni[i]['titolo'] = xml_album.getElementsByTagName('lista')[0].childNodes[i].childNodes[1].textContent;
						_album_data.canzoni[i]['minuti'] = xml_album.getElementsByTagName('lista')[0].childNodes[i].childNodes[2].textContent;
						_album_data.canzoni[i]['secondi'] = xml_album.getElementsByTagName('lista')[0].childNodes[i].childNodes[3].textContent;
						_album_data.canzoni[i]['mp3'] = xml_album.getElementsByTagName('lista')[0].childNodes[i].childNodes[4].textContent;
					}*/
					_album_data.id = xml_album.getElementsByTagName('id')[0].childNodes[0].nodeValue;
					_album_data.titolo = xml_album.getElementsByTagName('titolo')[0].childNodes[0].nodeValue;
					_album_data.anno = xml_album.getElementsByTagName('anno')[0].childNodes[0].nodeValue;
					_album_data.info = xml_album.getElementsByTagName('info')[0].childNodes[0].nodeValue;
					for ( i = 0 ; i < xml_album.getElementsByTagName('lista')[0].childNodes.length; i++ ){
						_album_data.canzoni[i] = new Array();
						_album_data.canzoni[i]['id_song'] = xml_album.getElementsByTagName('lista')[0].childNodes[i].childNodes[0].childNodes[0].nodeValue;
						_album_data.canzoni[i]['titolo'] = xml_album.getElementsByTagName('lista')[0].childNodes[i].childNodes[1].childNodes[0].nodeValue;
						_album_data.canzoni[i]['minuti'] = xml_album.getElementsByTagName('lista')[0].childNodes[i].childNodes[2].childNodes[0].nodeValue;
						_album_data.canzoni[i]['secondi'] = xml_album.getElementsByTagName('lista')[0].childNodes[i].childNodes[3].childNodes[0].nodeValue;
						if ( xml_album.getElementsByTagName('lista')[0].childNodes[i].childNodes[4].childNodes[0] == null )
							_album_data.canzoni[i]['mp3'] = '';
						else
							_album_data.canzoni[i]['mp3'] = xml_album.getElementsByTagName('lista')[0].childNodes[i].childNodes[4].childNodes[0].nodeValue;
					}
					aggiorna_album();
				}
			}
		}
	}
	ajax.send();
}


/*function GetXmlHttpObject()
 { 
 var objXMLHttp=null;
 if (window.XMLHttpRequest)
  {
  objXMLHttp=new XMLHttpRequest();
  }
 else if (window.ActiveXObject)
  {
  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 return objXMLHttp;
 }*/
 // function to create an XMLHttpClient in a cross-browser manner
function GetXmlHttpObject() {
	var xmlhttp;
	try {
 	// Mozilla / Safari / IE7
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
 // IE
	var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP' );
	var success = false;
	for (var i=0;i < XMLHTTP_IDS.length && !success; i++) {
		try {
			xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
			success = true;
		} catch (e) {}
	}
	if (!success) {
		throw new Error('Unable to create XMLHttpRequest.');
	}
	}
	return xmlhttp;
}
 
//funzione ad hoc per aggiornare i campi dell'album html
function aggiorna_album(transizione){
	if (transizione == true){
	//TRANSIZIONE DINAMICA ATTIVA
	html_info = '<span class="titolo_album">' + _album_data.titolo + '-' + _album_data.anno + '</span><br />';
	html_info += _album_data.info;
	jQuery('#album_info').css('display','none');
	//$('#album_demo').css('display','none');
	jQuery('#album_img').css('display','none').html('<img src="images/disco/albums/' + _album_data.id + '.jpg" />').fadeIn('fast',function(){jQuery('#wheretobuy').html('Acquista nel WEB');jQuery('#reviews').html('Recensioni nel WEB');});
	jQuery('#album_img').css('border-color','#CCC').css('border-width','1px').css('border-style','solid');
	html_demo = '<div style="position:absolute;margin-top:0px;margin-left:0px" id="player"></div>';
	
	html_demo += '<div style="display:none;position:absolute;margin-top:0px;width:inherit" id="prima"><div id="song1" style="position:absolute;margin-top:0px;margin-left:20px;"';
	if ( _album_data.canzoni[0]['mp3'] != '' ) {
		html_demo += ' onclick="play_stop(' + 1 + ')"><img id="icona1" src="images/disco/play_on.png" style="margin-bottom:0px;" width="15" />&nbsp;';
	}else{
		html_demo +='><img src="images/disco/play_off.png" id="icona1" style="margin-bottom:0px;" width="15" />&nbsp;';
	}
	html_demo += _album_data.canzoni[0]['titolo'] + '</div></div>';
	for ( i=1 ; i<_album_data.canzoni.length; i++ ){
		html_demo += '<div style="display:none;position:absolute;margin-top:' + i*15 +'px;width:inherit"><div id="song' + (i+1) + '" style="position:absolute;margin-top:0px;margin-left:20px;"';
		if ( _album_data.canzoni[i]['mp3'] != '' ) {
			html_demo += ' onclick="play_stop(' + (i+1) + ')"><img id="icona' + (i+1) + '" src="images/disco/play_on.png" style="margin-bottom:0px;" width="15" />&nbsp;';
		}else{
			html_demo +='><img src="images/disco/play_off.png" id="icona' + (i+1) + 'style="margin-bottom:0px;" width="15" />&nbsp;';
		}
		html_demo += _album_data.canzoni[i]['titolo'] + '</div></div>';
	}
	jQuery('#album_demo').html(html_demo);
	jQuery('#album_info').html(html_info).fadeIn('slow',function(){
		jQuery('#prima').fadeIn(100,function(){
			jQuery(this).next('div').fadeIn(100,arguments.callee);
		})
	});
	jQuery("#player").jPlayer({ready: function(){jQuery("#player").jPlayer('setFile','')}});
	for ( i=0 ; i<_album_data.canzoni.length ; i++ ){
		if ( _album_data.canzoni[i]['mp3'] != '' ) {
			jQuery("#song" + (i+1)).css('cursor','pointer');
		}
	}
	jQuery('#player').jPlayer({ready: function(){jQuery("#player").jPlayer('setFile','')}});
	jQuery('#player').jPlayer('onSoundComplete',function(){
		jQuery('#icona' + state_playing).attr('src','images/disco/play_on.png');
		jQuery("#song" + state_playing).css('color','#333').css('font-weight','normal');
													});
	}else{
	//TRANSIZIONE DINAMICA DISATTIVATA
	html_info = '<span class="titolo_album">' + _album_data.titolo + '-' + _album_data.anno + '</span><br />';
	html_info += _album_data.info;
	jQuery('#album_info');//.css('display','none');
	//$('#album_demo').css('display','none');
	jQuery('#album_img').html('<img src="images/disco/albums/' + _album_data.id + '.jpg" />');
	jQuery('#wheretobuy').html('Acquista nel WEB');
	jQuery('#reviews').html('Recensioni nel WEB');
	jQuery('#album_img').css('border-color','#CCC').css('border-width','1px').css('border-style','solid');
	html_demo = '<div style="position:absolute;margin-top:0px;margin-left:0px" id="player"></div>';
	
	html_demo += '<div style="position:absolute;margin-top:0px;width:inherit" id="prima"><div id="song1" style="position:absolute;margin-top:0px;margin-left:20px;"';
	if ( _album_data.canzoni[0]['mp3'] != '' ) {
		html_demo += ' onclick="play_stop(' + 1 + ')"><img id="icona1" src="images/disco/play_on.png" style="margin-bottom:0px;" width="15" />&nbsp;';
	}else{
		html_demo +='><img src="images/disco/play_off.png" id="icona1" style="margin-bottom:0px;" width="15" />&nbsp;';
	}
	html_demo += _album_data.canzoni[0]['titolo'] + '</div></div>';
	for ( i=1 ; i<_album_data.canzoni.length; i++ ){
		html_demo += '<div style="position:absolute;margin-top:' + i*15 +'px;width:inherit"><div id="song' + (i+1) + '" style="position:absolute;margin-top:0px;margin-left:20px;"';
		if ( _album_data.canzoni[i]['mp3'] != '' ) {
			html_demo += ' onclick="play_stop(' + (i+1) + ')"><img id="icona' + (i+1) + '" src="images/disco/play_on.png" style="margin-bottom:0px;" width="15" />&nbsp;';
		}else{
			html_demo +='><img src="images/disco/play_off.png" id="icona' + (i+1) + 'style="margin-bottom:0px;" width="15" />&nbsp;';
		}
		html_demo += _album_data.canzoni[i]['titolo'] + '</div></div>';
	}
	jQuery('#album_demo').html(html_demo);
	jQuery('#album_info').html(html_info);//.fadeIn('slow',function(){
		//jQuery('#prima').fadeIn(100,function(){
		//	jQuery(this).next('div').fadeIn(100,arguments.callee);
		//})
	//});
	jQuery("#player").jPlayer({ready: function(){jQuery("#player").jPlayer('setFile','')}});
	for ( i=0 ; i<_album_data.canzoni.length ; i++ ){
		if ( _album_data.canzoni[i]['mp3'] != '' ) {
			jQuery("#song" + (i+1)).css('cursor','pointer');
		}
	}
	jQuery('#player').jPlayer({ready: function(){jQuery("#player").jPlayer('setFile','')}});
	jQuery('#player').jPlayer('onSoundComplete',function(){
		jQuery('#icona' + state_playing).attr('src','images/disco/play_on.png');
		jQuery("#song" + state_playing).css('color','#333').css('font-weight','normal');
													});
	}
}

state_playing = -1;
state_pause = -1;

function play_stop(num) {
	//Disattivo la canzone in esecuzione e attivo la nuova; se è gia in esecuzione vado in pausa
	if ( jQuery('#player').jPlayer('getData','diag.isPlaying') ){
		if ( state_playing != num ) {
			//stacco la attuale e attivo la nuova, poi salvo lo stato di esecuzione
			jQuery("#song" + state_playing).css('color','#333').css('font-weight','normal');
			jQuery("#icona" + state_playing).attr('src','images/disco/play_on.png');
			jQuery("#player").jPlayer('stop');
			jQuery("#player").jPlayer('setFile','');
			jQuery("#song" + num).css('color','green').css('font-weight','bold');
			jQuery("#icona" + num).attr('src','images/disco/pause_on.png');
			jQuery("#player").jPlayer('setFile','musica/' + _album_data.canzoni[num-1]['mp3']);
			jQuery("#player").jPlayer('play');
			state_playing = num;
		}else{
			//si clicca sulla stessa canzone in esecuzione -> metto in pausa
			jQuery("#song" + state_playing).css('color','red').css('font-weight','bold');
			jQuery("#icona" + state_playing).attr('src','images/disco/play_on.png');
			jQuery("#player").jPlayer('pause');
			state_pause = num;
		}
	}else {
		if ( state_pause == num ) {
			//si clicca su una canzone in pausa, riattivo
			jQuery("#song" + state_playing).css('color','green').css('font-weight','bold');
			jQuery("#icona" + state_playing).attr('src','images/disco/pause_on.png');
			jQuery("#player").jPlayer('play');
			state_pause = -1;
		}else{
			//verifica di file pendenti in pausa disattivo e attivo il nuovo
			if ( state_pause != -1 ){
				jQuery("#song" + state_pause).css('color','#333').css('font-weight','normal');
				jQuery("#icona" + state_pause).attr('src','images/disco/play_on.png');
				jQuery("#player").jPlayer('stop');
				state_pause = -1;
			}
		    //non si è in esecuzione , dunque attivo tutto
			jQuery("#song" + num).css('color','green').css('font-weight','bold');
			jQuery("#icona" + num).attr('src','images/disco/pause_on.png');
			jQuery("#player").jPlayer('setFile','musica/' + _album_data.canzoni[num-1]['mp3']);
			jQuery("#player").jPlayer('play');
			state_playing = num;
		}
	}
	
}


function carica_galleria(album,transizione){
	var ajax = GetXmlHttpObject();
	ajax.open('get','get_album_grid.php?album=' + album);
	ajax.onreadystatechange = function () {
		if ( ajax.readyState === 4 ){
			if ( ajax.status === 200 ) {
				xml_grid = ajax.responseXML;
				tmp_xml = ajax.responseXML;
				_gallery_grid.id = xml_grid.getElementsByTagName('id')[0].childNodes[0].nodeValue;
				_gallery_grid.path_thumb = xml_grid.getElementsByTagName('thumb_path')[0].childNodes[0].nodeValue;
				_gallery_grid.path_thumb_big = xml_grid.getElementsByTagName('thumb_big_path')[0].childNodes[0].nodeValue;
				_gallery_grid.ncols = xml_grid.getElementsByTagName('ncols')[0].childNodes[0].nodeValue;
				_gallery_grid.nrows = xml_grid.getElementsByTagName('nrows')[0].childNodes[0].nodeValue;
				_gallery_grid.nextra = xml_grid.getElementsByTagName('nextra')[0].childNodes[0].nodeValue;
				n_elem = xml_grid.getElementsByTagName('pictures')[0].childNodes.length;
				i=0;j=0;k=0;
				for ( i = 0 ; i < _gallery_grid.nrows; i++ ){
					_gallery_grid.grid[i]=new Array();
					for ( j = 0 ; j < _gallery_grid.ncols ; j++ ){
						_gallery_grid.grid[i][j]=new Array();
						_gallery_grid.grid[i][j]['file']=xml_grid.getElementsByTagName('pictures')[0].childNodes[k].childNodes[0].childNodes[0].nodeValue;
						_gallery_grid.grid[i][j]['file_mini']=xml_grid.getElementsByTagName('pictures')[0].childNodes[k].childNodes[1].childNodes[0].nodeValue;
						_gallery_grid.grid[i][j]['didascalia']=xml_grid.getElementsByTagName('pictures')[0].childNodes[k].childNodes[2].childNodes[0].nodeValue;
						k++;
					}
				}
				_gallery_grid.grid[i]=new Array();
				for ( s=0 ; k < n_elem ; k++ ) {
					_gallery_grid.grid[i][s]=new Array();
					_gallery_grid.grid[i][s]['file']=xml_grid.getElementsByTagName('pictures')[0].childNodes[k].childNodes[0].childNodes[0].nodeValue;
					_gallery_grid.grid[i][s]['file_mini']=xml_grid.getElementsByTagName('pictures')[0].childNodes[k].childNodes[1].childNodes[0].nodeValue;
					_gallery_grid.grid[i][s]['didascalia']=xml_grid.getElementsByTagName('pictures')[0].childNodes[k].childNodes[2].childNodes[0].nodeValue;
				}
				aggiorna_gallery();
			}
		}
	}
	ajax.send();
}

old_link = 0;

function color_link(elemento){
	jQuery('#album_link_' + elemento).toggleClass('galleria_album_selezionato');
	jQuery('#album_link_' + old_link).toggleClass('galleria_album_selezionato');
	old_link = elemento;
}

function aggiorna_gallery(){
	//si scrive il codice html per la tabella.
	jQuery('#galleria_loading').removeClass('nascosto').addClass('visibile');
	jQuery('#galleria_griglia_holder').addClass('nascosto');
	html = '<table border="0" cellpadding="20" cellspacing="20" width="100%">';
	for ( i = 0 ; i < _gallery_grid.nrows ; i++ ){
		html += '<tr>';
		for ( j = 0 ; j < _gallery_grid.ncols ; j++ ){
			html += '<td>';
			html += '<a href="' + _gallery_grid.path_thumb_big + _gallery_grid.grid[i][j]['file'] + '" rel="lightbox[';
			html += _gallery_grid.id +  ']" title="' + _gallery_grid.grid[i][j]['didascalia']  + '">';
			html += '<img class="elemento_griglia" src="' + _gallery_grid.path_thumb + _gallery_grid.grid[i][j]['file_mini'] + '" width="80" /></a>';
			html += '</td>';
		}
		html += '</tr>';
	}
	if ( _gallery_grid.nextra != 0 ){
		html += '<tr>';
		for ( k = 0 ; k < _gallery_grid.nextra ; k++ ){
			html += '<td>';
			html += '<a href="' + _gallery_grid.path_thumb_big + _gallery_grid.grid[i][k]['file'] + '" rel="lightbox['
			html += _gallery_grid.id +  ']" title="' + _gallery_grid.grid[i][k]['didascalia']  + '">';
			html += '<img class="elemento_griglia" src="' + _gallery_grid.path_thumb + _gallery_grid.grid[i][k]['file_mini'] + '" width="80" /></a>'; 
			html += '</td>';
		}
		html += '<td colspan="' + (_gallery_grid.nrows - _gallery_grid.nextra) + '">&nbsp;</td>';
		html += '</tr>';
	}
	html += '</table>';
	jQuery('#galleria_griglia_holder').html(html);
	jQuery('#galleria_griglia_holder').onImagesLoad({
			 selectorCallback: function(){
				 jQuery('#galleria_griglia_holder').removeClass('nascosto').addClass('visibile');
				 jQuery('#galleria_griglia_holder').jScrollPane({scrollbarWidth:26,dragMinHeight:60,dragMaxHeight:60,scrollbarMargin:30,reinitialiseOnImageLoad: true});
				 jQuery('#galleria_loading').removeClass('visibile').addClass('nascosto');
				 }
											});
}
