(function($){
	$.fn.addToCart = function(settings) {
		
		this.each(function(){
			
			$(this).click(function(event){
				
				//add item to cart
				$.ajax({
					url : $(this).attr('name'), 
					success : function(data){
						//load popup
						$.modal(data, {autoResize:false});
						
						if (!$.browser.msie)
							$('body, html').animate({scrollTop:0});
						
						//update cart
						$.ajax({
							url : '/home/loadcart/', 
							data : null, 
							success : function(data){
								
								$('#ShoppingCartRefresh').html(data);
							},
							error : function(request, status, error) {
								alert(request.responseXML);
							}
						});
						
						//setup close links
						$('.cart-popup .close').click(function(event){
							$.modal.close();
							event.preventDefault();
						});
						
						//continue link - refresh page
						$('.cart-popup .continue').click(function(event){
							window.location.reload();
							event.preventDefault();
						});
					},
					error : function(request, status, error) {
						alert('There has been an error adding your item to the cart.')
					}
					
				});
				
				event.preventDefault();
			});
		});
		
		
	};
})(jQuery);

$(document).ready(function(){
	$('a.add-to-cart').addToCart();
});
