// JavaScript Document

 $(document).ready(
	function() {
		setUpProducts();

		$("ul.productList div.colorItem").live("click",
			function() {
				//remove the colorSelect class
				$(this).parents("li.ProductItem").find("div.colorItem").removeClass("colorSelect");
				//apply the colorSelect class
				$(this).addClass("colorSelect")
				//set the color                  
				$(this).parents("li.ProductItem").find("span.ColorHolder input").attr("value", $(this).attr("_value"));
			}

		);
		
		$("ul.productList a.goCart").live("click",
			function()
			{
				
				
				
				window.location.href = "viewcart.aspx";
				
				
				
			}
		);
		
		//wire up extpanels
		$("div.extPanel a").click(function(){
					
			//alert($(this).siblings("div.extPanel input.panelHtml").attr("value"));
			showModalOver($(this).siblings("div.extPanel input.panelHtml").attr("value"));
										   
		});

	});

    function setUpProducts() {


        //set defaults
        $.each($("li.ProductItem"),
                function() {





                    var colorValue = $(this).find("span.ColorHolder input").attr("value");

                    if (colorValue != null && colorValue.length > 0) {
                        //apply color if it exists
                        //--------------------------------------

                        //alert(colorValue);

                        $(this).find("div.colorItem[_value='" + colorValue + "']").addClass("colorSelect");


                    }
                    else {

                        //apply defaults if no color is selected
                        //--------------------------------------

                        //apply the color select class
                        $(this).find("div.colorItem:first").addClass("colorSelect");

                        //set the color
                        $(this).find("span.ColorHolder input").attr("value", $(this).find("div.colorItem:first").attr("_value"));


                    }


                }


        );
    }

    function showAddedToCart() {
        $("div.AddedToCart[_added=true]").fadeIn(100,
            function() {
                $(this).delay(1000).fadeOut(500);
            }
        );
		
		

    }

    function updatePanelComplete() {
        setUpProducts();
        showAddedToCart();
    }
	
	function showLargeImage(imagePath)
	{
		if (imagePath != null && imagePath.length > 0)
		{
			var target = window.open(imagePath,"largePicture","location=1,status=1,scrollbars=1,width=650,height=450");
			target.focus();
		}
		
	}
	
	function showModalImage(largePath)
	{
		showModalOver("<img src='" + largePath + "' border='0' style='display:inline;margin-top:30px;'/>");
	}



    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(updatePanelComplete);
