function BnInterface(tipo) {
  function Scheda(){
	this.getCode= function(targ) {
	   return $(targ).parent().parent().prev().attr("id");
	};

/*	this.switchIco= function(targ) { 
	   if ($(targ).attr('src')==undefined) var obj = $(targ).parents('div:first').find('img');
	   else obj = targ;
	   var tmp = $(obj).attr('src');
	   if (tmp.match('-meno\.jpg$')=='-meno.jpg' || tmp.match('-meno-on\.jpg$')=='-meno-on.jpg') {
		 if (tmp.match('-meno-on\.jpg$')=='-meno-on.jpg') $(obj).attr('src','http://www.rivieradiromagna.it/html/img/icona-blocknotes-piu-on.jpg');
		 else $(obj).attr('src','http://www.rivieradiromagna.it/html/img/icona-blocknotes-piu.jpg');
	   }else {
		 if (tmp.match('-piu-on\.jpg$')=='-piu-on.jpg') $(obj).attr('src','http://www.rivieradiromagna.it/html/img/icona-blocknotes-meno-on.jpg');
		 else $(obj).attr('src','http://www.rivieradiromagna.it/html/img/icona-blocknotes-meno.jpg');
	   }
	}
*/
	this.getImg = function(targ) {
	   return $(targ).parent().parent().prev().find('img').attr('src');
	}

	this.add = function(targ) {
	  this.switchIco(targ);
	  code = this.getCode(targ);
	  if ($("#bn_elenco img[alt='"+code+"']").length==0){
		img = this.getImg(targ);
		$.post('http://www.rivieradiromagna.it/blocknotes.php',{op:'add',hotel:code});
		var block = $('#bn_elenco div.blocknotes');
		var i = 0;
		while ($(block[i]).children('img.bn_img').length) i++;
		$(block[i]).append('<img class="bn_img" src="'+img+'" alt="'+code+'" />');
	//	this.sync(code);
	   } else return false
	}

	this.rem = function(targ) {
	  this.switchIco(targ);
	  code = this.getCode(targ);
	  if ($("#bn_elenco img[alt='"+code+"']").length>0){
		$.post('http://www.rivieradiromagna.it/blocknotes.php',{op:'rem',hotel:code});
		$("#bn_elenco img[alt='"+code+"']").remove();
	//	this.sync(code);
	  } else return false;
	}

/*	this.sync = function (code) {
	   if ($('#corpo_testo #'+code).length>0) $('#corpo_testo #'+code+' .maniglia_hotel').trigger('click');
	}*/
  };

  function Pulsante(){ //funziona
	this.getCode = function (targ) {
	   return $(targ).parents("div[id]:first").attr("id");
	 }

	this.switchIco = function (targ) {
	  if ($(targ).find('a').length>0) targ = $(targ).find('a');
	  if ($(targ).hasClass('bn_add')) {$(targ).removeClass('bn_add'); $(targ).addClass('bn_remove');}
	  else {$(targ).removeClass('bn_remove'); $(targ).addClass('bn_add');}
	}

	this.getImg = function (targ) {
	   return $(targ).parents("div[id]:first").find('img:first').attr('src');
	   return $(targ).prev().attr('src');
	}

	this.add = function(targ) {
	  this.switchIco(targ);
	  code = this.getCode(targ);
	  if ($("#bn_elenco img[alt='"+code+"']").length==0){
		img = this.getImg(targ);
		$.post('http://www.rivieradiromagna.it/blocknotes.php',{op:'add',hotel:code});
		var block = $('#bn_elenco div.blocknotes');
		var i = 0;
		while ($(block[i]).children('img.bn_img').length) i++;
		$(block[i]).append('<img class="bn_img" src="'+img+'" alt="'+code+'" />');
		//this.sync(code);
	  } else return false;
	}

	this.rem = function(targ) {
	  this.switchIco(targ);
	  code = this.getCode(targ);
	  if ($("#bn_elenco img[alt='"+code+"']").length>0){
		$.post('http://www.rivieradiromagna.it/blocknotes.php',{op:'rem',hotel:code});
		$("#bn_elenco img[alt='"+code+"']").remove();
		//this.sync(code);
	  } else return false;
	}

 /*   this.sync = function (code) {
      if ($('#hotelChange').find('div#'+code).length>0) $('#hotelChange').find('.addIco:first').trigger('click');
    }*/
  }

  function Empty(){ //confronta hotel
	this.empty = function(){
	  var hotels = $('#bn_elenco .blocknotes .bn_img');
	  $.post('http://www.rivieradiromagna.it/blocknotes.php',{op:'empty'},function(){
		$.post('http://www.rivieradiromagna.it/blocknotes.php',{op:'redraw'},function(data){
		 $('#bn_elenco').empty().append(data);
		},'html');
	  });
	  this.sync(hotels);
	}

	this.partial = function(){
	  var obj = $('#notifica span.nosottolineato');
	  obj.each(function() {
		var clas = $(this).attr('class');
		var code = clas.substr(15);

		$("#bn_elenco img[alt='"+code+"']").remove();
		$.post('http://www.rivieradiromagna.it/blocknotes.php',{op:'rem',hotel:code});
		$("#blocknotes_confronta input[value='"+code+"']").parents('tr:first').remove();
		$('#notifica_close').trigger('click');
		if($("#blocknotes_confronta .mailHotel img[alt='"+code+"']").length>0)
			$("#blocknotes_confronta .mailHotel img[alt='"+code+"']").parents('.mailHotel:first').remove();
	  });
	}

	this.sync = function (hotels){
	  hotels.each(function() {
		code = $(this).attr('alt');
		if ($('#hotelChange').find('div#'+code).length>0) $('#hotelChange').find('.addIco:first').trigger('click');
		if ($('#corpo_testo #'+code).length>0) $('#corpo_testo #'+code+' .block_ico').trigger('click');
		if($("#blocknotes_confronta .mailHotel img[alt='"+code+"']").length>0)
			$("#blocknotes_confronta .mailHotel img[alt='"+code+"']").parents('.mailHotel:first').remove();

		if ($("#"+code+" .maniglia_hotel a[class='bn_remove']").length>0){
			$("#"+code+" .maniglia_hotel a[class='bn_remove']").removeClass('bn_remove');
			$("#"+code+" .maniglia_hotel a[class='']").addClass('bn_add');
		}
	  });
	}
  }

  function Info(){
    this.getCode = function(targ) {
	  return $('#info img:first').attr('alt');
	}
	
	this.sync = function (code) {
       //if ($('#hotelChange').find('div#'+code).length>0) $('#hotelChange').find('.addIco:first').trigger('click');
	   //if ($('#corpo_testo #'+code).length>0) $('#corpo_testo #'+code+' .maniglia_hotel').trigger('click');
	   if ($("#blocknotes_confronta .mailHotel img[alt='"+code+"']").length>0){
		   $("#blocknotes_confronta .mailHotel img[alt='"+code+"']").parents('.mailHotel:first').remove();
	   }
	   if ($("#"+code+" .maniglia_hotel a[class='bn_remove']").length>0){
		$("#"+code+" .maniglia_hotel a[class='bn_remove']").removeClass('bn_remove');
		$("#"+code+" .maniglia_hotel a[class='bn_remove']").addClass('bn_add');
	  }
    }
	
	this.rem = function(targ) {
	  code = this.getCode(targ);
      if ($("#bn_elenco img[alt='"+code+"']").length>0){
        $.post('http://www.rivieradiromagna.it/blocknotes.php',{op:'rem',hotel:code});
        $("#bn_elenco img[alt='"+code+"']").remove();
        this.sync(code);
      } else return false;
	  return false;
	}
  }
  
  function Confronto(){
    this.getCode = function(targ) {
       return $(targ).attr("alt");
    }
    this.rem = function(targ) {
      code = this.getCode(targ);
      $.post('http://www.rivieradiromagna.it/blocknotes.php',{op:'rem',hotel:code});
      $(targ).parents('li.mailHotel').remove();
      $("#bn_elenco img[alt='"+code+"']").remove();
	  return false;
    }
  }

  if (tipo=='scheda') this.scheda = new Scheda();
  else if (tipo=='pulsante') this.pulsante = new Pulsante();
  else if (tipo=='empty') this.empty = new Empty();
  else if (tipo=='info') this.info = new Info();
  else this.confronto = new Confronto();
}

 function Tooltip() { //funziona
   this.create = function(targ){
	 $('#info').remove();
	 if ($(targ).find('img').length>0) var img = $(targ).find('img').clone();
	 else var img = $(targ).clone();
	 $(img).attr('style','');
	 var info = document.createElement('div');
	 $(info).attr('id','info');
	 code = $(img).attr('alt');
	 if (code==undefined) code = $(targ).attr('alt');
	 if (code!=undefined) {
	   $.post('http://www.rivieradiromagna.it/getHotelTooltip.php',{idHotel:code},function(data){
		 $(img).appendTo($(info));
		 $(data).appendTo($(info));
		 //pos è l'id delle div degli hotel nel box_blocknotes.inc
		 var pos = $(targ).attr('id');
		 if (pos==undefined || pos=='') pos = $(targ).parent('div:first').attr('id');
		 var template = 1;
		 var elevation = 0;
		 if (pos>=9) elevation=1;
		 if (pos<=4) {
		   //var shift=36*pos;
		   var shift=49*pos;
		   var ieshift=parseInt(shift)-288;
		 } else if (pos<=8){
		   //var shift = (288-(36*(8-pos)))-108;
		   var shift = (400-(49*(8-pos)))-106;
		   var ieshift = parseInt(shift)-288;
		   var template=2;
		 } else if (pos>=9) {
		  // var shift=36*(pos-8);
		  //9 è il numero di hotel che ci stanno in una riga
		   var shift=49*(pos-9);
		   var ieshift=parseInt(shift)-288;
		 } else {
		   //var shift = (288-(36*(8-(pos-8))))-108;
		   var shift = (400-(49*(8-(pos-9))))-106;
		   var ieshift = parseInt(shift)-288;
		   var template=2;
		 }
		 if (pos>=10) pos-=10;
		 if (template==1){
		   $(info).children('img').css({float:'left'});
		   $(info).children('#tooltip').css({float:'right'});
		 } else {
		   $(info).children('img').css({float:'right'})
		   $(info).children('#tooltip').css({float:'left'});
		 }
		 if (elevation==1) $(info).find('img:first').css({margin:'52px 0 0 0'});
		 $(info).css('cssText',"margin-top:8px; background:#666; position:absolute; top:0px; left:"+shift+"px!important; left:"+ieshift+'px; border:2px solid #666');
		if (isIE7()) $(info).css('left',shift);
		 $(info).css('width','138px');
		 $(info).css('height','92px');
		 $('#bn_elenco').append(info);
		 $(info).find('a.drem').click(function (e){
		   var tmp = new BnInterface('info');
		   tmp.info.rem(e.target);
		 });
//	   $('#info').animate({width:'138px', height:'66px', opacity:0.9},150);
		 $(info).hover(function(){},function(){$('#info').remove();});
		 reg();
	   },'html');
	 }
   }
   this.remove = function(){
	 $('#info').remove();
   }
}
