// JavaScript Document

var pic_show_img_array = new Array();
var pic_show_img_dir = "./uploads/images/"; 
var pic_show_rotation_speed = 5000;

// Format for all the images
//   black and white thumbnail, color thumbnail, full image, title, subtitle, target url
pic_show_img_array[0] = ["S1112C1_ThumbB&W.jpg"
                        ,"S1112C1_ThumbColor.jpg"
                        ,"S1112C1_BannerMain.jpg"
                        ,"Count Basie Orchestra", "Saturday, September 24, 2011, 7:30 p.m."
                        ,"?page=S1112C1&show_target=0"]; // set one
pic_show_img_array[1] = ["S1112C2_ThumbB&W.jpg"
                        ,"S1112C2_ThumbColor.jpg"
                        ,"S1112C2_BannerMain.jpg"
                        ,"Brooklyn Rider String Quartet"
                        ,"Saturday, October 29, 2011, 7:30 p.m."
                        ,"?page=S1112C2&show_target=1"]; // set two
pic_show_img_array[2] = ["S1112C3_ThumbB&W.jpg"
                        ,"S1112C3_ThumbColor.jpg"
                        ,"S1112C3_BannerMain.jpg"
                        ,"Tierney Sutton Band"
                        ,"Saturday, November 12, 2011, 7:30 p.m."
                        ,"?page=S1112C3&show_target=2"]; // set three
pic_show_img_array[3] = ["S1112C4_ThumbB&W.jpg"
                        ,"S1112C4_ThumbColor.jpg"
                        ,"S1112C4_BannerMain.jpg"
                        ,"Crossroads"
                        ,"Saturday, February 25, 2012, 7:30 p.m."
                        ,"?page=S1112C4&show_target=3"]; // etc...
pic_show_img_array[4] = ["S1112C5_ThumbB&W.jpg"
                        ,"S1112C5_ThumbColor.jpg"
                        ,"S1112C5_BannerMain.jpg"
                        ,"Georgia Guitar Quartet with Baritone Robert Sims"
                        ,"Saturday, March 24, 2012, 7:30 p.m."
                        ,"?page=S1112C5&show_target=4"];
pic_show_img_array[5] = ["S1112C6_ThumbB&W.jpg"
                        ,"S1112C6_ThumbColor.jpg"
                        ,"S1112C6_BannerMain.jpg"
                        ,"John Pizzarelli Quartet with Jessica Molaskey"
                        ,"Saturday, April 21, 2012, 7:30 p.m."
                        ,"?page=S1112C6&show_target=5"];

// Do not edit variables below this line

var pic_show_main_img_target = 0;
var pic_show_current_image = 0; // will be set by ?show_target= in the URL
pic_show_timer = null;


function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
                   
        var img=new Image();
       img.src= this;
    });
}



// Used to select images from the url
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

// Change the images to highlight the current selection
function picture_show_select(picture_show_selection)
{
  // Change the small images
  
  // Get locatino of the tile that should change and place our block over it
  var x = $('.hoverswitch').eq(picture_show_selection).position().left;
  var y = $('.hoverswitch').eq(picture_show_selection).position().top;
  
  
  
  $("#picture_show_color_box").fadeOut('slow', function() {
    
    $("#picture_show_color_box").css( { top: y, left: x } );
    $("#picture_show_color_box img")[0].src = image_cache["color"+picture_show_selection].src;
    //$("#picture_show_color_box img")[0].src=pic_show_img_dir+pic_show_img_array[picture_show_selection][1];
    //$("#picture_show_color_box").css("z-index: 10");
    //$("#picture_show_color_box").css("display: visible");
    $("#picture_show_color_box").fadeIn("slow");
    
    
    }); 

  
  //$('.hoverswitch').eq(picture_show_selection)[0].src=pic_show_img_dir+pic_show_img_array[picture_show_selection][1];
  
  // Change the main image
  if( pic_show_main_img_target )
  {
    $("#picture_show_main_image2").css("z-index: 1");
    $("#picture_show_main_image").css("z-index: 0");
    $("#picture_show_main_image")[0].src = image_cache["image"+picture_show_selection].src; 
    $("#picture_show_main_image").fadeIn("slow");
    $("#picture_show_main_image2").fadeOut("slow");
    $("#picture_show_main_link").attr("href",pic_show_img_array[picture_show_selection][5]);

    pic_show_main_img_target = 0;
  }
  else
  {
    $("#picture_show_main_image").css("z-index: 1");
    $("#picture_show_main_image2").css("z-index: 0");
    $("#picture_show_main_image2")[0].src = image_cache["image"+picture_show_selection].src;  
    $("#picture_show_main_image2").fadeIn("slow");
    $("#picture_show_main_image").fadeOut("slow");
    $("#picture_show_main_link2").attr("href",pic_show_img_array[picture_show_selection][5]);
    
    pic_show_main_img_target = 1;
  }
  
  // Set the titles
  $("#picture_show_title").text(pic_show_img_array[picture_show_selection][3]);
  $("#picture_show_subtitle").text(pic_show_img_array[picture_show_selection][4]);
  
  }  

