/* <![CDATA[ */
var XMLHTTP

  function GetXmlHttpObject()
  {
    var XMLHTTP=null;
    try
    {
      // Firefox, Opera 8.0+, Safari
	  XMLHTTP=new XMLHttpRequest();
    }
    catch (e)
    { 
    // Internet Explorer
      try
	  {
	    XMLHTTP=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	  catch (e)
	  {
	    XMLHTTP=new ActiveXObject("Microsoft.XMLHTTP");
	  }
    }
    return XMLHTTP;
  }	

function isMobile()
{ 

  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
	alert ("Your browser does not support AJAX!");
	return;
  } 
  var url="/mobile.php";
  url=url+"?sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	// alert(XMLHTTP.responseText);
	 tipo = XMLHTTP.responseText;
	 tipo = tipo.split(":");

	 if(tipo[0]=='MOBILE')
	 {
		dispositivo = tipo[1];
		
		if((dispositivo.search(/Apple/i)>-1)&&(dispositivo.search(/ipad/i)==-1))
		{
		  //alert("iphone");	
		  var viewportmeta = document.querySelector('meta[name="viewport"]');
  		  if (viewportmeta) 
		  {
			//viewportmeta.content = 'width=980';
			viewportmeta.content = 'width=device-width, user-scalable=yes, initial-scale=1.0, maximum-scale=1.5, minimum-scale=1.0';
		  }
		}
		if(dispositivo.search(/ipad/i)>-1)
		{
			//alert("ipad");
		  var viewportmeta = document.querySelector('meta[name="viewport"]');
		  if (viewportmeta) 
		  {
		    viewportmeta.content = 'width=device-width, user-scalable=yes, initial-scale=1.0, maximum-scale=1.5, minimum-scale=1.0';
		  }
		}
		/*if(dispositivo.search(/android/i)>-1)
		{
		  var viewportmeta = document.querySelector('meta[name="viewport"]');
  		  if (viewportmeta) 
		  {
			viewportmeta.content = 'width=device-width, initial-scale=1.0, user-scalable=no';
		  }
		}*/
		
	 }
  } 
  else 
  {
	alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
  return(tipo[0]);
}

tipo_dispositivo = isMobile();

 function Sposta(tipo)
  {
    var posleft;
  	posleft = $("#gallcolor > .cubicolor:first-child").position();
	left = posleft.left;
	numero = ($("#gallcolor > .cubicolor").size())-1;
    width = $(".cubicolor").css('width');
	maxW = parseInt(numero)*parseInt(width);
	
    if(tipo==1)
    {
	  if(parseInt($(".cubicolor:last-child").css("left"))<0)
	  {
	    left = parseInt(left) + parseInt(width);
	    $(".cubicolor").css('left',left+'px');
	  }
	}
	else
	{
	  //alert(Math.abs(parseInt($(".cubi:last-child").css("left")))+"  "+maxW);
	  if(Math.abs(parseInt($(".cubicolor:last-child").css("left")))<maxW)
	  {
	    left = parseInt(left) - parseInt(width);
	    $(".cubicolor").css('left',left+'px');
	  }
	}
  }
  


  menu = new Array();
	menu[0]="vigneto";
	menu[1]="prodotti";
	menu[2]="produzione";
	menu[3]="masseria";
	menu[4]="certificazioni";
	menu[5]="novita";
	menu[6]="dinoi";
	menu[7]="contatti";
	
	
  testomenu = new Array();
	testomenu[1]="Vigneto_Giardino";
	testomenu[2]="Prodotti";
	testomenu[3]="Come_Produciamo";
	testomenu[4]="La_Masseria";
	testomenu[5]="Le_Certificazioni";
	testomenu[6]="News";
	testomenu[7]="Dicono_di_Noi";
	testomenu[8]="Contatti";
	
	
	
	
  quantomenu = new Array();
	quantomenu[0]=3;
	quantomenu[1]=5;
	quantomenu[2]=9;
	quantomenu[3]=4;
	quantomenu[4]=1;
	quantomenu[5]=3;
	quantomenu[6]=4;
	quantomenu[7]=4;






  function cambiacolore2(elem)
  {
    //alert(elem+"  "+elemento+"  "+jelem);
	  var elemento = document.getElementById(elem);
	  if(rgbToHex(elemento.style.color)=='#FFFFFF')
	  {
        elemento.style.color = rgbToHex('153, 153, 153');
      }
	  else
	  {
        elemento.style.color = rgbToHex('255, 255, 255');
      }
  }
  
	function SessioneMenu(id,parametro)
	{ 
	
	  XMLHTTP=GetXmlHttpObject();
	  if (XMLHTTP==null)
	  {
		alert ("Your browser does not support AJAX!");
		return;
	  } 
	  var url="ajax.asp";
	  url=url+"?id="+id+"&parametro="+parametro;
	  url=url+"&sid="+Math.random();
	 // alert(url);
	  XMLHTTP.open("GET",url,false);
	  XMLHTTP.send(null);
	  if(XMLHTTP.status == 200) 
	  {
	   // alert(XMLHTTP.responseText);
		 return(XMLHTTP.responseText);
		 
	  } 
	  else 
	  {
		alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
	  }
	}

