/**
parts-master.ru javascript by Nikolay Komarkov, 2010-2011
(c) 2011 www.novelsite.ru
*/

$(document).ready(function(){

	$(".b-round #plist").tablesorter({widgets: ['zebra'], headers: {6:{sorter: false}} });
	$('.b-main-menu li:last').addClass('last');
	$('.b-reset a').click(function(){
		$('.b-form-order form').reset();
		return false;
	});
	
	$('.b-reverse li:last').addClass('last');
    
    $("#basket").hover(
      function() {
          $(this).css({'background': '#e7f3fb', 
                       'cursor':'pointer'
          });
      } , 
      function() {
          $(this).css({'background' : 'none'});
    });
    
    $("#basket").click(function() {window.location = '/basket';});

    
    jQuery.basket();

    jQuery('.add_cart').click(function(){
        var str = jQuery(this).attr("rel");
        var arr1 = str.split(',');
        // id, price, amount
        var id = '#product_'+arr1[0];
        var val =  0;
        if (parseInt(jQuery(id).val()) > 0) {
            val = parseInt(jQuery(id).val());
        }
        val = parseInt(val)+1;
        jQuery(id).val(parseInt(val));
        jQuery.basket(arr1[0], arr1[1], val);
        jQuery('#pr_'+arr1[0]+' td').attr('style', 'font-weight:bold');
        
    });
    
    jQuery('.del_cart').click(function(){
        var str = jQuery(this).attr("rel");
        var arr1 = str.split(',');
        var id = '#product_'+arr1[0];
        var val = jQuery(id).val();
        if (parseInt(val) > 0) {
            jQuery(id).val(parseInt(val)-1);
            if (parseInt(val)-1 == 0) {
                jQuery(id).val('');
            }
        }
        else {
            jQuery(id).val('');
        }
        var s = arr1[0]+','+jQuery(id).val();
        jQuery.basket(arr1[0], arr1[1], jQuery(id).val());
        if (jQuery(id).val() == '') {
            jQuery('#pr_'+arr1[0]+' td').attr('style', 'font-weight:normal');
            jQuery('#tr_'+arr1[0]).fadeOut(500).delay(500).remove();
        }
    });
    

});