// Change the images to un-highlight the current selection
function picture_show_unselect(picture_show_selection)
{
  // Change the images
  $('.hoverswitch').eq(picture_show_selection)[0].src=pic_show_img_dir+pic_show_img_array[picture_show_selection][0];
  
}

// Called by a timer function to rotate the images
function pic_rotation_timer()
{
  // De-select the current one
  picture_show_unselect(pic_show_current_image);
  
  // Rotate count
  pic_show_current_image++;
  if( pic_show_current_image == 6 )
  {
    pic_show_current_image = 0;
  }
  
  // Highlight
  picture_show_select(pic_show_current_image);
  
  // Keep going on forever
  pic_show_timer = setTimeout("pic_rotation_timer()",pic_show_rotation_speed);
}



$(document).ready(function() 
{
  // Preload images
  image_cache = {};
  for( nI = 0; nI < 6; nI++)
  {
    image_cache["bw"+nI] = new Image();
    image_cache["bw"+nI].src = pic_show_img_dir + pic_show_img_array[nI][0];
    image_cache["color"+nI] = new Image();
    image_cache["color"+nI].src = pic_show_img_dir + pic_show_img_array[nI][1];
    image_cache["image"+nI] = new Image();
    image_cache["image"+nI].src = pic_show_img_dir + pic_show_img_array[nI][2];   
  }
  
  //preload(image_cache);
  
  
  // If a selection was passed via the url, then select it now
  picture_show_selection = gup("show_target");
  
  if( picture_show_selection && picture_show_selection.length )
  {
   
    pic_show_current_image = picture_show_selection;
    picture_show_select(picture_show_selection);
  }
  
  else
  {
    pic_show_timer = setTimeout("pic_rotation_timer()",pic_show_rotation_speed);
    picture_show_select(pic_show_current_image);
    
      // Sets our hover hooks
    $('.hoverswitch').hover(function() {
    
    // Kill our timer to it doesn't disrupt the user and reset it 10 seconds into the future
    clearTimeout(pic_show_timer);
    picture_show_unselect(pic_show_current_image);
    pic_show_timer = setTimeout("pic_rotation_timer()",pic_show_rotation_speed);
    
                   
    target = $(this).attr('rel');
    $(this)[0].src=pic_show_img_dir+pic_show_img_array[target][1];

    
    
    
      }, function() {
        
    target = $(this).attr('rel');   
    $(this)[0].src=pic_show_img_dir+pic_show_img_array[target][0];    
    //$(this).attr("src", pic_show_img_dir+pic_show_img_array[target][0]);
  });
  
  }
  
  // Sets our click hooks
  $('.hoverswitch').click(function() {
    
    // Set this before we go to the next page - this will let them look at it while the next page is loading
    target = $(this).attr('rel'); 
      $("#picture_show_main_image")[0].src = pic_show_img_dir+pic_show_img_array[target][2];  
    
    // Set the titles
    $("#big_picture_area .title").text(pic_show_img_array[target][3]);
    $("#big_picture_area .subtitle").text(pic_show_img_array[target][4]);
    
    // Now go to the target url
    document.location = pic_show_img_array[target][5];
    
    return false;
  });


});
