// JavaScript Document
var velocita=20;
var ratio=8;
var fading=Array();
var timeout=Array();
function fadeTo(obj,colore,colorefrom,forcefrom)
    {
    //document.getElementById(obj).style.background=cutHex(colorefrom)
    if (forcefrom)document.getElementById(obj).style.background=cutHex(colorefrom)
    if (fading[obj]) window.clearTimeout(timeout[obj])
    timeout[obj]=window.setTimeout("changecolor('"+obj+"','"+colore+"')",velocita)
    fading[obj]=true;
    
    }


function changecolor(obj,coloreto)
    {
    colorefrom=document.getElementById(obj).style.background
    tored=HexToR(coloreto)
    togreen=HexToG(coloreto)
    toblue=HexToB(coloreto)
    
    
    oldred=HexToR(colorefrom)
    oldgreen=HexToG(colorefrom);
    oldblue=HexToB(colorefrom)
    
    if (tored>oldred) 
        {newred=Math.round(oldred+(tored-oldred)/ratio)}  
    else
        {newred=Math.round(oldred-(oldred-tored)/ratio)}  
    if (togreen>oldgreen) 
        {newgreen=Math.round(oldgreen+(togreen-oldgreen)/ratio)}  
    else
        {newgreen=Math.round(oldgreen-(oldgreen-togreen)/ratio)}  
    if (toblue>oldblue) 
        {newblue=Math.round(oldblue+(toblue-oldblue)/ratio)}  
    else
        {newblue=Math.round(oldblue-(oldblue-toblue)/ratio)}  
 
    
    
   
    document.getElementById(obj).style.background=RGBtoHex(newred,newgreen,newblue)
    
    if ((Math.abs(tored-newred)<=10)&&(Math.abs(togreen-newgreen)<=10)&&(Math.abs(toblue-newblue)<=10))
        {
        document.getElementById(obj).style.background=RGBtoHex(tored,togreen,toblue)
        fading[obj]=false;
        }    
    else
        {
        timeout[obj]=window.setTimeout("changecolor('"+obj+"','"+coloreto+"')",velocita)}
        }

function HexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
function HexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
function HexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}
function RGBtoHex(R,G,B) {return toHex(R)+toHex(G)+toHex(B)}
function toHex(N) {
 if (N==null) return "00";
 N=parseInt(N); if (N==0 || isNaN(N)) return "00";
 N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
 return "0123456789ABCDEF".charAt((N-N%16)/16)
      + "0123456789ABCDEF".charAt(N%16);
}
function stopTimeout()
{
if (fading)
window.clearTimeout(timeout)
}
function goToURL() { //v3.0
  var i, args=goToURL.arguments; document.returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


function Ac(id)
{
if (document.getElementById(id).style.display=='none')
{
document.getElementById(id).style.display='block';
}
else
{
document.getElementById(id).style.display='none';
}
}


