
  ZeroClipboard.setMoviePath('/static/js/clipboard/ZeroClipboard10.swf');

  $(function() {
    var NO_MORE, PAGE, SCROLL_ACTIVE, coupon_setup, placeholder;
    $('div.coupon-item .button.coupon a').each(function(i, elem) {
      var clip;
      $(elem).click(function(e) {
        return e.preventDefault();
      });
      clip = new ZeroClipboard.Client();
      clip.setHandCursor(true);
      clip.setText($(elem).data('code'));
      clip.glue(elem, $(elem).parent()[0]);
      return clip.addEventListener('complete', function(client, text) {
        return window.open($(elem).attr('href'), '_blank');
      });
    });
    window.resize = function() {
      return $('#page-sidebar').height($('#page-columns').height());
    };
    resize();
    $('div.coupon-item .description').each(function(i, elem) {
      var expander, text;
      var _this = this;
      text = $('.text', elem);
      if (text.height() > $(this).height()) {
        expander = $('.expander', this);
        expander.show();
        return expander.click(function(e) {
          e.preventDefault();
          $(_this).height(text.height());
          return expander.hide();
        });
      }
    });
    $('#page-sidebar button').click(function(e) {
      e.preventDefault();
      return $.get('/ajax/email-subscribe', {
        'email': $('#page-sidebar input').val()
      }, function() {
        $('#page-sidebar .submit-success').toggle();
        return $('#page-sidebar .form').toggle();
      });
    });
    coupon_setup = function() {
      var logo;
      logo = $('img.logo', this);
      return logo.error(function() {
        return logo.attr('src', logo.attr('src').replace(/\d+.jpg/, 'no_image.png'));
      });
    };
    $('.coupon-item').live('new-coupon', coupon_setup);
    $('.coupon-item').trigger('new-coupon');
    if ($('body.search').length > 0) {
      SCROLL_ACTIVE = false;
      NO_MORE = false;
      PAGE = 0;
      $(window).scroll(function() {
        var height, position, query;
        if (SCROLL_ACTIVE || NO_MORE) return;
        height = $(document).height();
        position = $(window).scrollTop() + $(window).height();
        if (height - position < 700) {
          PAGE += 1;
          SCROLL_ACTIVE = true;
          query = {
            'query': $('#search-query').text(),
            'page': PAGE
          };
          return $.get('/ajax/f/more', query, function(data) {
            SCROLL_ACTIVE = false;
            if (data.length < 100 && data.replace(/\s/g, '').length === 0) {
              NO_MORE = true;
              return;
            }
            if ($('.description', $(data)).length === 0) {
              NO_MORE = true;
              return;
            }
            $('#search-coupons').append(data);
            $('.coupon-item').trigger('new-coupon');
            return resize();
          });
        }
      });
    }
    placeholder = function(selector, submit_selector, parent) {
      var hasPlaceholderSupport, property;
      property = 'placeholder';
      hasPlaceholderSupport = function() {
        var input;
        input = document.createElement('input');
        return input.hasOwnProperty && input.hasOwnProperty(property);
      };
      if (!hasPlaceholderSupport()) {
        if (submit_selector) {
          $(submit_selector).click(function() {
            var node;
            parent = $(this).parents(parent);
            node = $("input[" + property + "]", parent);
            if ($(node).val() === $(node).attr(property)) return $(node).val('');
          });
        }
        return $(selector).blur(function() {
          var ph;
          ph = $(this).attr(property);
          if (!ph) return;
          if ($(this).val().length === 0 || $(this).val() === ph) {
            return $(this).val(ph).addClass('input-placeholder');
          }
        }).focus(function() {
          var ph;
          ph = $(this).attr(property);
          $(this).removeClass('input-placeholder');
          if (!ph) return;
          if ($(this).val() === $(this).attr(property)) return $(this).val('');
        }).blur();
      }
    };
    placeholder('#page-sidebar .email', '#page-sidebar button', '.email-form');
    return placeholder('#search-form input', '#search-form button', '#search-form');
  });

  $(function() {
    if (!$('body.admin')) return;
    $('body').append("<script src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js'></script>");
    $('body').append("<link rel='stylesheet' type='text/css' href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/ui-lightness/jquery-ui.css'/>");
    setTimeout(function() {
      return $('#admin-link').show();
    }, 2000);
    return $('#admin-link').click(function() {
      var admin_panel;
      admin_panel = $('#admin-panel');
      admin_panel.show();
      return admin_panel.dialog({
        title: 'Admin Panel',
        width: 800,
        height: 400,
        modal: true,
        zIndex: 58000,
        autoOpen: true
      });
    });
  });

