var enews_email_text = "";
var wpsc_single_item_cart = false;

jQuery(document).ready(function($) {
  var submenu = $('ul.submenu');
  if (submenu != null && submenu.length > 0) {
    var top_offset = submenu.offset();
    var bottom_offset = $('div.page div.wp-content').offset().top;
    $("ul.submenu li").each(function(i) {
      var this_offset = $(this).offset();
      if (this_offset.top == top_offset.top) {
        $(this).addClass('toprow');
      }
      if (this_offset.left == top_offset.left) {
        $(this).addClass('leftcol');
      }
      var is_bottom = bottom_offset - this_offset.top - $(this).height() - 1;
      if (is_bottom == 0) {
        $(this).addClass('bottomrow');
      }
    });
  }

  enews_email_text = $('#enews_email').attr('value');
  $('input#enews_email').focus(function() {
      if ($(this).attr('value') == enews_email_text) $(this).attr('value', "");
  });
  $('input#enews_email').blur(function() {
      if ($(this).attr('value') == "") $(this).attr('value', enews_email_text);
  });

  if($.browser.msie && $.browser.version=="6.0") {
    $('li.page-item-1180 a').click(function() {
      alert("We apologize, but online ordering is not supported in this browser (Internet Explorer 6) at this time. \nPlease call us at 1-800-754-9453 instead."); 
      return false;
    });
  }

  $.localScroll({ hash:false });

  // auto-set payment amount
  var total = $('#checkout_total');
  if (total != null && total.length > 0) {
    total_html = total.html();
    $('#wpsc_checkout_form_42').attr('value',total_html);
    $('#wpsc_checkout_form_42').attr('disabled',true);

    if (wpsc_single_item_cart) {
      $('#wpsc_checkout_form_43').attr('value',total_html);
      $('tr.wpsc_checkout_form_43').hide();
      $('div.custom_gateway:last').hide();
    }
  }
  jQuery("form.wpsc_checkout_forms").submit(function() {
      var email1 = $('#wpsc_checkout_form_19').attr('value');
      var email2 = $('#wpsc_checkout_form_44').attr('value');
      if (email1 != email2) {
        alert("The specified email address does not match the verification email address.  Please double-check your email address.");
        return false;
      }
      return true;
  });
  // go directly to check-out for single-item page
  jQuery("form.single_product_form").submit(function() {
      // we cannot submit a file through AJAX, so this needs to return true to submit the form normally if a file formfield is present
      file_upload_elements = jQuery.makeArray(jQuery('input[type=file]', jQuery(this)));
      if(file_upload_elements.length > 0) {
      return true;
      } else {
      form_values = jQuery(this).serialize();
      // Sometimes jQuery returns an object instead of null, using length tells us how many elements are in the object, which is more reliable than comparing the object to null
      if(jQuery('#fancy_notification').length == 0) {
      jQuery('div.wpsc_loading_animation',this).css('visibility', 'visible');
      }
      jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
        eval(returned_data);
        jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');

        if(jQuery('#fancy_notification') != null && jQuery('#fancy_notification').length > 0) {
        jQuery('#loading_animation').css("display", 'none');
        //jQuery('#fancy_notificationimage').css("display", 'none');
        }
	window.location = "/book-now/checkout/";

        });
      wpsc_fancy_notification(this);
      return false;
      }
  });
  if($.browser.msie) {
    $('#variation_select_20_6, #variation_select_21_1').hover(function() {
      $(this).data('origWidth', $(this).css('width')).css('width','auto');
    }, function() {
      //$(this).css('width', $(this).data('origWidth'));
    });
  }

  $(".tshirt-info, .product_view_23 .wpsc_description a").colorbox({inline:true, href:"#tshirt-popup-content"});
});

