$(document).ready(function() {
  $('.leaving_site_wrapper').hide();
  /* $('.social_fb a, .social_tweet a, .sidebar_follow_us .facebook, .sidebar_follow_us .twitter').click(function() {
    var link = $(this).attr('href');
    $('.leaving_site_wrapper').modal();
    $('.leaving_site_top h2').text('Social Networking');
    $('.continue_yes a').click(function() {
      window.location.href = link;
      return false;
    });
    $('.continue_no a, .leaving_site_close a').click(function() {
      $.modal.close();
      return false;
    });
    return false;
  }); */

  

  $('.buy_now .store_locator_stores ul li a').click(function() {
    var link = $(this).attr('href');
    $.modal.close();
    setTimeout(function () {  
      $('.leaving_site_wrapper').modal();
    }, 20);  
    $('div.leaving_site_wrapper').addClass("store_locator_two");
    $('.leaving_site_top h2').text('Buy Now');    

    $('.store_locator_two .continue_yes a').click(function() {
      window.open(link, "mywindow");
      return false;
    });

    $('.continue_no a, .leaving_site_close a').click(function() {
      $.modal.close();
      $('div.leaving_site_wrapper').removeClass("store_locator_two");
      return false;
    });
    return false;
  });
  
  /* function store_locator_drop_down_site_exit(dropdown_url) {
    $.modal.close();
    setTimeout(function () {  
      $('.leaving_site_wrapper').modal();
    }, 20);  
    $('div.leaving_site_wrapper').removeClass("store_locator_one store_locator_two store_locator_three store_locator_four");
    $('.leaving_site_top h2').text('Store Locator');    

    $('.continue_yes a').click(function() {
      window.open(dropdown_url);
      return false;
    });

    $('.continue_no a, .leaving_site_close a').click(function() {
      $.modal.close();
      return false;
    });
    return false;
  } */

  $('.store_locator_stores ul li a').click(function() {
    var link = $(this).attr('href');
    $.modal.close();
    setTimeout(function () {  
      $('.leaving_site_wrapper').modal();
    }, 20);  
    $('div.leaving_site_wrapper').addClass("store_locator_one");
    $('.leaving_site_top h2').text('Store Locator');    

    $('.store_locator_one .continue_yes a').click(function() {
       window.open(link, "mywindow");
      return false;
    });

    $('.continue_no a, .leaving_site_close a').click(function() {
      $.modal.close();
      delete link;
      $('div.leaving_site_wrapper').removeClass("store_locator_one");
      return false;
    });
    return false;
  });

  $('.allegra_save_wrapper ul li a').click(function() {
    if ( $(this).parent().hasClass("two_dollar") ) {
      _gaq.push(['_trackEvent', 'Coupon', 'printed', 'Two Dollar Coupon']);
    }
    if ( $(this).parent().hasClass("four_dollar") ) {
      _gaq.push(['_trackEvent', 'Coupon', 'printed', 'Four Dollar Coupon']);
    }
    var link = $(this).attr('href');
    $.modal.close();
    setTimeout(function () {  
      $('.leaving_site_wrapper').modal();
    }, 20);  
    $('div.leaving_site_wrapper').addClass("store_locator_three");
    $('.leaving_site_top h2').text('Print Coupon');    

    $('.store_locator_three .continue_yes a').click(function() {
      window.open(link, "mywindow");
      return false;
    });

    $('.continue_no a, .leaving_site_close a').click(function() {
      $.modal.close();
      $('div.leaving_site_wrapper').removeClass("store_locator_three");
      return false;
    });
    return false;
  });

  $('.offer a').click(function() {
    if ( $('body').hasClass("save_on_allegra_two") ) {
      _gaq.push(['_trackEvent', 'Coupon', 'printed', 'Two Dollar Coupon']);
    }
    if ( $('body').hasClass("save_on_allegra_four") ) {
      _gaq.push(['_trackEvent', 'Coupon', 'printed', 'Four Dollar Coupon']);
    }
    var link = $(this).attr('href');
    $('.leaving_site_wrapper').modal();
    $('div.leaving_site_wrapper').addClass("store_locator_four");
    $('.leaving_site_top h2').text('Print Coupon');    

    $('.store_locator_four .continue_yes a').click(function() {
      window.open(link, "mywindow");
      return false;
    });

    $('.continue_no a, .leaving_site_close a').click(function() {
      $.modal.close();
      $('div.leaving_site_wrapper').removeClass("store_locator_four");
      return false;
    });
    return false;
  });

  

  /* $('.footer_bottom a').click(function() {
    var link = $(this).val();
    $.modal.close();
    setTimeout(function () {  
      $('.leaving_site_wrapper').modal();
    }, 20);  
    
    $('.leaving_site_top h2').text('Chattem');    

    $('.continue_yes a').click(function() {
      window.location.href = link;
      return false;
    });

    $('.continue_no a, .leaving_site_close a').click(function() {
      $.modal.close();
      return false;
    });
    return false;
  }); */

  /* $('.news_listing a').click(function() {
    var link = $(this).val();
    $.modal.close();
    setTimeout(function () {  
      $('.leaving_site_wrapper').modal();
    }, 20);  
    
    $('.leaving_site_top h2').text('News & Press');    

    $('.continue_yes a').click(function() {
      window.open(link);
      return false;
    });

    $('.continue_no a, .leaving_site_close a').click(function() {
      $.modal.close();
      return false;
    });
    return false;
  }); */
 
});

