var leftphotos = new Array(
  new Image(),
  new Image(),
  new Image(),
  new Image()
)
var middlephotos = new Array(
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image()
)
var rightphotos = new Array(
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image()
);
var nextposition = 'left';
var homephotocounter = new Array('1','1','1');



function disableMenuLinks() {
  var links = document.getElementById('navMenu').getElementsByTagName('a');
  for (var i=0;i<links.length;i++) {
    links[i].href = 'javascript: void nothing();';
  }
}

function nothing(){}

function home_setup() {
  
  for (var i=0;i<leftphotos.length;i++) {
    leftphotos[i].src = 'images/home_photos/left/home'+ (i+1) +'.jpg';
  }
  for (var i=0;i<middlephotos.length;i++) {
    middlephotos[i].src = 'images/home_photos/middle/home'+ (i+1) +'.jpg';
  }
  for (var i=0;i<rightphotos.length;i++) {
    rightphotos[i].src = 'images/home_photos/right/home'+ (i+1) +'.jpg';
  }
  //setTimeout(rotate_homephoto, 1500);
  setInterval(rotate_homephoto, 3500);
}

function rotate_homephoto() {
  var img = document.getElementById('homeshot_' + nextposition);
  var photoarray, countPos, next;
  switch (nextposition) {
    case 'left':
      photoarray = leftphotos;
      countPos = 0;
      next = 'middle';
      break;
    case 'middle':
      photoarray = middlephotos;
      countPos = 1;
      next = 'right';
      break;
    case 'right':
      photoarray = rightphotos;
      countPos = 2;
      next = 'left';
      break;
  }
  img.src = photoarray[homephotocounter[countPos]].src;
  if (homephotocounter[countPos] == photoarray.length -1) {
    homephotocounter[countPos] = 0;
  } else {
    homephotocounter[countPos]++;
  }
  nextposition = next;
  //setTimeout(rotate_homephoto, 1500);
}

function switchPicture(e) {
  var button = getEventSrc(e);
  document.getElementById('pic').src = button.bigpicture;
  document.getElementById('navContainer').style.backgroundImage = 'url("'+ button.navBg +'")';
}

function lightButton(e) {
  var button = getEventSrc(e);
  button.src = button.altSrc;
}

function dimButton(e) {
  var button = getEventSrc(e);
  button.src = button.defaultSrc;
}

function setupButtonFrame() {
  var buttons = document.getElementById('buttonFrame').getElementsByTagName('img');
  window.imageCache = new Array();
  for (var i=0;i<buttons.length;i++) {
    configurePictureButton(buttons[i]);
    imageCache[imageCache.length] = new Image;
    imageCache[imageCache.length -1].src = buttons[i].bigpicture;
    imageCache[imageCache.length] = new Image;
    imageCache[imageCache.length -1].src = buttons[i].altSrc;
    imageCache[imageCache.length] = new Image;
    imageCache[imageCache.length -1].src = buttons[i].navBg;
    addEvent(buttons[i], 'click', switchPicture);
    addEvent(buttons[i], 'mouseover', lightButton);
    addEvent(buttons[i], 'mouseout', dimButton);
  }
}

function configurePictureButton(button) {
  var filename = getFileNameFromURI(button.src);
  filename = filename.substring(0, filename.lastIndexOf('pb') -1);
  button.bigpicture = 'images/backgrounds/'+ filename +'.jpg';
  button.altSrc = 'images/picturebuttons/'+ filename +'-pb2.jpg';
  button.navBg = 'images/backgrounds/'+ filename +'-nav.jpg';
  button.defaultSrc = button.src;
}

function setupDirections() {
  var field = document.getElementById('start');
  field.defaultVal = field.value;
  addEvent(field, 'focus', clearField);
  addEvent(field, 'blur', restoreField);
  addEvent(document.driving.directionsButton, 'click', function(){document.driving.submit()});
}

function clearField(e) {
  var field = getEventSrc(e);
  if (field.value == field.defaultVal) {
    field.value = '';
  }
}

function restoreField(e) {
  var field = getEventSrc(e);
  if (field.value == '') {
    field.value = field.defaultVal;
  }
}

function getDirections() {
  var start = document.driving.start.value.replace(' ','+');
  window.open('http://maps.google.com/maps?f=d&hl=en&saddr='+start+'&daddr=1+Healthsouth+Pkwy+S,+Birmingham,+AL+35243&btnG=Search');
  return false;
}
