﻿var base_path = '/';
/*
Shadowbox.loadSkin('classic', base_path + 'js/shadowbox/skin');
Shadowbox.loadLanguage('en', base_path + 'js/shadowbox/lang');
Shadowbox.loadPlayer(['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'], base_path + 'js/shadowbox/player');
$(window).load(function(){
  var options = {};
  Shadowbox.init(options);
});
*/

$(function(){
  /* Buy product **************************************************************/
  $('a.buy_button').click(function(){
    var id  = this.id.split('_')[1];
    $.post(
      base_path + 'shop/add-to-cart.html',
      {'product_id' : id},
      function(data){
        $('#cart_list').html(data);
/*
        var but = $('#prd_' + id);
        if(but.nextAll('.cart_content').length == 0){
          but.after(
            '<div class="cart_content">' +
              'Добавлен в <a href="'+ base_path +'shop/cart.html">корзину</a>' +
            '</div>'
          );
        }
*/
      }
    );
    return false;
  });

  /* Search submit ************************************************************/
  $('#search_form').submit(function(){
    window.location = (base_path + 'shop/search/' + encodeURIComponent($('#search_form input[name=search_string]').val()) + '.html');
    return false;
  });
  $('#search_form input.text').focus(function(){
    $(this).val( $(this).val() == "Поиск" ? "" : $(this).val() );
  });
  $('#search_form input.text').blur(function(){
    $(this).val( $(this).val() == "" ? "Поиск" : $(this).val() );
  });
});

function remove_from_cart(id, reload)
{
  $.post(
    base_path + 'shop/remove-from-cart.html',
    {'product_id' : id},
    function(data){
      $('#cart_list').html(data);
      if(reload == true){window.location = window.location;}
    }
  );
}
