// DO NOT MODIFY THIS FILE.
// DO NOT MODIFY THIS FILE.
// DO NOT MODIFY THIS FILE.
// DO NOT MODIFY THIS FILE.

// The configuration is in banner_config.js
// The configuration is in banner_config.js
// The configuration is in banner_config.js
// The configuration is in banner_config.js

// Last Updated: 4/13/2011
// Author: Wes Hays (wes@lsreno.com)

/******* GLOBAL VARIABLES *******/
// var rotation_delay = 3000; // 3000 milliseconds, so 3 second delay

// Keeps track of the timer id so we can stop the timer.
var last_timer_id = 0;

// Tracks what slide we are currently on.  Arrays are indexed starting
// at 0 (zero), so we will initialize current_slide at -1 and use that
// to mean we have not started displaying the slides yet.
var current_slide = -1;

// //  Path to banner images directory.  Must have ending slash.
// var banner_image_path = './';


// // EXAMPLE
// // var banner_images = [ ['acts29.jpg', '', ''],                              // positions 0, so x = 0
// //                       ['joinus.jpg', 'http://www.lsreno.com', 'same'],     // positions 1, so x = 1
// //                       ['lskids.jpg', 'http://www.cnn.com', 'new'],         // positions 2, ....
// //                       ['ss_m_promo_web.jpg', '', ''],                      // positions 3, ....
// //                       ['twitter.jpg', 'http://www.godaddy.com', 'new'] ];  // positions 4, ....
// //
// //  The third parameter is how the link responds to a click.
// //  "new" opens the link in a new window.
// //  "same", opens the link in same window.  THIS IS THE DEFAULT.
// 
// var banner_images = [ ['easter.jpg', 'http://bit.ly/g2UcmA', 'new'],                           
//                       ['joinus.jpg', 'http://www.livingstonesreno.com/worshipgatherings.html', 'same'],  
//                       ['intern.jpg', 'http://www.livingstonesreno.com/intern.html','same'],   
//                       ['lskids.jpg', '', ''],
// 					     ['twitter.jpg', 'http://twitter.com/livingstones', 'new'] ]; 
/********************************/



// This will be called once the entire page has been loaded.
$(document).ready(function(){
  update_banner();
  preload_images();
  start_banner_rotation();
});



function start_banner_rotation() {
  last_timer_id = setInterval("update_banner()", rotation_delay);  // start the timer
}
                   
                     
function update_banner() {  
  current_slide = current_slide + 1;          // Advance to the next image
  if(current_slide >= banner_images.length) { // If we passed the last image 
    current_slide = 0;                        // Then start over at the first image.
  }
  
  $("#banner").css("background-image", "url(" + banner_image_path + banner_images[current_slide][0] + ")" );  
  
  set_banner_link(current_slide);
  
  show_numbers();
}


function go_to_slide(num) {
  clearTimeout( last_timer_id );     // Stop the timer
  current_slide = num
  $("#banner").css("background-image", "url(" + banner_image_path + banner_images[num][0] + ")" );  
  set_banner_link(current_slide);
  show_numbers();
}


function show_numbers() {
  var number_links = '';
  for(i=0; i<banner_images.length; i++) {
    link_num = i+1;
    css_cls = (current_slide == i) ? 'banner_link_active' : '';
    number_links += '<a href="#" onclick="go_to_slide(' + i +');return false;" class="' + css_cls + '">' + link_num + '</a>';
  }
  $("#numbers").html(number_links);  
}

function set_banner_link(num) {
  $('#banner').removeClass('banner_link_hand');
  $("#banner").unbind('click');
  if(banner_images[num][1] != '') {
	$('#banner').addClass('banner_link_hand');
    $('#banner').click(function() { go_to_banner_link(banner_images[num][1], banner_images[num][2]); });
  }
}

function go_to_banner_link(lnk, wnd) {
  if (wnd == 'new') {
    window.open(lnk);	
  } else {
	window.location = lnk;  
  }
}

function preload_images() {
  var image_array = [];
  for(i=0; i<banner_images.length; i++) { image_array[i] = banner_image_path + banner_images[i][0]; }
  $(image_array).each(function(){
    (new Image()).src = this;
  });
}

