jQuery(document).ready(function($){


function checkFields () {
    var title = $('#voucher_title').val();
    var name = $('#recipient_name').val();
    var message = $('#recipient_message').val();
    var from = $('#voucher_from').val();
    var amount = $('#amount').val();

    if((amount)) {
        $('#previewLink').show();
    } else {
        $('#previewLink').hide();
    }

}
    $('#voucher_title').focus(checkFields);
    $('#recipient_name').focus(checkFields);
    $('#recipient_message').focus(checkFields);
    $('#voucher_from').focus(checkFields);
    $('#amount').focus(checkFields);

    checkFields();

    $(document).bind('cbox_closed', function(){
        $('#addToCart').show();
    });

  $('#previewPDF').colorbox({
      href: function(){
            // get the values of the fields
            var title = $('#voucher_title').val();
            var name = $('#recipient_name').val();
            var message = $('#recipient_message').val();
            var from = $('#voucher_from').val();
            var amount = $('#amount').val();
            var product = $('[name="product"]').val();

            var href = this.href + 'title/' + escape(title);
            href += '/name/' +  escape(name);
            href += '/message/' +  escape(message.replace(/\//g, '##fwd##'));
            href += '/name/' +  escape(name);
            href += '/from/' +  escape(from);
            href += '/amount/' +  escape(amount);
            href += '/productId/' +  escape(product);
            return href;
      }

  });

  if($('.slideshow').length) {
      $('.slideshow').cycle({
        fx: 'fade',
        pause: 'true'
      });
  }

  if($('.options-list label').length) {
      $('.options-list label').each(function(i){
          if(i == 0) {
            $(this).tooltip({
                tip: $('#packaging-classic')
            });
          }
          if(i == 1) {
            $(this).tooltip({
                tip: $('#packaging-x-mas')
            });
          }
//          $(this).wrapInner('<a href="#" />');
      });

  }


});
