function GetElement(nome){
	return document.getElementById(nome);
}

function IntRandom(hi){
	var ind = Math.floor(hi*Math.random());
	if (ind == hi) --ind;
	return ind;
}

Array.prototype.Set = function(ind){
	var foto  = GetElement('Foto');
	foto.src = this[ind][0];
	if (this[ind][2]) foto.style.width  = this[ind][2];
	if (this[ind][3]) foto.style.height = this[ind][3];
	GetElement('Legenda').innerHTML = this[ind][1];
	GetElement('Scelta').selectedIndex = ind;
	GetElement('Scelta').value = ind;
}

Array.prototype.Random = function(hi){
	this.Set(IntRandom(hi));
}

Array.prototype.Change = Array.prototype.Set;

Array.prototype.Next = function(){
	var ind = GetElement('Scelta').value;
	if (ind < this.length - 1) ++ind; else ind = 0;
	this.Set(ind);
}

Array.prototype.Prev = function(){
	var ind = GetElement('Scelta').value;
	if (ind > 0) --ind; else ind = this.length -1;
	this.Set(ind);
}

Array.prototype.MMSet = function(ind){
	var media = GetElement('Media');
	var html = '<';
	posext = this[ind][0].indexOf('.');
	var ext = this[ind][0].substr(posext+1, 7);
	if ((ext  == 'jpeg') || (ext == 'jpg') || (ext == 'png') || (ext == 'gif')) {
		html += "img src= '" + this[ind][0] +"'";
	} else if ((ext == 'wma') ||(ext == 'mp3') || (ext == 'mpg') || (ext == 'mpeg')){
		html += "embed src='" + this[ind][0] +"'";
	} else if (ext == 'YouTube') {
		sorg = 'http://www.youtube.com/v/' + this[ind][0].substr(7, 255) + '&hl=it&rel=0&fs=1&color2=0xe4a400';
		html += "embed type='application/x-shockwave-flash' src='" + sorg + "'";
	} else {
		sorg = 'http://video.google.com/googleplayer.swf?docid=' + this[ind][0].substr(6, 255) + '&amp;hl=it&amp;fs=true';
		html += "embed type='application/x-shockwave-flash' src='" + sorg + "'";
	}
	if (this[ind][2]) html += "width= " + this[ind][2] + " style='width:" + this[ind][2] + ";'";
	if (this[ind][3]) html += "height= " + this[ind][3] + " style='height:" + this[ind][3] + ";'";
	html += '>';
	media.innerHTML = html;
	GetElement('Legenda').innerHTML = this[ind][1];
	GetElement('Scelta').selectedIndex = ind;
}

Array.prototype.MMRandom = function(hi){
	this.MMSet(IntRandom(hi));
}

Array.prototype.MMNext = function(){
	var ind = GetElement('Scelta').value;
	if (ind < this.length - 1) ++ind; else ind = 0;
	this.MMSet(ind);
}

Array.prototype.MMPrev = function(){
	var ind = GetElement('Scelta').value;
	if (ind > 0) --ind; else ind = this.length -1;
	this.MMSet(ind);
}

function CambiaFoto(fname){
	GetElement('Scelta').value = fname;
	GetElement('Foto').src = fname;
}

function ChangeFoto(fname){
	CambiaFoto(fname);
}


