var numitems;
var starting;
var lowest;
var highest;

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}


function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function startup()
{
  numitems=8;
  lowest=1;
  gethighest();
  //if (GetCookie("starting")!=null)
  //{
  //  starting = parseInt(GetCookie("starting"));
  //  if (starting > highest)
  //  {
 //     starting = 1;
 //   }
 // }
//  else
//  {
    starting = 1;
//  }
  show(starting, numitems);
}



function gethighest()
{
  for (x=1;x<=5000;x++)
  {
    if (document.getElementById('item'+x)!=null)
    {
      highest = x;
    }
    else
    {
      break;
    }
  }
}


function hidediv(id)
{
  if (document.getElementById(id))
  {
    document.getElementById(id).style.display = "none";
  }
} 

function showdiv(id)
{ 
  if (document.getElementById(id))
  {
    document.getElementById(id).style.display = "block";
  }
} 


function show(from, qty)
{
  if (highest == 0)
  {
    gethighest();
  }
  if (from >= highest)
  {
    from = 0;
  }
  if (from > 0 && from < highest)
  {
    for(x=starting;x<=starting+numitems;x++)
    {
      hidediv('item'+x);
    }
    starting = from;
    var d = new Date();
    d.setTime(d.getTime() + (60 * 60 * 1000)); 
    //SetCookie("starting", starting, d);
    var x;
    for(x=starting;x<starting+qty;x++)
    {
      showdiv('item'+x);
    }
  }
}