//to: {width:308,height:200}

$.extend($.modal.defaults, {
	overlayClose: true,
	onOpen: function(dialog) {
		dialog.overlay.fadeIn('fast', function () {
			dialog.data.show();
			dialog.container.show('slide', { direction:'up' }, 'slow', function() {
				//dialog.data.fadeIn('fast');
			})		
		})
	},
	onClose: function(dialog) {
		dialog.container.fadeOut('fast', function () {
			dialog.overlay.fadeOut('fast', function() {
				$.modal.close();
			})		
		})
	}
});

function googlecartBeforeRemove(item, index, newQuantity) {
	window.setTimeout(smallCartUpdateQuantity, 1000);
	return true;
}
	
function googlecartAfterAdd() {
	googlecart.expungeMarkedForRemoval()
	$("#googlecart-widget").modal({
		persist:true, 
		containerId:'googlecart-container',
		position: [32,525]
	});
  smallCartUpdateQuantity();
}

function smallCart() {
	googlecartWidget.open();
	googlecartAfterAdd();
	window.setTimeout(googlecartWidget.refresh, 1000);
}

function googlecartWidgetLoaded() {
	$('.cartHead').remove();
	$("<div class='cartHead'><div class='cartTitle'>Your Shopping Cart</div></div>").insertBefore("#googlecart-widget-head");
	$('.cartHeadImage').remove();
	$('.cartHead').append("<img class='cartHeadImage' src='cart-x.gif' />");
	$(".cartHeadImage").click(function () { 
      $.modal.close();
    });
	
	smallCartUpdateQuantity();
}

function smallCartUpdateQuantity() {
	var itemCount = googlecart.getTotalQuantity();
	if( itemCount > 0 ) {
		$('#smallCartItemCount').text(itemCount.toString());
		$("#smallCart").css("display","block");
	} else {
		$("#smallCart").css("display","none");
	}
}
