﻿



$.fn.orderButton = function(options){
	
	var url = options.orderUrl;
	var productId = $('.product-id:first', this).val();
	var _this = this;
	
	
	$('.product-price input:first', _this).keyup(function(e){
		if(isNaN($(this).val())){
			$(this).val(1);
		} 
		if(parseInt($(this).val()) < 1){
			$(this).val(1);
		}
		if($(this).val() == null || $(this).val() == ''){
			$(this).val(1);
		}
		$('.product-cost',_this).html(parseFloat($('.product-price span', _this).html()) * parseInt($(this).val()));
	});
	$(this).hover(function(e){
		$('.cart-preview-box', _this).show();
	},
	function(e){
		$('.cart-preview-box', _this).hide();
	});
	
	
	
	$('.product-order a:first', this).click(function(e){
		
		var quantity = $('.product-price input:first', _this).val();
		if(isNaN(quantity)){
			quantity = 1;
			$('.product-price input:first', _this).val(1);
		}
		$.ajax({
            type: "POST",
            url: url,
            data: {productId : productId, quantity : quantity},
            dataType: "html",
            success: function (data) {
            }
        });
		
	});
}
