function changeservices(which){
	var thelinkid = document.getElementById(which);
	var thedescid = document.getElementById(which + '-Description');
	var theimageid = document.getElementById('servicesimage');
	
	try{eval(thePrevLinkThatChanged);}
	catch(e) {
		thePrevLinkThatChanged = document.getElementById(which);
		thePrevDescThatChanged = document.getElementById(which + '-Description');		
	}
	
	thelinkid.className = 'selected';
	thedescid.style.display = 'block';
	theimageid.src = "images/servicesimages/" + which + ".jpg";
	
	if (thelinkid != thePrevLinkThatChanged) {
		thePrevLinkThatChanged.className = '';
		thePrevDescThatChanged.style.display = 'none';
		
		thePrevLinkThatChanged = document.getElementById(which);
		thePrevDescThatChanged = document.getElementById(which + '-Description');
	}else {
	}
}
function RequestYarn(which) {
    var oColor = $('.' + which).val();
    //if (oColor != "") {
        location.href = 'contact.aspx?Mess=I would like to request a yarn sample of ' + oColor;
    //}
}
function CheckQuantity(productId, selColor, oRel) {
    /*var oRel = $(this).attr('rel');
    var oSelQty = $(this).val();
    //alert(oRel + " :: " + oSelQty);
    if (oSelQty == "0" || oSelQty == 0) {
        $('.pAddCart' + oRel).fadeOut(250, function() {
            $('.pSoldOut' + oRel).fadeIn(250);
        });
    } else {
        $('.pSoldOut' + oRel).fadeOut(250, function() {
            $('.pAddCart' + oRel).fadeIn(250);
        });
    }*/
    $.ajax({
        type: "GET",
        url: "/WebService.asmx/CheckQuantity?productId=" + productId + "&selColor=" + selColor,
        cache: false,
        success: function(data) {
            //alert('.pAddCart' + oRel + " :: " + productId + " :: " + $('boolean', data).text().toLowerCase());
            if ($('boolean', data).text().toLowerCase() == "false") {
                //try
                //{
                    $('.pAddCart' + oRel).fadeOut(250, function() {
                        $('.pSoldOut' + oRel).fadeIn(250);
                    });
                //}
                //catch
                //{
                //    $('.pSoldOut' + oRel).fadeIn(250);
                //}
            } else {
                //try
                //{
                    $('.pSoldOut' + oRel).fadeOut(250, function() {
                        $('.pAddCart' + oRel).fadeIn(250);
                    });
                //}
                //catch
                //{
                //    $('.pAddCart' + oRel).fadeIn(250);
                //}
            }
        }
    });
}

$(document).ready(function() {
    $('.ddlcolors').change(function() {
        var oRel = $(this).attr('rel');
        var oSelColor = $(this).val();
        CheckQuantity(oRel.replace('ddl', ''), oSelColor, oRel);
        /*
        var oRel = $(this).attr('rel');
        var oSelQty = $(this).val();
        //alert(oRel + " :: " + oSelQty);
        if (oSelQty == "0" || oSelQty == 0) {
        $('.pAddCart' + oRel).fadeOut(250, function() {
        $('.pSoldOut' + oRel).fadeIn(250);
        });
        } else {
        $('.pSoldOut' + oRel).fadeOut(250, function() {
        $('.pAddCart' + oRel).fadeIn(250);
        });
        }*/
    });
    $('#shopspace div.entry:last .description').css('width', '164px');
    $("#chkSameAsBilling").change(function() {
        if (this.checked) {
            $("#ctl00_ContentPlaceHolder2_txtShipToName").val($("#ctl00_ContentPlaceHolder2_txtBillingName").val());
            $("#ctl00_ContentPlaceHolder2_txtShipToAddress1").val($("#ctl00_ContentPlaceHolder2_txtBillingAddress1").val());
            $("#ctl00_ContentPlaceHolder2_txtShipToAddress2").val($("#ctl00_ContentPlaceHolder2_txtBillingAddress2").val());
            $("#ctl00_ContentPlaceHolder2_txtShipToCity").val($("#ctl00_ContentPlaceHolder2_txtBillingCity").val());
            $("#ctl00_ContentPlaceHolder2_cboShipToState").val($("#ctl00_ContentPlaceHolder2_cboBillingState").val());
            $("#ctl00_ContentPlaceHolder2_txtShipToZip").val($("#ctl00_ContentPlaceHolder2_txtBillingZip").val());
        } else {

        }
    });


    //mainproductimage
    $('.shopimage p img').click(function() {
        var newImg = $(this).attr('src').replace('_small.', '_large.');
        var imgRel = $(this).attr('rel');
        var oName = 'div_' + $(this).attr('name');

        $('.' + oName + ' #photoTextInfo').animate({ "height": ($('.' + oName + ' .mainproductimage').height() + 54) }, { duration: "slow" });

        $('.' + oName + ' .photoTextDiv').fadeOut(250);
        $('.' + oName + ' .mainproductimage').fadeOut(250, function() {
            $('.' + oName + ' #entwineloader').fadeIn(250);
            $('.' + oName + ' .mainproductimage').attr('src', newImg);
            $('.' + oName + ' .photoTextDiv').text(imgRel);
            $('.' + oName + ' #entwineloader').fadeOut(1000, function() {
                $('.' + oName + ' .mainproductimage').fadeIn("slow", function() {
                    $('.' + oName + ' #photoTextInfo').animate({ "height": ($('.' + oName + ' .mainproductimage').height() + 54) }, { duration: "slow" });
                });
                $('.' + oName + ' .mainproductimage').fadeIn("slow");
                $('.' + oName + ' .photoTextDiv').fadeIn(250);
            });
        });
    });


});
