
var interval = 3;       // delay between rotating images (in seconds)
var random_display = 1; // 0 = sequential, 1 = random
interval *= 1000;

var image_index = 0;
image_list = new Array();
image_list[image_index++] = new imageItem("Images/slide1.jpg");
image_list[image_index++] = new imageItem("Images/slide2.jpg");
image_list[image_index++] = new imageItem("Images/slide3.jpg");
image_list[image_index++] = new imageItem("Images/slide4.jpg");
image_list[image_index++] = new imageItem("Images/slide5.jpg");
image_list[image_index++] = new imageItem("Images/slide6.jpg");
image_list[image_index++] = new imageItem("Images/slide7.jpg");
image_list[image_index++] = new imageItem("Images/slide8.jpg");
image_list[image_index++] = new imageItem("Images/slide9.jpg");

var number_of_image = image_list.length;

var print_icon;
var empty_icon;


function init()
{
  if (parseInt(navigator.appVersion)>3)
  {
    if (navigator.appName.indexOf("Microsoft") != -1)
    {
        document.getElementById('MainDiv').style.height = document.body.offsetHeight;
    }
    else
    {
      document.getElementById('MainDiv').style.height = window.innerHeight;
    }
  }

  print_icon = new Image();
  print_icon.src="Images/print.gif";
  empty_icon = new Image();
  empty_icon.src="Images/empty.gif";

  rotateImage('rImage');
  loadDiv('menus/daily.html','daily');
  CheckForSpecialMenu();
}

function rollover(link)
{
  document.body.style.cursor = 'pointer';
  document.getElementById(link).style.fontWeight = 'bold';
  document.getElementById(link).style.backgroundColor = '#FFFFFF';
  document.getElementById(link).style.color = '#003619';
}

function menurollover(link,icon)
{
  rollover(link);
  document.getElementById(icon).src=print_icon.src;
  document.getElementById(icon).alt='Printer Friendly Menu';
}

function rollout(link)
{

  document.body.style.cursor = 'default';
  document.getElementById(link).style.fontWeight = 'normal';
  document.getElementById(link).style.backgroundColor = '#003619';
  document.getElementById(link).style.color = '#FFFFFF';
}
function menurollout(link,icon)
{

  rollout(link);
  document.getElementById(icon).src=empty_icon.src;
  document.getElementById(icon).alt='';
}

function imageItem(image_location)
{
  this.image_item = new Image();
  this.image_item.src = image_location;
}

function get_ImageItemLocation(imageObj)
{
  return(imageObj.image_item.src);
}

function generate(x, y)
{
  var range = y - x + 1;
  return Math.floor(Math.random() * range) + x;
}

function getNextImage()
{
  if (random_display)
  {
    image_index = generate(0, number_of_image-1);
  }
  else
  {
    image_index = (image_index+1) % number_of_image;
  }
  
  var new_image = get_ImageItemLocation(image_list[image_index]);
  return(new_image);
}

function rotateImage(place)
{
  if (document[place] != undefined)
  {
    var new_image = getNextImage();
    document[place].src = new_image;
    var recur_call = "rotateImage('"+place+"')";
    setTimeout(recur_call, interval);
  }
}

function loadDiv(url, target)
{
  if (window.XMLHttpRequest)
  {
    req = new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }

  if (req != undefined)
  {
    var urlFixed;
    if (url.indexOf("?") == -1)
    {
      urlFixed= url +"?randomjunkparam=" + Math.random();
    }
    else
    {
      urlFixed= url +"&randomjunkparam=" + Math.random();
    }

    req.onreadystatechange = function() {DisplayContent(urlFixed, target);};
    req.open("GET", urlFixed, true);
    req.send("");
  }
}  

function DisplayContent(url, target)
{
  //if req is "loaded"
  if (req.readyState == 4) 
  { 
    //if "OK"
    if (req.status == 200)
    { 
      document.getElementById(target).innerHTML = req.responseText;
    }
    else
    {
      document.getElementById(target).innerHTML='<table width="100%"><tr><td align="center">Check back soon for our daily specials</td></tr></table>';
    }
  }
}

