/*
	Opens a new window with the provided url and dimension. Used
	for Scene7 and other situations.

	@param url the url to open
	@param width the window width
	@param height the window height
*/
function openPopup( url, width, height )
{
	if (url != null)
	{
		if (width != null && height != null)
		{
			window.open(url, "", "width=" + width +", height=" + height +", scrollbars=no, resizable=yes");
		}
		else
		{
			window.open(url, "", "scrollbars=no, resizable=yes");
		}
	}
}
/* function to update parent opener */
function setOpener( url )
{
	window.opener.location.href = url;
}

/*
 * Support for the compare window
*/
ProductCompare = {
	openPopup: function( url ) {
		window.open(
			url,
			'product_compare',
			'width=800,height=600,scrollbars=yes,resizable=yes',
			true /* replace history in the popped up window */
		).focus();
	}
}


/*
 * Functionality around the mini cart.
 */
var MiniCart = {
	// flag, whether cart is open or not
	state: 0,

	// during page loading, the Demandware URL is stored here
	url: '',

	// timer for automatic close of cart item view
	timer: null,

	cartAdd: function( form, progressImageSrc )
	{
	    var oldsrc = jQuery(".cart_button").attr("src");
		var postdata = jQuery( "#" + form ).serialize();
		jQuery.ajax({
		  type: "post",
		  url: MiniCart.url,
		  data: postdata,
		  beforeSend: function() {
		  	jQuery(".cart_button").attr("src",progressImageSrc).attr("disabled","disabled");
		  },
		  success: function(data,textStatus) {
		    jQuery(".cart_button").attr("src",oldsrc).removeAttr("disabled");
		  	jQuery("#minicart").html( data );
		  	jQuery("#mc_content").slideDown();
			MiniCart.timer = setTimeout( 'MiniCart.cartClose()', 10000 );
		  }
		});
		return false;
	},

	cartClose: function()
	{
		if ( MiniCart.timer != null )
		{
			clearTimeout( MiniCart.timer );
			MiniCart.timer = null;
			jQuery("#mc_content").slideUp();
		}
	},

	// hook which can be replaced by individual pages/page types (e.g. cart)
	suppressSlideDown: function()
	{
		return false;
	}
}