function Cart () {
	this.addToCart = function(formId) {
		// find formen.
		var form = $("#" + formId);
		// Hvis der er skjulte selects, så vil vi ikke submitte, men skal i stedet vise detaljesiden
		var selects = form.find('select[name^=product_variant_id_for_]:hidden');
		if (selects.length > 0) {
			// Find link til detaljevisning
			location.href = form.find('input[name="url_show"]').attr('value');
			return false;
		}
		// prepare postdata
		var postData = form.serialize();
		// Show overlay containing ajax-loader
		this.showLoadingOverlay();
		// post data
		$.post('/index.php', postData, function (data, textStatus) {
				if (textStatus == 'success') {
					// Insert the returned html
					$("#mini-cart").html(data);
					// Vis success overlay
					cart.showSuccessOverlay();
				}
			}
		);
	}

	this.successOverlayId = 'add_to_cart_overlay';
	this.loadingOverlayId = 'loading_overlay';

	this.showLoadingOverlay = function () {
		$("#" + this.loadingOverlayId).
			show().
			css('position',		'fixed').
			css('z-index',		'99').
			css('top',			'50%').
			css('left',			'50%').
			css('margin-left',	'-50px').
			css('margin-top',	'-50px');
	}

	this.showSuccessOverlay = function () {
		this.hide(this.loadingOverlayId);
		// Placerer overlay
		$("#" + this.successOverlayId).
			show().
			css('position',		'fixed').
			css('z-index',		'99').
			css('top',			'50%').
			css('left',			'50%').
			css('margin-left',	'-114px').
			css('margin-top',	'-58px');
	}

	this.hide = function (idToHide) {
		if (idToHide == '') {
			 return false;
		}

		$("#" + idToHide).hide();
		return true;
	}
}
var cart = new Cart();
