;(function($) {

    $.fn.side_favorite_delete = function(option){
    var defaults = {
      update:''
    };
    var option = $.extend(defaults,option);

    this.bind('click', function(e){
      $.ajax({
        url: '/paint/favorite/delete_side?id='+$(this).data('id'),
        type: 'get',
        timeout: 10000,
        success: function(data) {
          $(option['update']).html(data);
        }
      });
    });

    return(this);
  };

    $.fn.side_recommend_zip = function(option){
    var defaults = {
      update:'',
      zip1:'',
      zip2:''
    };
    var option = $.extend(defaults,option);

    this.bind('submit', function(e){
      e.preventDefault();
      $.ajax({
        url: $(this).attr('action'),
        type: $(this).attr('method'),
        data: $(this).serialize(),
        timeout: 10000,
        success: function(data) {
          $(option['update']).html(data);
        }
      });
    });

    return(this);
  };

    $.fn.shop_estimate_add = function(option){
    var defaults = {
      update:'',
      select_check_box:''
    };
    var option = $.extend(defaults,option);
    
    this.bind('click', function(){
      var url = '';
      if($(this).prop('checked')) {
        url = '/paint/shops/add_shop_estimate?id='+$(this).data('id');
        var ele = document.getElementById('js-div-keep'+$(this).data('id'));
        if(ele != null){
          $('#js-div-keep'+$(this).data('id') + ' .keepalert').fadeIn(500).delay(700).fadeOut(700);
        }
      }
      else {
        url = '/paint/shops/del_shop_estimate?id='+$(this).data('id');
      }

      $.ajax({
        url: url,
        type: 'get',
        timeout: 10000,
        success: function(data) {
          $(option['update']).html(data);
        }
      });
    });

    return(this);
  };

    $.fn.shop_estimate = function(option){
    var defaults = {
      select_check_box:''
    };
    var option = $.extend(defaults,option);

    var el_shop_estimate = this;
    scrollShopEstimate(el_shop_estimate);

        $(window).bind('scroll', function(){
      scrollShopEstimate(el_shop_estimate);
    });

        $(option['select_check_box']).bind('click', function() {
      $.ajax({
        url: '/paint/shops/del_shop_estimate?id='+$(this).data('id'),
        type: 'get',
        timeout: 10000,
        success: function(data) {
          $(el_shop_estimate).html(data);
        }
      });
    });

    return(this);
  };

    function scrollShopEstimate(target) {
    if ($(window).scrollTop() > 100) {
      $(target).slideDown("fast");
    } else {
      $(target).slideUp("fast");
    }
  }
})(jQuery);
