
/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.X
 *	LICENSE: FL0M2SG681CQ - http://www.flynax.com/license-agreement.html
 *	PRODUCT: Pets Classifieds
 *	DOMAIN: pupsnshop.com
 *	FILE: LIB.JS
 *
 *	The software is a commercial product delivered under single, non-exclusive, 
 *	non-transferable license for one domain or IP address. Therefore distribution, 
 *	sale or transfer of the file in whole or in part without permission of Flynax 
 *	respective owners is considered to be illegal and breach of Flynax License End 
 *	User Agreement. 
 *
 *	You are not allowed to remove this information from the file without permission
 *	of Flynax respective owners.
 *
 *	Flynax Classifieds Software 2014 |  All copyrights reserved. 
 *
 *	http://www.flynax.com/
 *
 ******************************************************************************/

var shoppingCartClass = function(){

	/**
	* reference to self object
	**/
	var self = this;

    /**
	* handler events of items
	**/
	this.handlerItems = function() {
		$('span.increase').click(function()
		{
			var current = $(this).next().val();
			current++;
 
			$(this).next().val(current);
			var shc_dealer = $(this).parents('form').attr('id').split('_')[1];
			self.recalculateTotal(shc_dealer, $(this).next().attr('id').split('_')[1], current);
		});

		$('span.decrease').click(function()
		{
			var current = $(this).prev().val();

			if(current > 1)
			{
				current--;
			}

			$(this).prev().val(current);
			var shc_dealer = $(this).parents('form').attr('id').split('_')[1];
			self.recalculateTotal(shc_dealer, $(this).prev().attr('id').split('_')[1], current);
		});

		$('input.quantity').keyup(function()
		{          
			var shc_dealer = $(this).parents('form').attr('id').split('_')[1];
			self.recalculateTotal(shc_dealer, $(this).attr('id').split('_')[1], $(this).val());
		});
	}

    /**
	* recalculate total method
	**/
	this.recalculateTotal = function(dealer, id, quantity) {

		var current_item_price = parseFloat($('#quantity_' + id).attr('accesskey'));
		var current_item_total = parseFloat($('#price_' + id).html());
        var new_price = current_item_price * quantity;
		
		$('#price_' + id).html(new_price.toFixed(2));

		var total = parseFloat($('#total_' + dealer).html());
		total = (total - current_item_total) + new_price;

		total = $('#total_' + dealer).html(total.toFixed(2));
	}
}

var shoppingCart = new shoppingCartClass();