Image1 = new Image(902,467);
Image1.src = '/wp-content/themes/bucha/images/bottles_blood-orange.jpg';
Image2 = new Image(902,467);
Image2.src = '/wp-content/themes/bucha/images/bottles_grapefruit-sage.jpg';
Image3 = new Image(902,467);
Image3.src = '/wp-content/themes/bucha/images/bottles_guava-mango.jpg';
Image4 = new Image(902,467);
Image4.src = '/wp-content/themes/bucha/images/bottles_masala-chai.jpg';
Image5 = new Image(902,467);
Image5.src = '/wp-content/themes/bucha/images/bottles_verbena-rose.jpg';
Image6 = new Image(902,467);
//Image6.src = '/wp-content/themes/bucha/images/bottles_kiwi-passion.jpg';
Image6.src = '/wp-content/themes/bucha/images/bottles_lemongrass-ginger.jpg';

$(document).ready(function() {
  
  $('div#triggers > a').click(function() { // click a bottle
    var triggerId = $(this).attr('id');
    var showDivId = triggerId.substring(2);
    var showDivIdNumber = triggerId.substring(4);
    if ($(this).is('.active')) { // if we're clicking the active bottle, close it
      $('div#' + showDivId).fadeOut();
      $('div#descriptions div#d_' + showDivIdNumber).fadeOut();
      $('div#' + showDivId).removeClass('current');
      $('div#descriptions div#d_' + showDivIdNumber).removeClass('dcurrent');
      $('div#triggers > a.active').removeClass('active');
      return false;
    }
    else { // if we're clicking a new bottle
      showhide(showDivIdNumber);
      return false;
    }
  });
  
  $('div#header > h1 > a, div#bottles > div.bottle > div.infoWrap > div.info > div.b_nav > a.viewAll').click(function() { // click the logo or the view all link
    $('div#bottles > div.current').fadeOut();
    $('div#bottles > div.current').removeClass('current');
    $('div#descriptions > div.dcurrent').fadeOut();
    $('div#descriptions > div.dcurrent').removeClass('dcurrent');
    $('div#triggers > a.active').removeClass('active');
    return false;
  });
  
  $('#homeContent div#b_1_nav a.prev, #homeContent div#b_2_nav a.prev, #homeContent div#b_3_nav a.prev, #homeContent div#b_4_nav a.prev, #homeContent div#b_5_nav a.prev, #homeContent div#b_6_nav a.prev').click(function() { // click the 'prev' link
    var currentBottle = $('div#bottles > div.current').attr('id').substring(2);
    currentBottle = currentBottle * 1; // convert to a number
    var targetBottle;
    if (currentBottle == 1) {
      targetBottle = 6;
    }
    else {
      targetBottle = currentBottle - 1;      
    }
    showhide(targetBottle);
    return false;
  });
  
  $('#homeContent div#b_1_nav a.next, #homeContent div#b_2_nav a.next, #homeContent div#b_3_nav a.next, #homeContent div#b_4_nav a.next, #homeContent div#b_5_nav a.next, #homeContent div#b_6_nav a.next').click(function() { // click the 'next' link
    var currentBottle = $('div#bottles > div.current').attr('id').substring(2);
    currentBottle = currentBottle * 1; // convert to a number
    var targetBottle;
    if (currentBottle == 6) {
      targetBottle = 1;
    }
    else {
      targetBottle = currentBottle + 1;      
    }
    showhide(targetBottle);
    return false;
  });

  function showhide(targetBottle) {
    $('div#b_' + targetBottle).appendTo('#bottles');
    $('div#d_' + targetBottle).appendTo('#descriptions');
    $('div#triggers > a.active').removeClass('active');
    $('div#triggers > a#t_b_' + targetBottle).addClass('active');
    $('div#descriptions > div.dcurrent').fadeOut('fast');
    $('div#b_' + targetBottle).fadeIn(function() {
      $('div#bottles > div.current').fadeOut('fast');
      $('div#bottles > div.current').removeClass('current');
      $(this).addClass('current');
    });
    $('div#descriptions div#d_' + targetBottle).fadeIn(function() {
      $('div#descriptions > div.dcurrent').removeClass('dcurrent');
      $(this).addClass('dcurrent');
    });
  }

});

