// Royale Windows & Conservatories
// JavaScript Include




/******************** 
 * Testimonial Code * 
 ********************/

// List of quotes to display
var Testimonials = new Array(
  'An excellent job, efficiently done.',
  'You are clearly very experienced and professional and yet also friendly and approachable.',
  'We would recommend you to everyone.',
  'We were pleasantly surprised with both the speed and at the lack of mess.',
  'Your fitters were excellent and very professional.'
);

// Pick a random starting point
var curStr = Math.round(Math.random() * (Testimonials.length -1));


// Show the quote and set up the next one
function LoopTestimonials () {
  document.getElementById('short_testimonial').innerHTML = '<a href="testimonials.php" title="This link will take you to our testimonials page">"' + Testimonials[curStr] + '"</a>';
  curStr++;
  if (curStr >= Testimonials.length) {
    curStr = 0;
  }
  setTimeout('LoopTestimonials()', 10000)
}




/**************** 
 * Gallery Code * 
 ****************/

// Slideshow images/descriptions
var SlideShow = new Array(
  new Array('img/photos/door_1.jpg', 'Light Oak Front Door'),
  new Array('img/photos/window_1.jpg', 'Light Oak Window'),
  new Array('img/photos/conservatory_1.jpg', 'White PVC Conservatory'),
  new Array('img/photos/french_door_1.jpg', 'Light Oak French Doors'),
  new Array('img/photos/conservatory_2.jpg', 'White PVC Conservatory'),
  new Array('img/photos/french_door_2.jpg', 'Light Oak French Doors')
);


var currentSlide = -1;
var TickSpeed = 5000;
var TickActive = false;
var t;


function SlideShowInit () {
  for (var i=0; i<SlideShow.length; i++) {
    var img = new Image();
    img.src = SlideShow[i][0];
    document.getElementById('SlideShow_Thumbs').innerHTML += '<a href="#" onclick="SlideShowGoTo(' + i + '); return false;"><img src="' + SlideShow[i][0] + '" id="SlideShow_Thumb_' + i + '" alt="Image ' + (i+1) + ' of ' + SlideShow.length + '" width="75" height="75"></a> ';
  }
  document.getElementById('SlideShow_Wrapper').style.display = '';
  SlideShowStart();
}


function SlideShowGoTo (x) {

  if (document.getElementById('SlideShow_Thumb_' + currentSlide)) {
    document.getElementById('SlideShow_Thumb_' + currentSlide).style.border = '';
  }

  if (isFinite(x)) {
    currentSlide = x;
  }
  else if (x == '-') {
    currentSlide--;
  }
  else if (x == '+') {
    currentSlide++;
  }
  else if (x == 'S') {
    currentSlide = 0;
  }
  else if (x == 'E') {
    currentSlide = (SlideShow.length - 1);
  }

  if (currentSlide >= SlideShow.length) {
    currentSlide = 0;
  }
  else if (currentSlide < 0) {
    currentSlide = (SlideShow.length - 1);
  }

  document.getElementById('SlideShow_Thumb_' + currentSlide).style.border = '2px solid #0B2F79';
  document.getElementById('SlideShow_Image').src = SlideShow[currentSlide][0];
  document.getElementById('SlideShow_Image').alt = SlideShow[currentSlide][1];
  document.getElementById('SlideShow_Notes').innerHTML = 'Image ' + (currentSlide+1) + ' of ' + SlideShow.length + '<br>' + SlideShow[currentSlide][1];

}

function SlideShowStart () {
  if (!TickActive) {
    TickActive = true;
    SlideShowTick();
  }
}

function SlideShowStop () {
  if (TickActive) {
    TickActive = false;
    clearTimeout(t);
  }
}


function SlideShowTick () {
  if (TickActive) {
    SlideShowGoTo('+');
    clearTimeout(t);
    t = setTimeout('SlideShowTick()', TickSpeed);
  }
}





/**************** 
 * onLoad Event * 
 ****************/

window.onload = function () {

  // Check if the Google Analytics script is loaded
  if (window.urchinTracker) {
    // Set our userid
    _uacct = "UA-1611622-1";
    // Start tracking
    urchinTracker();
  }

  if (document.getElementById('short_testimonial')) {
    LoopTestimonials();
  }

  // Check if we are on the gallery page
  if (document.getElementById('SlideShow_Wrapper')) {
    // Start the slideshow
    SlideShowInit();
  }

}




// EOF