function alertSize(quale)
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) 
  {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } 
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } 
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 /* window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );*/
  if(quale == 0)
  {
    return(myHeight);
  }
  else
  {
    return(myWidth);
  }	
}
function modHT (id) 
{
newdim = document.getElementById(id).innerHTML= CaricaContenuto('vigneto','contenuto',0);
}


function altezza()
{
  w=alertSize(1);	
   document.body.style.width=w+"px";
   document.getElementById("menusopra").style.width=w+"px";
   document.getElementById("posizionetabella").style.width=w+"px";
   
   var possotto;
   //var altezza = window.screen.height;
  // var larghezza = window.screen.width;
   var altezza = alertSize(0);
   var larghezza = alertSize(1);
   var rapporto = larghezza / altezza;
   if(altezza>larghezza)
   {
	 altezza = Math.round(larghezza/1.7777);
   }
   $('.comunicato').css('height', altezza+"px");
   tabfont = 13;
   //alert(larghezza);
	 if(larghezza<550)
	 {
		 //MINORE 550
		 tabfont = 6;
		 altcentro = Math.abs(Math.round(((altezza * 88) / 100)));
		 largcentro = Math.abs(Math.round(((larghezza * 82) / 100)));
		 
		 $(".linktende").css("fontSize",tabfont+"px");
		 $(".linktendeWHT").css("fontSize",tabfont+"px");
		 $(".linktendina").css("fontSize",tabfont+"px");
		/* $(".freccetendasu").css("background-size","20%");
		 $(".freccetendagiu").css("background-size","20%");*/
		 
		 altsopra = Math.abs(Math.round(((altezza * 10) / 100)));
		 $("#menusopra").css("height",altsopra+"px");
		 altzone = Math.abs(Math.round(((altsopra * 45) / 100)));
		 $("#topbarra").css("height",altzone+"px");
		 $("#botbarra").css("height",altzone+"px");
		 altzone = Math.abs(Math.round(((altcentro * 10) / 100)));
		 $("#midbarra").css("height",altzone+"px");
	
		 altzone = Math.abs(Math.round(((altsopra * 20) / 100)));
		 $("#posizionetabella").css("top",altzone+"px");
		 		 
		 margintoptendina = Math.abs(Math.round(((altezza * 10) / 100)));
		 $("#tendina").css("top",margintoptendina+"px");
		 altezzatendina = Math.abs(Math.round(((altezza * 89) / 100)));
		 $("#tendina").css("height",altezzatendina+"px");
	     //MINORE 550
	 }
   else
   {
     tabfont = 13;
	 altcentro = Math.abs(Math.round(((altezza * 88) / 100)));
	 largcentro = Math.abs(Math.round(((larghezza * 82) / 100)));
	 
	 /*$(".linktende").css("fontSize",tabfont+"px");
	 $(".linktendeWHT").css("fontSize",tabfont+"px");
	 $(".linktendina").css("fontSize","8px");*/
	 /*$(".freccetendasu").css("background-size","50%");
	 $(".freccetendagiu").css("background-size","50%");*/
	 altsopra = Math.abs(Math.round(((altezza * 7) / 100)));
	 $("#menusopra").css("height",altsopra+"px");
	 altzone = Math.abs(Math.round(((altsopra * 45) / 100)));
	 $("#topbarra").css("height",altzone+"px");
	 $("#botbarra").css("height",altzone+"px");
	 altzone = Math.abs(Math.round(((altcentro * 10) / 100)));
	 $("#midbarra").css("height",altzone+"px");
    // alert(altsopra);
	 

	 		 
	 margintoptendina = Math.abs(Math.round(((altezza * 3) / 100)));
	 $("#tendina").css("top",margintoptendina+"px");
     altezzatendina = Math.abs(Math.round(((altezza * 92) / 100)));
     altezzatendina = parseInt(altezzatendina) + 10;
	 $("#tendina").css("height",altezzatendina+"px");
	
   }
   SessioneMenu(3,'');
   largslide = larghezza-200;
   largslide = largslide + "px";

   //alert("altezza pagina ="+altezza+" Tendina "+altezzatendina);
   margintoptendina = Math.abs(Math.round(((altezza * 5) / 100)));
   altbarra = Math.abs(Math.round(((altezza * 7) / 100)));
   altbarra2 = Math.abs(Math.round(((altezza * 8) / 100)));
   marginsotto = altezza - altbarra2;
   possotto = altezza - altbarra;
   marginL_logo = Math.abs(Math.round(((larghezza * 4) / 100)));
   marginT_logo = Math.abs(Math.round(((altezza * 13) / 100)));
   marginT_slide = Math.abs(Math.round(((altezza * 22) / 100)));
   
   logowidth = Math.abs(Math.round(((larghezza * 20) / 100)));
   paddingtabella = Math.round((altbarra-12)/2);
   marginL_onda = Math.abs(Math.round(((larghezza * 3) / 100)));
   marginT_onda = Math.abs(Math.round(((altezza * 89) / 100)));
   ondawidth =  Math.abs(Math.round(((larghezza * 17) / 100))); 
   margintendina = altbarra;
   altcentro = Math.abs(Math.round(((altezza * 82) / 100)));
   largcentro = Math.abs(Math.round(((larghezza * 77) / 100)));
   largtendina = Math.abs(Math.round(((larghezza * 16) / 100)));
   margintopcentro = margintendina;
   marginRTend = 0 - largtendina;
   document.getElementById("tendina").style.right = marginRTend+"px";
   document.getElementById("tendina").style.width = largtendina+"px";
   
   //document.getElementById("tendina").style.marginTop = margintoptendina+"px";
   
   altcubo = Math.abs(Math.round(((possotto * 23) / 100)));
   $('.cubi').css('height', altcubo);
   $(".cubi").css("top", '0px');

   

   altmidd = parseInt(altbarra)-50;
   //alert(altmidd);
   if(altmidd<0)
     altmidd=1;
   //document.getElementById("menusopra").style.height = altbarra+"px";
   document.getElementById("midbarra").style.height = altmidd+"px";
   
   //alert("OK META' 2 ");
   
   document.getElementById("posizionetabella").style.paddingTop = paddingtabella+"px";
   document.getElementById("posizionetabella").style.fontSize= tabfont+"px";
  /* document.getElementById("barrasotto").style.height = altbarra2+"px";
   document.getElementById("barrasotto").style.top = marginsotto+"px";*/
   //alert("OK META' 3");
   document.getElementById("divlogo").style.paddingTop = marginT_logo+"px";
   document.getElementById("divlogo").style.paddingLeft = marginL_logo+"px";
   document.getElementById("logoama").style.width = logowidth+"px";
   
   document.getElementById("divonda").style.paddingTop = marginT_onda+"px";
   document.getElementById("divonda").style.paddingLeft = marginL_logo+"px";
   document.getElementById("imgonda").style.width = ondawidth+"px";
   
   document.getElementById("divimgcenter").style.width = larghezza+"px";
   document.getElementById("divimgcenter").style.height = "300px";
   document.getElementById("divimgcenter").style.marginTop = marginT_slide+"px";
   //alert("OK META' 4");
   $('#top_sx').fadeIn('fast');
   $('#top_dx').fadeIn('fast');
   $('#cboxCloseTenda').fadeIn('fast');

   $('#menusopra').fadeIn('fast');
   $('#posizionetabella').fadeIn('fast');
   $('#slideshow').fadeIn('fast');
   $('#divlogo').fadeIn('fast');
   $('#divonda').fadeIn('fast');
  //alert("OK FINE");
}


  
  function Apri(elem,id)
  {
    var aperto,elembarra;
    rightnum = parseInt($('#tendina').css('right'));
	widthnum = parseInt($('#tendina').css('width'));
    //alert("R = "+rightnum+"  W = "+widthnum);
	$(".cubi").css("top", '0px');  
	$('.freccetenda').fadeOut('fast');
	$('.freccetenda').fadeOut('fast');
    $('.linktende').css('color','#999999');
	
	//$('#pdf').fadeOut('fast');
	$("#"+elem).css('color', 'white')
	//alert(widthnum+' '+rightnum);
  
    if((parseInt(rightnum)<0)&&(Math.abs(rightnum)==widthnum))
	{
	  numvoci = $('#ruotazione_'+id+' > .cubi').length;
	  if(numvoci>3)
	  {
	    $('#frecciasu_'+id+'').fadeIn('fast');
        $('#frecciagiu_'+id+'').fadeIn('fast');
	  }
		$('#testolinktendina_'+id+'').fadeIn('slow');
		largtend = $('#tendina').width();
		alttendina = $('#tendina').height();
		//alert(alttendina);
		altcont = parseInt(alttendina)-14;  
		largcont = parseInt(largtend)-14;

		$('#cont_sx').css('height', altcont);
		
		$('#cont_dx').css('height', altcont);
		$('#cont_dx').css('width', largcont);
		$('.tende').css('width', largcont+14);
		$('.tende').css('right', '0');
		$('.tende').css('left', '0');


		altcubo = $('#ruotazione_'+id+' > .cubi').height();
		altcontruota = parseInt(numvoci) * parseInt(altcubo);
		//alert(altcontruota);
		marginRuota = Math.abs(Math.round(((alttendina * 18) / 100)));
		altRuota = Math.abs(Math.round(((alttendina * 68.5) / 100))); 
		toptasto = Math.abs(Math.round(((alttendina * 6) / 100))); 
		topfrecciasu = Math.abs(Math.round(((alttendina * 12) / 100))); 
		topfrecciagiu = Math.abs(Math.round(((alttendina * 92) / 100))); 
		//alert(topfrecciagiu);
		
		//alert(alttendina+"   "+topfrecciagiu);
		$('.tende').css('top', marginRuota);
    	$('.tende').css('height', altRuota+'px');
		cuboh = $('.cubi').css('height');
		cuboh = parseInt(cuboh);
		altmini = Math.abs(Math.round(((cuboh * 40) / 100)));
		$('.miniatura').css('height', altmini+'px');
		
		freccialeft = Math.abs(Math.round(((largtend - 65)/2)));
		$('#frecciasu_'+id+'').css('left', freccialeft);
		$('#frecciagiu_'+id+'').css('left', freccialeft);
		$('#frecciasu_'+id+'').css('top', topfrecciasu);
		$('#frecciagiu_'+id+'').css('top', topfrecciagiu);
		//alert(' Altcontruota = '+altcontruota+' altruota = '+altRuota);
		/*if(parseInt(altcontruota)>parseInt(altRuota))
		{
		   $('#frecciasu_'+id+'').fadeIn('fast');
           $('#frecciagiu_'+id+'').fadeIn('fast');
		}
		else
		{
		   $('#frecciasu_'+id+'').fadeOut('fast');
		   $('#frecciagiu_'+id+'').fadeOut('fast');
		}*/
		$('#bombato').css('height', alttendina);
		$('#bombato').css('width', largtend);
		$('#top_dx').css('width', largcont);
		tasto = '#tastotitolo_'+id+'';
		$(tasto).css('height','100px');
	    $(tasto).css('width',largcont+14);
		$(tasto).css('top',toptasto);
		$('#tasto_'+id+'').css('top',toptasto);
		$('#tasto_'+id+'').css('width',largcont+14);
   	    alttasto = Math.abs(Math.round(((alttendina * 5) / 100))); 
		//alert("Alttasto = "+alttasto);
   	    alttasto = Math.abs(Math.round(((alttendina * 4) / 100))); 
		$('#tasto_'+id+'').css('height',alttasto);
		/*$('#tasto_sx_'+id+'').css('height',alttasto);
		$('#tasto_dx_'+id+'').css('height',alttasto);
		$('#tasto_mid_'+id+'').css('height',alttasto);*/
		if(alttasto<30)
		{
		  /*toptesto = toptasto + 6;
		  alert(toptesto+"   "+toptasto);*/
		  $('#testotitolo_'+id+'').css('font-size','9px');
		  $('#testotitolo_'+id+'').css('top',7);
		}
		else
		{
		 /* toptesto = toptasto + 10;
		  alert(toptesto+"   "+toptasto);*/
		  $('#testotitolo_'+id+'').css('font-size','11px');
		  $('#testotitolo_'+id+'').css('top',8);
		}
		//alert(alttasto);
		/*$('#tastotitolo').css('height',alttitolo);*/
		
		lefttastotitolo = parseInt($("#tendina").css('width'))-parseInt($("#tastotitolo_"+id+"").css('width'));
		//lefttastotitolo	= Math.abs(Math.round((lefttastotitolo)));
		//lefttastotitolo = lefttastotitolo + 15;
		$('#tastotitolo_'+id+'').css('left',lefttastotitolo+'px');
		//alert(lefttastotitolo+"  "+largtendina+"  "+($("#tastotitolo").width()));
		largmid = largcont-100;
		//alert('#tasto_mid_'+id+'  '+largmid);
		//alert(largcont+"   "+$("#tasto_sx").width()+"  "+largmid+"  "+$("#tasto_dx").width());
		$('#tasto_mid_'+id+'').css('width',largmid);
		$('#tendina').animate({
		right: "0px"
		},'slow', function() 
		{
			$('#tastotitolo_'+id+'').fadeIn('fast');
			 $('#tasto_'+id+'').fadeIn('fast');
			//alert("ruotazione_"+id);
			$('#ruotazione_'+id).fadeIn('fast');
			//document.getElementById("testotitolo2").innerHTML = testomenu[id].toUpperCase();
		});
		SessioneMenu(1,id);
		
	}
	if(parseInt(rightnum)==0)
	{
	  
	  aperto = SessioneMenu(2,'');
	  //alert(aperto);
	  Chiudi2(elem,aperto,1);
	  if(aperto==id)
	  {
	    SessioneMenu(3,'');
	  }
	  else
	  {
		numvoci = $('#ruotazione_'+id+' > .cubi').length;
		
		if(parseInt(numvoci)>3)
		{
		  $('#frecciasu_'+id+'').fadeIn('fast');
		  $('#frecciagiu_'+id+'').fadeIn('fast');
		}
		else
		{
		  $('#frecciasu_'+id+'').fadeOut('fast');
		  $('#frecciagiu_'+id+'').fadeOut('fast');	
		}
		$('#testolinktendina_'+id+'').fadeIn('slow');
		largtend = $('#tendina').width();
		alttendina = $('#tendina').height();
		//alert(alttendina);
		altcont = parseInt(alttendina)-14;  
		largcont = parseInt(largtend)-14;

		$('#cont_sx').css('height', altcont);
		
		$('#cont_dx').css('height', altcont);
		$('#cont_dx').css('width', largcont);
		$('.tende').css('width', largcont+14);
		$('.tende').css('right', '0');
		$('.tende').css('left', '0');

		numvoci = $('#ruotazione_'+id+' > .cubi').length;
		altcubo = $('#ruotazione_'+id+' > .cubi').height();
		altcontruota = parseInt(numvoci) * parseInt(altcubo);
		//alert(altcontruota);
		marginRuota = Math.abs(Math.round(((alttendina * 18) / 100)));
		altRuota = Math.abs(Math.round(((alttendina * 68.5) / 100))); 
		toptasto = Math.abs(Math.round(((alttendina * 6) / 100))); 
		topfrecciasu = Math.abs(Math.round(((alttendina * 12) / 100))); 
		topfrecciagiu = Math.abs(Math.round(((alttendina * 92) / 100))); 
		//alert(topfrecciagiu);
		
		//alert(alttendina+"   "+topfrecciagiu);
		$('.tende').css('top', marginRuota);
    	$('.tende').css('height', altRuota+'px');
		cuboh = $('.cubi').css('height');
		cuboh = parseInt(cuboh);
		altmini = Math.abs(Math.round(((cuboh * 40) / 100)));
		$('.miniatura').css('height', altmini+'px');
		
		freccialeft = Math.abs(Math.round(((largtend - 65)/2)));
		$('#frecciasu_'+id+'').css('left', freccialeft);
		$('#frecciagiu_'+id+'').css('left', freccialeft);
		$('#frecciasu_'+id+'').css('top', topfrecciasu);
		$('#frecciagiu_'+id+'').css('top', topfrecciagiu);
		//alert(' Altcontruota = '+altcontruota+' altruota = '+altRuota);
		/*if(parseInt(altcontruota)>parseInt(altRuota))
		{
		   $('#frecciasu_'+id+'').fadeIn('fast');
           $('#frecciagiu_'+id+'').fadeIn('fast');
		}
		else
		{
		   $('#frecciasu_'+id+'').fadeOut('fast');
		   $('#frecciagiu_'+id+'').fadeOut('fast');
		}*/
		$('#bombato').css('height', alttendina);
		$('#bombato').css('width', largtend);
		$('#top_dx').css('width', largcont);
		tasto = '#tastotitolo_'+id+'';
		$(tasto).css('height','100px');
	    $(tasto).css('width',largcont+14);
		$(tasto).css('top',toptasto);
		$('#tasto_'+id+'').css('top',toptasto);
		$('#tasto_'+id+'').css('width',largcont+14);
   	    alttasto = Math.abs(Math.round(((alttendina * 5) / 100))); 
		//alert("Alttasto = "+alttasto);
   	    alttasto = Math.abs(Math.round(((alttendina * 4) / 100))); 
		$('#tasto_'+id+'').css('height',alttasto);
		/*$('#tasto_sx_'+id+'').css('height',alttasto);
		$('#tasto_dx_'+id+'').css('height',alttasto);
		$('#tasto_mid_'+id+'').css('height',alttasto);*/
		if(alttasto<30)
		{
		  /*toptesto = toptasto + 6;
		  alert(toptesto+"   "+toptasto);*/
		  $('#testotitolo_'+id+'').css('font-size','9px');
		  $('#testotitolo_'+id+'').css('top',7);
		}
		else
		{
		 /* toptesto = toptasto + 10;
		  alert(toptesto+"   "+toptasto);*/
		  $('#testotitolo_'+id+'').css('font-size','11px');
		  $('#testotitolo_'+id+'').css('top',8);
		}
		//alert(alttasto);
		/*$('#tastotitolo').css('height',alttitolo);*/
		
		lefttastotitolo = parseInt($("#tendina").css('width'))-parseInt($("#tastotitolo_"+id+"").css('width'));
		//lefttastotitolo	= Math.abs(Math.round((lefttastotitolo)));
		//lefttastotitolo = lefttastotitolo + 15;
		$('#tastotitolo_'+id+'').css('left',lefttastotitolo+'px');
		//alert(lefttastotitolo+"  "+largtendina+"  "+($("#tastotitolo").width()));
		largmid = largcont-100;
		//alert('#tasto_mid_'+id+'  '+largmid);
		//alert(largcont+"   "+$("#tasto_sx").width()+"  "+largmid+"  "+$("#tasto_dx").width());
		$('#tasto_mid_'+id+'').css('width',largmid);
		$('#tendina').animate({
		right: "0px"
		},'slow', function() 
		{
			$('#tastotitolo_'+id+'').fadeIn('fast');
			 $('#tasto_'+id+'').fadeIn('fast');
			//alert("ruotazione_"+id);
			$('#ruotazione_'+id).fadeIn('fast');
			//document.getElementById("testotitolo2").innerHTML = testomenu[id].toUpperCase();
		});
		SessioneMenu(1,id);
	  }
	  

	}
    //alert("aperto = "+aperto+" id = "+id); 
  }


  function Chiudi2(elem,id,k)
  {	  
    //alert("Chiudi");
    $('.linktende').css('color','#999999');
	$('.linktendeWHT').css('color','#999999');
   	$('.ombratasto').fadeOut('fast');

	//alert("tastotitolo_"+id);
	$('.tende').fadeOut('fast');
	x=0;
	while (x<=8)
	{
	  $('#frecciasu_'+x+'').fadeOut('fast');
	  $('#frecciagiu_'+x+'').fadeOut('fast');
	  x=x+1;
	}	
	if(id==undefined)
	{
	  x=0;
	  while (x<=8)
	  {
	    $('#testolinktendina_'+x+'').fadeOut('fast');
		x=x+1;
	  }	
	  
	}
	else
	{
		$('#testolinktendina_'+id+'').fadeOut('fast');
	}
    largtend = $('#tendina').width();
	marginRTend = 0 - largtend;

    $('#tendina').animate({
	right: marginRTend+'px'
	},'slow', function() 
	{
 	  
	});
  }

  
	function Dec2Hex (Dec) 
	{
	  var hexChars = "0123456789ABCDEF";
	  var a = Dec % 16;
	  var b = (Dec - a)/16;
	  hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
	  return hex;
	}
	
	function rgbToHex(rgb)
	{
	  if (rgb.indexOf("#") == 0)
	  {
		var rgb = rgb.toUpperCase();
		return rgb;
	  }
	
	  var str = rgb.replace(/rgb\(/,"").replace(/\)/,"");
	  var arr = str.split(", ");
	
	  var r = arr[0];
	  var g = arr[1];
	  var b = arr[2]; 
	
	  return "#" + Dec2Hex(r) + Dec2Hex(g) + Dec2Hex(b);
	}
	


  
  function getDim (id) 
  {
      document.getElementById(id).style.height="auto";
      // match box models
      if (document.all) 
	  {
        gh = document.getElementById(id).offsetHeight+10;
      }
      else 
	  {
        gh = document.getElementById(id).offsetHeight;
      }
      return (gh)
  }

