$(document).ready(function() {
	/* place jQuery actions here */
	var link = "/";
	var browserName = navigator.appName;

	$("div.right_text_box form").submit(function() {
		
		

		// Get the product ID and the quantity
			var id = $(this).find('input[name=product_id]').val();
			var qty = $(this).find('input[name=quantity]').val();
			var option = $('select[name=option]').val();
			
			//alert(option);

			$.post(link + "trgovina/add_cart_item/", {
				option: option, 
				product_id : id,
				quantity : qty,
				ajax : '1'
			}, function(data) {

				if (data == 'true') {

					$.get(link + "trgovina/show_cart/", function(cart) {
						$("#cart_content").html(cart);

					});

					$.get(link + "trgovina/cart_items/", function(cart) {
						$("#cart_refresh").html(cart);

					});

				} else {
					alert("Product does not exist");
				}
				if (browserName == "Microsoft Internet Explorer") {
					window.location.reload()
				}

			});

			return false;
		});
	$("div.slide_item_small_2 form").submit(function() {

		// Get the product ID and the quantity
			var id = $(this).find('input[name=product_id]').val();
			var qty = $(this).find('input[name=quantity]').val();
			var option = $('select[name=option]').val();

			$.post(link + "trgovina/add_cart_item/", {
				option: option,
				product_id : id,
				quantity : qty,
				ajax : '1'
			}, function(data) {

				if (data == 'true') {

					$.get(link + "trgovina/show_cart/", function(cart) {
						$("#cart_content").html(cart);

					});

					$.get(link + "trgovina/cart_items/", function(cart) {
						$("#cart_refresh").html(cart);

					});

				} else {
					alert("Product does not exist");
				}
				if (browserName == "Microsoft Internet Explorer") {
					window.location.reload()
				}

			});

			return false;
		});

	$("div.slide_item_small form").submit(function() {

		// Get the product ID and the quantity
			var id = $(this).find('input[name=product_id]').val();
			var qty = $(this).find('input[name=quantity]').val();
			var option = $('select[name=option]').val();

			$.post(link + "trgovina/add_cart_item/", {
				option: option,
				product_id : id,
				quantity : qty,
				ajax : '1'
			}, function(data) {

				if (data == 'true') {

					$.get(link + "trgovina/show_cart/", function(cart) {
						$("#cart_content").html(cart);

					});

					$.get(link + "trgovina/cart_items/", function(cart) {
						$("#cart_refresh").html(cart);

					});

				} else {
					alert("Product does not exist");
				}
				if (browserName == "Microsoft Internet Explorer") {
					window.location.reload()
				}

			});

			return false;
		});
	
	$("div.product_bottom form").submit(function() {

		// Get the product ID and the quantity
			var id = $(this).find('input[name=product_id]').val();
			var qty = $(this).find('input[name=quantity]').val();
			var option = $('select[name=option]').val();

			$.post(link + "trgovina/add_cart_item/", {
				option: option,
				product_id : id,
				quantity : qty,
				ajax : '1'
			}, function(data) {

				if (data == 'true') {

					$.get(link + "trgovina/show_cart/", function(cart) {
						$("#cart_content").html(cart);

					});

					$.get(link + "trgovina/cart_items/", function(cart) {
						$("#cart_refresh").html(cart);

					});

				} else {
					alert("Product does not exist");
				}
				if (browserName == "Microsoft Internet Explorer") {
					window.location.reload()
				}

			});

			return false;
		});
	
	$(".empty").live("click", function() {

		$.get(link + "trgovina/empty_cart/", function() {

			$.get(link + "trgovina/show_cart/", function(cart) {
				$("#cart_content").html(cart);
			});

			$.get(link + "trgovina/cart_items/", function(cart) {
				$("#cart_refresh").html(cart);

			});
			if (browserName == "Microsoft Internet Explorer") {
				window.location.reload()
			}

		});
		return false;
		
		

	});
	




});
