/**
ford-ural.ru javascript by Nikolay Komarkov, 2010 march
(c) 2010 www.novelsite.ru
*/

jQuery(document).ready(function(){
    jQuery("a").hover(function(){$(this).fadeOut(100);$(this).fadeIn(500);});
    jQuery(".plist").colorize({oneClick:true, click:'cell'});
    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();
        }
    });
    
function liFormat (row, i, num) {
	var result = row[0];
	return result;
}
function selectItem(li) {
	if( li == null ) var sValue = 'nothing';
	if( !!li.extra ) var sValue = li.extra[2];
	else var sValue = li.selectValue;
	document.location = "/catalog?act=search&target=product&qs="+sValue;
}

jQuery("#qs").autocomplete("_service/autocomplete_search.php", {
	delay:500,
	minChars:2,
	matchSubset:1,
	autoFill:false,
	matchContains:1,
	cacheLength:10,
	selectFirst:true,
	formatItem:liFormat,
	maxItemsToShow:10,
	onItemSelect:selectItem
}); 

});

