// array of location hours
var locations = [];

// absolute positioned div for hours table
var hours;

// elements for location data
var lName;
var sundayOpen;
var sundayClose;
var mondayOpen;
var mondayClose;
var tuesdayOpen;
var tuesdayClose;
var wednesdayOpen;
var wednesdayClose;
var thursdayOpen;
var thursdayClose;
var fridayOpen;
var fridayClose;
var saturdayOpen;
var saturdayClose;

function showHours(locationNo) {
  // make sure we have the hours div
  if (!hours) {
    hours = getElm('locationHours');
  }
  
  hours.style.display = 'block';
  facade.positionElmPercent(hours, 50, 50);
  hours.style.visibility = 'visible';

  // set the location name
  if (!lName) {
    lName = getElm('locationName');
  }
  lName.innerHTML = locations[locationNo]['name'];
  
  // set the daily hours
  if (!sundayOpen || !sundayClose) {
    sundayOpen = getElm('sundayOpen');
    sundayClose = getElm('sundayClose');
  }
  sundayOpen.innerHTML = locations[locationNo]['hours'][0]['open'];
  sundayClose.innerHTML = locations[locationNo]['hours'][0]['close'];
  
  if (!mondayOpen || !mondayClose) {
    mondayOpen = getElm('mondayOpen');
    mondayClose = getElm('mondayClose');
  }
  mondayOpen.innerHTML = locations[locationNo]['hours'][1]['open'];
  mondayClose.innerHTML = locations[locationNo]['hours'][1]['close'];
  
  if (!tuesdayOpen || !tuesdayClose) {
    tuesdayOpen = getElm('tuesdayOpen');
    tuesdayClose = getElm('tuesdayClose');
  }
  tuesdayOpen.innerHTML = locations[locationNo]['hours'][2]['open'];
  tuesdayClose.innerHTML = locations[locationNo]['hours'][2]['close'];
  
  if (!wednesdayOpen || !wednesdayClose) {
    wednesdayOpen = getElm('wednesdayOpen');
    wednesdayClose = getElm('wednesdayClose');
  }
  wednesdayOpen.innerHTML = locations[locationNo]['hours'][3]['open'];
  wednesdayClose.innerHTML = locations[locationNo]['hours'][3]['close'];
  
  if (!thursdayOpen || !thursdayClose) {
    thursdayOpen = getElm('thursdayOpen');
    thursdayClose = getElm('thursdayClose');
  }
  thursdayOpen.innerHTML = locations[locationNo]['hours'][4]['open'];
  thursdayClose.innerHTML = locations[locationNo]['hours'][4]['close'];
  
  if (!fridayOpen || !fridayClose) {
    fridayOpen = getElm('fridayOpen');
    fridayClose = getElm('fridayClose');
  }
  fridayOpen.innerHTML = locations[locationNo]['hours'][5]['open'];
  fridayClose.innerHTML = locations[locationNo]['hours'][5]['close'];
  
  if (!saturdayOpen || !saturdayClose) {
    saturdayOpen = getElm('saturdayOpen');
    saturdayClose = getElm('saturdayClose');
  }
  saturdayOpen.innerHTML = locations[locationNo]['hours'][6]['open'];
  saturdayClose.innerHTML = locations[locationNo]['hours'][6]['close'];
}

function closeHours() {
  try {
    hours.style.display = 'none';
    hours.style.visibility = 'hidden';
  } catch (e) {
    alert('Your web browser doesn\'t support the JavaScript necessary to view this page. Please upgrade your browser.');
  }
}

function getElm(elmId) {
  var elm = false;
  
  if (document.getElementById) {
    elm = document.getElementById(elmId);
  }
  
  return elm;
}