// horizontal slider control
function init(){
  if(document.cookie){
    cookie = document.cookie;
    if(cookie.match('bgColor=')){
      cookieVal = cookie.substr(cookie.search('bgColor=')+8,cookie.search(';'));
      if(cookieVal != -1){ 
        cookieVal = cookieVal.slice(0,6);
        document.body.style.backgroundColor = '#'+cookieVal;
        setBlend(cookieVal.slice(0,2));
        slider.setValue(parseInt(cookieVal.slice(0,2),16)*-1);
      }  
    }
  }
}

function changeColor(val){        
  var out;
  var bild;
  var name;
  
  endDate = new Date();
  days = endDate.getTime() + (7 * 24 * 60 * 60 * 1000);
  endDate.setTime(days);
  res = (Math.ceil(val)*(-1)).toString(16);  
  setBlend(res);
  res = res.concat(res).concat(res);
  document.body.style.backgroundColor = '#'+res;
  document.cookie = 'bgColor='+res+'; expires='+endDate.toGMTString(); 
}
  
function setBlend(res){
  out=parseInt(res,16);
  bild = (Math.floor((out+5) / 9))-2;
  name = (bild - 26) * 13;
  res = res.concat(res).concat(res);
  document.getElementById('blend').style.backgroundColor = '#'+res;
  document.getElementById('edge').style.backgroundPosition = name +'px 50%';
}

