    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(){
	    InitPage();
	    
	    $("#categorySortLabel").corner("round 10px");
	    $("#categorySortFirst").corner("round 10px tl bl");
	    $("#categorySortLast").corner("round 10px tr br");	
	});

	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.AddToCartLink").attr("href", selectedVariant.AddToCartLink);
	    $("tr.Prod" + productId).find("a.ViewDetailsLink").attr("href", selectedVariant.ViewDetailsLink);
	    $("tr.Prod" + productId).find("a.ProductName").attr("href", selectedVariant.ViewDetailsLink);
	    $("tr.Prod" + productId).find("a.AddToCartLink").attr("style", selectedVariant.VisibleStatus);
	}

	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();
	}
