	// this scene 7 parameter must match the scene 7 parameter on /consumer/my_account/view_orders_content.jsp
	// make sure they match
	var relatedProdScene7Params = "?fmt=jpg&wid=150&hei=150&resmode=sharp2&op_usm=1,1,10,0";

	var PriceChanger = function() {
		return {
			changePrice: function(productId, sellable, skuId) {
				if (sellable == "true" && skuId) {
					$.get("/consumer/products/product_price_fragment.jsp", {id: productId, skuId: skuId}, function(data) {
						$(".cross-sell-product-"+productId).find("div.price").html(data);
					});
				}
			}
		};
	}();

	$(document).ready(function() {
		$(".product-size-selector").change(function() {
			var productId = $(this).parents("li.cross-sell-product:first").ident().replace(/cross-sell-/g,"");
        	var size = $(this).children(":selected").html().trim();
        	var color = null;
        	if ($(this).parents("li.cross-sell-product:first").find(".product-color-selector:first").length > 0) {
        		color = $(this).parents("li.cross-sell-product:first").find(".product-color-selector:first").find(":selected").html().trim();
        	}
        	SkuFinder.lookupImageForSku(productId, '', '', '', '', '', '', '', '', size, color, function(result) {
    			PriceChanger.changePrice(productId, result[2], result[3]);

    			if (result[0]) {
    				$("#cross-sell-image-"+productId).attr("src", result[0]+relatedProdScene7Params);
    				$("#cross-sell-image-"+productId).attr("alt", result[1]);
    			}
    			
    			if (result[3]) {
    				$("#"+productId).find(".buy-online-link").each(function() {
    					var qsp = new QueryStringParser();
    					$(this).attr("href", qsp.set($(this).attr("href"), "skuId", result[3]));
    				});
    			}
    			
    			if (result[4]) {
                	$("#cross-sell-"+productId).find(".product-size-selector").children("option:selected").removeAttr("selected");
                	$("#cross-sell-"+productId).find(".product-size-selector").children("option:[value="+result[4]+"]").attr("selected", "selected");
				}
        	});
        });

        $(".product-color-selector").change(function() {
        	var productId = $(this).parents("li.cross-sell-product:first").ident().replace(/cross-sell-/g,"");
        	var size = null;
        	if ($(this).parents("li.cross-sell-product:first").find(".product-size-selector:first").length > 0) {
        		size = $(this).parents("li.cross-sell-product:first").find(".product-size-selector:first").find(":selected").html().trim();
        	}
        	var color = $(this).children(":selected").html().trim();
        	SkuFinder.lookupImageForSku(productId, '', '', '', '', '', '', '', '', size, color, function(result) {
    			PriceChanger.changePrice(productId, result[2], result[3]);

    			if (result[0]) {
    				$("#cross-sell-image-"+productId).attr("src", result[0]+relatedProdScene7Params);
    				$("#cross-sell-image-"+productId).attr("alt", result[1]);
    			}
    			
    			if (result[3]) {
    				$("#"+productId).find(".buy-online-link").each(function() {
    					var qsp = new QueryStringParser();
    					$(this).attr("href", qsp.set($(this).attr("href"), "skuId", result[3]));
    				});
    			}
    			
    			if (result[4]) {
                	$("#cross-sell-"+productId).find(".product-size-selector").children("option:selected").removeAttr("selected");
                	$("#cross-sell-"+productId).find(".product-size-selector").children("option:[value="+result[4]+"]").attr("selected", "selected");
				}
        	});
        });

        $(".swatch").click(function() {

            var productId = $(this).parents("li.cross-sell-product:first").ident().replace(/cross-sell-/g,"");
            var size = null;
            if ($(this).parents("li.cross-sell-product:first").find(".product-size-selector:first").length > 0) {
	            size = $(this).parents("li.cross-sell-product:first").find(".product-size-selector:first").find(":selected").text();
	            size = $.trim(size);
            }
            var color = $(this).attr("id");
            $(this).parents("li.cross-sell-product:first").find(".product-color-selector:first").val(color);

            SkuFinder.lookupImageForSku(productId, '', '', '', '', '', '', '', '', size, color, function(result) {
                PriceChanger.changePrice(productId, result[2], result[3]);
                if (result[0]) {
                    $("#cross-sell-image-"+productId).attr("src", result[0]+relatedProdScene7Params);
                    $("#cross-sell-image-"+productId).attr("alt", result[1]);
                }
                
                if (result[3]) {
    				$("#"+productId).find(".buy-online-link").each(function() {
    					var qsp = new QueryStringParser();
    					$(this).attr("href", qsp.set($(this).attr("href"), "skuId", result[3]));
    				});
    			}
                
                if (result[4]) {
                	$("#cross-sell-"+productId).find(".product-size-selector").children("option:selected").removeAttr("selected");
                	$("#cross-sell-"+productId).find(".product-size-selector").children("option:[value="+result[4]+"]").attr("selected", "selected");
				}
            });
            return false;
        });


	});