jQuery(function()
{
    jQuery('#submenus .product').each(function()
    {
        var prod = jQuery(this);
        var idProd = '#' + prod.attr('id');
        var size = jQuery(idProd + ' .size');
        var option = jQuery(idProd + ' .option');
        var price = jQuery(idProd + ' .price');
        var quant = jQuery(idProd + ' .quant').after('<a href="" class="inc"><img src="/img/layout/next.gif" alt="+ Increase" width="5" height="15" border="0" class="arrow_small_right" /></a>').before('<a href="" class="dec"><img src="/img/layout/prev.gif" alt="- Decrease" width="5" height="15" border="0" class="arrow_small_left" /></a>');
        
        if (size.size() || option.size())
        {
            var changePrice = function(event)
            {
                if (size.val() == -1 || option.val() == -1)
                {
                    price.html('');
                }
                else
                {
                    var priceId = prod.attr('id');
                
                    if (size.size())
                    {
                        priceId += 's' + size.val();
                    }
                
                    if (option.size())
                    {
                        priceId += 'o' + option.val();
                    }
                    
                    var qty = parseInt(quant.val());
                    if(qty < 1) qty = 1;
                    //multiply if grater than 1 - disabled
                    //var tmp_price =  (jQuery('#' + priceId).html() * (isNaN(qty) ? 0 : qty) ).toFixed(2);  
                     var tmp_price =   (jQuery('#' + priceId).html() * 1 ).toFixed(2);
                    price.html('$ ' + tmp_price);
                                
                }
            }
            
            size.change(changePrice);
            option.change(changePrice);
            quant.keyup(function ()
            {
                var value = quant.val();
                
                if (value != '')
                {
                    var value = parseInt(value);
                    
                    if (isNaN(value) || (value < 0 ))
                    {
                        quant.val('0');
                    }
                    else if(value > 10)
                    {
                        quant.val('10');
                    }
                }
            
                //changePrice();
            });
            
            changePrice();
            
	        var inc = jQuery(idProd + ' .inc');
	        var dec = jQuery(idProd + ' .dec');
	        
	        inc.click(function(event)
	        {
	            var qty = parseInt(quant.val());
	            
	            if (isNaN(qty) || qty < 0)
                {
                    quant.val('0');
                }
                else if (qty < 10)
                {
                    quant.val(qty + 1);
                }
                
                // changePrice();
                return false;
	        });
	        
	        dec.click(function(event)
            {
                var qty = parseInt(quant.val());
                
                if (isNaN(qty) || qty < 0)
                {
                    quant.val('0');
                }
                else if (qty > 0)
                {
                    quant.val(qty - 1);
                }
                
                // changePrice();
                return false
            });
        }
    });
});

// myBasket tab dynamic height
jQuery(function()
{
    var tabBasket = jQuery('#tabBasket a');
    var height = tabBasket.parent().parent().parent().height();
    var rows = parseInt(height / 27);
    tabBasket.attr('style', 'height: ' + (rows * 27 - 11) + 'px; line-height: ' + (rows * 27 - 11) + 'px');
    
    var newHeight = tabBasket.parent().parent().parent().height();
    
    if (newHeight > height)
    {
        rows++;
        tabBasket.attr('style', 'height: ' + (rows * 27 - 11) + 'px; line-height: ' + (rows * 27 - 11) + 'px');
    }
});

jQuery(function()
{
    var qty = jQuery('#submenus .quant');
    
    qty.each(function()
    {
	    var current = jQuery(this);
	    var value = 0;
	    
	    current.bind('focus', function(event)
	    {
	        value = current.val();
	        current.val('');
	    })
	    .bind('blur', function(event)
	    {
	       if (current.val() == '')
	       {
	           current.val(value);
	       }
	    });
	});
});