$(document).ready(function() {
  if ($.fn.superfish) {
    $(".nav").superfish({
      delay: 100,
      speed: "fast"
    })
    .find(">li[ul]").mouseover(function() {
      $("ul", this).bgIframe({ opacity:0});
    })
    .find("a").focus(function() {
      $("ul", $(".nav>li[ul]")).bgIframe({opacity:false});
    });
  }

  $('input.button').hover(function() {
      $(this).toggleClass('button')
             .toggleClass('buttonHover');
  },
  function() {
     $(this).toggleClass('button')
            .toggleClass('buttonHover');
  });

  $('.emailSignupButton').hover(function() {
      $(this).toggleClass('emailSignupButton')
             .toggleClass('emailSignupButtonHover');
  },
  function() {
     $(this).toggleClass('emailSignupButton')
            .toggleClass('emailSignupButtonHover');
  });

  $('.notifyMeButton').hover(function() {
      $(this).toggleClass('notifyMeButton')
             .toggleClass('notifyMeButtonHover');
  },
  function() {
     $(this).toggleClass('notifyMeButton')
            .toggleClass('notifyMeButtonHover');
  });

  $('#location').bind("keypress", function(e) {
     var code = e.charCode || e.keyCode;
     if (code == 13) {
       $('#findStore').click();
       return false;
     }
  });


  var rCookies = $.cookies.get(['kFirstTime', 'kFirstTimeShown', 'ReedsStoreIdCookie']);
  if (rCookies != null) {
    if (false && rCookies.kFirstTime != null && rCookies.kFirstTimeShown == null) {
      $.cookies.set('kFirstTimeShown', '', {domain: '.reeds.com'});
      tb_show('First Time Visitor', 'FirstTime.html?height=330&width=275');
    }

    if (rCookies.ReedsStoreIdCookie != null) {
      $.getJSON("/cart/CartAction.html", { action: 'timeOnPage' }, function(result) {
        if (result.status == 'OK' && (result.timeOnPage > 300 || result.timeOnPage < 0)) {
          tb_show('New Visitor', '/cart/NewVisitor.html?height=300&width=275');
        }
      });
    }
}

  // Non - Free ship states
  var noState = ['AK', 'AS', 'FM', 'GU', 'HI', 'MH', 'MP', 'PW', 'PR', 'VI', 'AE', 'AA', 'AP'];
  if (false && google && google.loader && google.loader.ClientLocation && google.loader.ClientLocation.address.country_code == "US" && google.loader.ClientLocation.address.region)  {
    if (jQuery.inArray(google.loader.ClientLocation.address.region.toUpperCase(), noState) == -1) {
      $('#sblcImage').attr({
        src: '/banners/left-col/free-standard-shipping.gif',
        alt: 'Free Standard Shipping',
        title: 'Free Standard Shipping'
      });
      $('#sblcLink').removeAttr('href');
      $('#sbhImage').attr({
        src: '/banners/free-shipping.gif',
        alt: 'Free Standard Shipping',
        title: 'Free Standard Shipping'
      });
      $('#sbhLink').removeAttr('href');
    }
  }
});


