var playing=true; // value representing whether the banner is currently cycling
var transition_speed=3500; // the number of milliseconds between transitions
var image_location="images" // location where the banner images are kept (no trailing "/")
var banners=new Array("online_campaign_management.jpg","sales_visibility_into_marketing.jpg","attracting_customers.jpg","increasing_sales.jpg"); // array of the images in the banner
var current_image=1; // the current image in the array. (initially set to 1 because we want to start playing the second image in the array because the first image is already set in the html)
var banner_img; // the image node;

var preloaded_images=new Array();
for(var i=0;i<banners.length;i++){
  preloaded_images[i]=new Image();
  preloaded_images[i].src=image_location+"/"+banners[i];
}

function go_to_image(n){
  play_transition();
  current_image=n;
  clearInterval(banner_interval);
  next_image();
  banner_interval=setInterval("next_image()",transition_speed);
  return false;
}

function next_image(){
  if(playing==true){
    $(banner_img).fadeTo("500",.01,swap_image);
  }
}

function swap_image(){
  banner_img.src=preloaded_images[current_image].src;
  $(banner_img).fadeTo("500",1);
  current_image=(current_image>=banners.length-1)?0:current_image+1;
}

function play_transition(){
  playing=true;
  return false;
}
  
function stop_transition(){
  playing=false;
  return false;
}

window.onload=function(){
  banner_img=document.getElementById("banner_img"); // global variable
  banner_interval=setInterval("next_image()",transition_speed);
};
