function init() {
  scorri();
  setInterval("sposta()", 100);
  var elenco = h('check_cont').getElementsByTagName('input');
  for (j=0; j < elenco.length; j++) {
    elenco[j].checked = false;
  }
}

function anteprima_colore() {
  var colore = h('search_color').value;
  if (colore.length == 3) {
    h('anteprima_colore').style.background = '#' + colore;
    h('anteprima_colore').style.border = '1px solid #000';
    h('no_color').style.border = '1px solid #8cd1ff';
    h('no_color').style.background = 'url(/directory/images/no_color.gif) no-repeat center center';
  }
  if (colore.length == 6) {
    h('anteprima_colore').style.background = '#' + colore;
    h('anteprima_colore').style.border = '1px solid #000';
    h('no_color').style.border = '1px solid #8cd1ff';
    h('no_color').style.background = 'url(/directory/images/no_color.gif) no-repeat center center';
  }
  if (colore.length == 0) {
    h('anteprima_colore').style.background = 'none';
    h('anteprima_colore').style.border = '1px solid #8cd1ff';
    h('no_color').style.border = '1px solid #000';
    h('no_color').style.background = '#def url(images/no_color_selected.gif) no-repeat center center';
  }
}

function sposta() {
  var elemento = h("fixed");
  var is_explorer = (navigator.userAgent.indexOf("MSIE")>=0) ? true : false;
  var left = bytefx.$position(elemento).x;
  var posTop = (is_explorer) ? document.documentElement.scrollTop + 5 : pageYOffset + 5;
  if (posTop>187) {
    bytefx.move(elemento, {x:left,y:posTop}, 10);
  }
  else {
    bytefx.move(elemento, {x:left,y:187}, 10);
  }
}

function h(el) { return document.getElementById(el); }

function toggle_check() {
  var lingua=this.id.split("_")[1];
  el = h('check_'+lingua);
  img = h('img_'+lingua);
  if (el.checked) {
    el.checked = false;
    img.style.background = "none";
  } else {
    el.checked = true;
    img.style.background = "#ccffb1";
  }
}

function createListener( ths, funzione){
	ths.metodo = function(event){
					funzione.call( ths, event);
				};
		} 

function scorri() {
  var elenco = h('check_cont').getElementsByTagName('input');
  for (j=0; j < elenco.length; j++) {
    var lang = elenco[j].value;
    
    imgSost = h('check_cont').appendChild(document.createElement("img"));
    imgSost.setAttribute("src", "/directory/lingue/"+lang+".gif");
    imgSost.setAttribute("alt", lang);
    imgSost.setAttribute("id", "img_"+lang);
  }
  for (j=0; j < elenco.length; j++) {
    elenco[j].style.position = 'absolute';
    elenco[j].style.top = '-999px';
    elenco[j].style.left = '-999px';
  }
  for (j=0; j < elenco.length; j++) {
    var lang = elenco[j].value;
    var tempobj;
    tempobj = h("img_"+lang);
    createListener( tempobj, toggle_check) ;

    if(tempobj.attachEvent)
      tempobj.attachEvent("onclick", tempobj.metodo );
    else if(tempobj.addEventListener)
      tempobj.addEventListener("click", tempobj.metodo, false);  }
}

function no_color() {
  h('search_color').value = "";
  anteprima_colore();
}