function CheckForSpecialMenu()
{
  if (window.XMLHttpRequest)
  {
    easter    = new XMLHttpRequest();
    mother    = new XMLHttpRequest();
    father    = new XMLHttpRequest();
    xmas      = new XMLHttpRequest();
    newyear   = new XMLHttpRequest();
    valentine = new XMLHttpRequest();
    restweek  = new XMLHttpRequest();
    prixfixe  = new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {
    easter    = new ActiveXObject("Microsoft.XMLHTTP");
    mother    = new ActiveXObject("Microsoft.XMLHTTP");
    father    = new ActiveXObject("Microsoft.XMLHTTP");
    xmas      = new ActiveXObject("Microsoft.XMLHTTP");
    newyear   = new ActiveXObject("Microsoft.XMLHTTP");
    valentine = new ActiveXObject("Microsoft.XMLHTTP");
    restweek  = new ActiveXObject("Microsoft.XMLHTTP");
    prixfixe  = new ActiveXObject("Microsoft.XMLHTTP");
}

  if (easter != undefined)
  {
    easter.onreadystatechange = function() {SpecialMenu(); };
    easter.open("GET", "http://www.pepmill.com/menus/easter.htm"+"?randomjunkparam=" + Math.random(), true);
    easter.send("");
  }
  if (mother != undefined)
  {
    mother.onreadystatechange = function() {SpecialMenu(); };
    mother.open("GET", "http://www.pepmill.com/menus/mothersday.htm"+"?randomjunkparam=" + Math.random(), true);
    mother.send("");
  }
  if (father != undefined)
  {
    father.onreadystatechange = function() {SpecialMenu(); };
    father.open("GET", "http://www.pepmill.com/menus/dadsday.htm"+"?randomjunkparam=" + Math.random(), true);
    father.send("");
  }
  if (xmas != undefined)
  {
    xmas.onreadystatechange = function() {SpecialMenu(); };
    xmas.open("GET", "http://www.pepmill.com/menus/xmas.htm"+"?randomjunkparam=" + Math.random(), true);
    xmas.send("");
  }
  if (newyear != undefined)
  {
    newyear.onreadystatechange = function() {SpecialMenu(); };
    newyear.open("GET", "http://www.pepmill.com/menus/nye.htm"+"?randomjunkparam=" + Math.random(), true);
    newyear.send("");
  }
  if (valentine != undefined)
  {
    valentine.onreadystatechange = function() {SpecialMenu(); };
    valentine.open("GET", "http://www.pepmill.com/menus/val.htm"+"?randomjunkparam=" + Math.random(), true);
    valentine.send("");
  }
  if (restweek != undefined)
  {
    restweek.onreadystatechange = function () { SpecialMenu(); };
    restweek.open("GET", "http://www.pepmill.com/menus/restweek.htm" + "?randomjunkparam=" + Math.random(), true);
    restweek.send("");
  }
  if (prixfixe != undefined)
  {
    prixfixe.onreadystatechange = function () { SpecialMenu(); };
    prixfixe.open("GET", "http://www.pepmill.com/menus/prixfixe.htm" + "?randomjunkparam=" + Math.random(), true);
    prixfixe.send("");
  }
}


function SpecialMenu()
{
 
  if (easter.readyState == 4) 
  { 
    if (easter.status == 200)
    {
      GetHolidayName('http://www.pepmill.com/Holiday/easter.htm');
    }
  }
  if (mother.readyState == 4) 
  { 
    if (mother.status == 200)
    {
      GetHolidayName('http://www.pepmill.com/Holiday/mothersday.htm');
    }
  }
  if (father.readyState == 4) 
  { 
    if (father.status == 200)
    {
      GetHolidayName('http://www.pepmill.com/Holiday/dadsday.htm');
    }
  }
  if (xmas.readyState == 4) 
  { 
    if (xmas.status == 200)
    {
      GetHolidayName('http://www.pepmill.com/Holiday/xmas.htm');
    }
  }
  if (newyear.readyState == 4) 
  { 
    if (newyear.status == 200)
    {
      GetHolidayName('http://www.pepmill.com/Holiday/newyear.htm');
    }
  }
  if (valentine.readyState == 4) 
  { 
    if (valentine.status == 200)
    {
      GetHolidayName('http://www.pepmill.com/Holiday/val.htm');
    }
  }
  if (restweek.readyState == 4) 
  { 
    if (restweek.status == 200)
    { 
      GetSpecialName('http://www.pepmill.com/Holiday/restweek.htm');
    }
  }
  if (prixfixe.readyState == 4)
  {
    if (prixfixe.status == 200)
    {
      GetSpecialName('http://www.pepmill.com/Holiday/prixfixe.htm');
    }
  }
}

function GetHolidayName(url) {
    if (window.XMLHttpRequest) {
        HolName = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        HolName = new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (HolName != undefined) {
        HolName.onreadystatechange = function () { ShowHolidayName(); };
        HolName.open("GET", url, true);
        HolName.send("");
    }
}

function ShowHolidayName() {
    //if req is "loaded"
    if (HolName.readyState == 4) {
        //if "OK"
        if (HolName.status == 200) {
            document.getElementById('rowHoliday').innerHTML = HolName.responseText;
        }
    }
}
function GetSpecialName(url) {
    if (window.XMLHttpRequest) {
        SpecName = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        SpecName = new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (SpecName != undefined) {
        SpecName.onreadystatechange = function () { ShowSpecialName(); };
        SpecName.open("GET", url, true);
        SpecName.send("");
    }
}

function ShowSpecialName() {
    //if req is "loaded"
    if (SpecName.readyState == 4) {
        //if "OK"
        if (SpecName.status == 200) {
            document.getElementById('rowSpecial').innerHTML = SpecName.responseText;
        }
    }
}

