/*** www.it24.ru ***************************************************************
 * Basket class for it24.ru Library
 *    _    ____ _    _    _____  _    _
 *  _| |  / __ \ |  | |  |  _  \| |  | |
 * {_} |_|_| | | |  | |  | {_}  | |  | |
 *  _|  /    | | |__| |  |  ___/| |  | |
 * | | |    / / \___| |  | |\ \ | |  | |
 * | | |__ / /_     | |  | | \ \| |__| |
 * |_|\__/_____|    |_|{}|_|  \_/\_____| 
 * 
 *** www.it24.ru ***************************************************************/

var Basket = {
  translations: {
    ru: {
        padd:     'Добавить в корзину',
        pdel:     'Удалить из корзины',
        loading:  'Обновление информации',
        porder:   'Для заказа товара щёлкните на изображении корзинки рядом с ним',
        order:    'Оформить заказ'
        }
  },
  images: {
    on:           '/itlib/buy/c-buy-on.gif',
    off:          '/itlib/buy/c-buy-off.gif',
    loading:      '/itlib/loaders/2.gif'
  },

move: function(o, i){
  key = i.substring(2);

  if(o.alt.substring(0,this.translations.ru.padd.length)==this.translations.ru.padd)
  {
    ok = false;
    o.src = this.images.loading;
    o.alt = this.translations.ru.loading;
    o.title = this.translations.ru.loading;
    this.pAdd(o,key);
  }
  else if(o.alt.substring(0,this.translations.ru.pdel.length)==this.translations.ru.pdel)
  {
    ok = false;
    o.src = this.images.loading;
    o.alt = this.translations.ru.loading;
    o.title = this.translations.ru.loading;
    this.pDel(o,key);
  }
},

pAdd: function(o,itemid){
//	$('#basket').html("<div id='a_loader' style='height:100%'><img src='"+this.images.loading+"'/></div>");
    $.post('/ajax_basket.php', {
        itemid:itemid,cmd:'add'}, function(data,status) {
        if(status=="success") {
        	 $('#basket').html(data);
        	 ok = true;
       }
    if(ok) {
    	o.src =		Basket.images.off;
    	o.alt =		Basket.translations.ru.pdel;
    	o.title =	Basket.translations.ru.pdel;
    	num++;
    }   
    });    
},

pDel: function(o,itemid){
//$('#basket').html("<div id='a_loader' style='height:100%'><img src='"+this.images.loading+"'/></div>");	
    $.post('/ajax_basket.php', {
        itemid:itemid,cmd:'delete'}, function(data,status) {
        if(status=="success") {
        	 $('#basket').html(data);
        	 ok = true;
       }
	    if(ok) {
	    	o.src =		Basket.images.on;
	    	o.alt =		Basket.translations.ru.padd;
	    	o.title =	Basket.translations.ru.padd;
	    	num--;
	    }        
    });       
}
};


jQuery( function($) {
  $(".addbasket").bind("click", function(e){Basket.move(this,this.id);});
  $.post('/ajax_basket.php', {}, function(data) {$('#basket').html(data);});
});

