    var products = new Products();
    
    Product.prototype = {
        FindByVariant: function(color, systemType)
        {
            for (i = 0; i < this.Variations.length; i++)
                if (color == this.Variations[i].Attributes["Color"] && systemType == this.Variations[i].Attributes["Type"])
                    return this.Variations[i];
        }
    }

    $(document).ready(function () {
        if (typeof ('InitPage') == 'function') { InitPage(); }

        $("#categorySortLabel").addClass("rounded-corners");
        $("#categorySortFirst").addClass("rounded-corners-left");
        $("#categorySortLast").addClass("rounded-corners-right");
    });

	function DisplayVariant(productId, selectedVariant) {
	
	    $("tr.Prod" + productId).find("span.ProductPrice").html(selectedVariant.Price);
	    $("tr.Prod" + productId).find("span.color").html(selectedVariant.Attributes["Color"]);

	    $("tr.Prod" + productId).find(".SkuImage img").hide();
	    $("tr.Prod" + productId).find(".SkuImage img").attr("src", selectedVariant.ImageUrl);
	    $("tr.Prod" + productId).find(".SkuImage img").fadeIn();
	    $("tr.Prod" + productId).find(".SkuImage").attr("href", selectedVariant.ViewDetailsLink);
	    
	    $("tr.Prod" + productId).find("a.ViewDetailsLink").attr("href", selectedVariant.ViewDetailsLink);
	    $("tr.Prod" + productId).find("a.ProductName").attr("href", selectedVariant.ViewDetailsLink);

	    if (selectedVariant.AddToCartLink != "") {
	        $("tr.Prod" + productId).find("a.AddToCartLink").attr("rel", selectedVariant.Id);
	        $("tr.Prod" + productId).find("a.AddToCartLink").show();
	    } else {
	        $("tr.Prod" + productId).find("a.AddToCartLink").attr("rel", "");
	        $("tr.Prod" + productId).find("a.AddToCartLink").hide();
	    }
	    
	    $("tr.Prod" + productId).find(".StockMessage").html(selectedVariant.StockMessage); 	    
	    
	}

	function ChangeVariantColor(productId, color) {
	    var currentType = GetCurrentSystemType(productId);
	    var selectedVariant = products.Find(productId).FindByVariant(color, currentType);
	    DisplayVariant(productId, selectedVariant);
	}
	
    function ChangeVariantSystemType(sender, productId, systemType)
    {
        ResetSystemTypeButtons(productId);
        SetSelectedSystemType(sender, productId, systemType)
        var currentColor = GetCurrentSystemColor(productId);
        var selectedVariant = products.Find(productId).FindByVariant(currentColor, systemType);
        DisplayVariant(productId, selectedVariant);
    }

	function GetCurrentSystemColor(productId)
	{
	    var rows = $("tr.Prod" + productId);
	    return rows.find("span.color").text();
	}

