<!-- // JavaScript Document

var initContatti = function() {
  var mappa  = "map";
  var classe = "zoom"; 
  var select = "sel"
  var lista  = new Array( "images/mappa1.gif", "images/mappa2.gif", "images/mappa3.gif" );
  
  // crea l'oggetto e setta gli eventi
  var zoomCtrl = new MapControl(mappa, classe, select, lista);
}

/**
 * Classe MapControl
 *  
 * Crea un controllo per la mappa
 * Se passo l'immagine e i bottoni assegna gli 
 * eventi in modo che schiacciando il bottone
 * cambi l'immagine di zoom corrispondente.  
*/   
function MapControl(imgId,btnClass, selection,imgList) {
  // Proprietà
  this.img      = null;
  this.btns     = null;
  this.length   = 0;
  this.classSel = selection;
  this.prev     = null;
  
  this.E_length = new Error("Il numero di immagini passate non corrisponde!");
  
  this._refresh = function(trg) {
    this.img.src = trg.href;
    if (trg != this.prev){
      trg.className += " " + this.classSel;
      var exp = new RegExp("(^|\\s)" + this.classSel + "(\\s|$)");
      this.prev.className = this.prev.className.replace(exp, "$1$2"); 
      this.prev = trg;
    }
  }
  
  this._checkClass = function(str, className) {
    var pattern = new RegExp("(^|\\s)"+ className +"(\\s|$)");
    return pattern.test(str)
  }
  
  // recupero gli elementi
  this.img    = document.getElementById(imgId);
  this.btns   = getElementsByClass(btnClass);
  this.length = this.btns.length;
  
  // se i percorsi delle immagini passate non sono tanti quanti i bottoni da errore
  if (imgList.length < this.length) throw(this.E_length)
  
  // setta l'evento del bottone
  for (var i=0; i<this.length; i++) {
    var el  = this.btns[i];
    el.href = imgList[i];
    ctrl = this
    el.onclick = function() {
       ctrl._refresh(this);
       return false;
    }
    if (this._checkClass(el.className, this.classSel)) this.prev = el;
  }
}

/** Grab Elements from the DOM by className **/
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )	node = document;
	if ( tag == null )  tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


-->