function tendinascendi(x)
{
  altprimo = $(".cubi").css("height");
  altprimo = altprimo.replace("px","") * 1.02;
  alttot = Math.ceil(altprimo);
  alttendina = $("#tendina").css("height");
  alttendina = alttendina.replace("px","")
  alttendina = parseInt(alttendina) + 100; 
 // alert(alttendina);
  alttendina = Math.ceil(alttendina / 2);
  numerodiv = $("#ruotazione_<%=x%> > .cubi").length;
  altcubo = $(".cubi:first-child").css("height");
  altcubo = altcubo.replace("px","");
	  //alert(altcubo);
  distultimo = $("#ruotazione_"+x+" > .cubi:last-child").position();
	  //posleft = $('#ruotazione_ > .primo').position();
  disttop = Math.round(distultimo.top);
	 // alert(disttop+"   "+alttendina);
	  //alert("GIU Distop="+disttop+" alttendina = "+alttendina);
  if(parseInt(disttop)>parseInt(alttendina))
  {
		
		//top = $(".primo").css("top");
	distultimo = $("#ruotazione_"+x+" > .cubi:first-child").position();
	disttop = Math.round(distultimo.top);
	top5 = parseInt(disttop);
		
		//alert(distultimo);
		/*top2=top.replace("px","");
		top=parseInt(top5)-parseInt(altcubo);*/
		//alert("GIU "+top);
	top3=(parseInt(top5)-parseInt(altcubo));
	//alert(top5+"  "+altcubo+"  "+top3);
	if(parseInt(top3)>-900)
	{
	  //alert("GIU "+top);
	  $(".cubi").css("top", top3);
	}
  }
}

