if (typeof RVR == "undefined") RVR = {}; 

RVR.body_color = function() {
  function set_cookie(name, value) {
    document.cookie = name + '=' + value + '; path=/';
  }
  
  function get_cookie(name) {
    name = name + "=";
    var cookies = document.cookie.split(';');
    for(var i=0; i < cookies.length; i++) {
      var cookie = cookies[i];
      while (cookie.charAt(0) == ' ') {
        cookie = cookie.substring(1, cookie.length);
      }
      if (cookie.indexOf(name) == 0) {
        return cookie.substring(name.length, cookie.length);
      }
    }
    return null;
  }
  
  function find_first_in_array(array, element) {
    for(var i=0; i < array.length; i++) {
      if (array[i] == element) {
        return i;
      }
    }
    return null;
  }
  
  var colors = ['red', 'green', 'blue', 'purple'];
  var previous_color = get_cookie('color');
  if (previous_color) {
    colors.splice(find_first_in_array(colors, previous_color), 1);
  }
  var color = colors[Math.floor(Math.random() * colors.length)]
  document.body.className = color;
  set_cookie('color', color);
}

RVR.header_position = function() {
  document.getElementById('logo').style.backgroundPosition = (Math.round(Math.random() * 348) * 11) + 'px 0px';
}