( function( $ ) {

function ttv_nl_show() {
   if( !$.cookie('prevent_newsletter_popup') ) {
      $.cookie('prevent_newsletter_popup', 1 );

      $('body').append( ttv_nl_build() );

      $('#ttv-newsletter-popup .ttv-np-close').click( function() {
         $('#ttv-newsletter-overlay').remove();
         $('#ttv-newsletter-popup').remove();
      });
   }
}

function ttv_nl_build() {
   var html = '';
   
   html += '<div id="ttv-newsletter-popup">';
   html += '   <form action="https://www.tenthousandvillages.ca/subscribe" method="POST">';
   html += '      <input type="hidden" name="lang" value="51250" />';

   html += '      <header>';
   html += '         <div class="ttv-np-close"></div>';
   html += '         <div class="ttv-np-inner">';
   html += '            <h2 class="en">Let\'s Stay Connected</h2>';
   html += '            <p>Be the first to hear about our new arrivals, latest offers and artisan features.</p>';
   html += '            <p><input type="email" name="email" placeholder="E-mail Address" /></p>';
   html += '            <p><input type="text" name="postal" placeholder="Postal Code" /></p>';
   html += '         </div>';
   html += '      </header>';
   html += '      <div class="ttv-np-main">';
   html += '         <div class="ttv-np-inner">';
   html += '            <p><strong>Were you referred by someone currently on our mailing list?</strong> Enter their email address and both of you will receive 15% off your next purchase.</p>';
   html += '            <p><input type="email" name="referrer" placeholder="Your friend\'s email address" /></p>';
   html += '            <p><input type="submit" class="btn-brown" value="Subscribe" /></p>';
   html += '         </div>';
   html += '      </div>';
   html += '      <footer>';
   html += '         <div class="ttv-np-inner">';
   html += '            <p>By signing up, you agree to receive Ten Thousand Villages promotions and other commercial emails. You may withdraw your consent at any time. For more details, please read our <a href="http://www.tenthousandvillages.ca/privacy-and-legal">Privacy Policy</a>.</p>';
   html += '         </div>';
   html += '      </footer>';
   html += '   </form>';
   html += '</div>';
   html += '<div id="ttv-newsletter-overlay"></div>';

   return html;
}


$( function() {
   ttv_nl_show();
});

}( jQuery ));