function tendinasali(x)
{
//  alert(x);
  ruotadiv = "#ruotazione_"+x;
  //alert(ruotadiv);
  altprimo = $(".cubi").css("height");
  altprimo = altprimo.replace("px","") * 1.02;
  alttot = Math.ceil(altprimo);
  alttendina = $("#tendina").css("height");
  alttendina = alttendina.replace("px","")
  alttendina = parseInt(alttendina) + 100; 
	 // alert(alttendina);
  alttendina = Math.ceil(alttendina / 2);
  numerodiv = $(ruotadiv+' > .primo').size();
  altcubo = $(".cubi:first-child").css("height");
  altcubo = altcubo.replace("px","");
  //alert(numerodiv);
  distultimo = $(ruotadiv+' > .cubi:first-child').position();
  //posleft = $('#ruotazione_ > .primo').position();
  top3 = ""+distultimo.top;
  //alert("SU "+top3);
  if(parseInt(top3)!=0)
  {
	top2=top3.replace("px","");
	top5=parseInt(top2)+parseInt(altcubo);
	//alert("SU "+top);
	$(".cubi").css("top", top5);
  }
}  
function Scolora()
  {
  
    $('#bookload').fadeOut(1000, function() {
      Colora();
    }); 
  }
  function Colora()
  {
	$('#bookload').fadeIn(1000, function() {
       Scolora();
    });
	
  }
function Stop()
{
	$('#bookload').stop();
}
/* ]]>*/
