function largeImage(src) {	
	swapImage("largeProductImage", src);
	$("#largeProductImageContainer").center().show();
	document.body.className = "largeImage";

}
function hideLargeProductImage() {
    $("#largeProductImageContainer").hide();
}
var originalPriceText = "";

function selectSize(sku, size, price) {
    if (sku != null) {
        if (sku != "null") {
            $("#sku").val(sku);
        }
        $("#cart-sku").val(sku);
    }
    
    $.$("qty").disabled = false;
    if (price) {
        if (originalPriceText.length == 0) {
            originalPriceText = $("#price").html();
        }
        $("#price").html(price);
    }

    $("#qty").val("1");

    cart.choose();
    
//    $("#addtobasketbutton").unbind("click").click(function() {
//        cart.addFromQtyDdl(sku, "qty");
//    });     
    
    $("#addtobasket").center(true).show();            
}


function change() {
    $("#vid").val("");
	$.$("pcontent").className = "";
	$.$("qty").disabled = true;

	$("#addedToBasketContainer").hide();
//	if ($.$("addedToBasketContainer") != null) {
//		$.$("addedToBasketContainer").style.display = "none";
//	}
	if (originalPriceText.length > 0) {
	    $("#price").html(originalPriceText);
	}
}

/* sets add to basket as onclick */
function checkStock(el, button, rowId, qty) {
	stockText = el.options[el.selectedIndex].text.toLowerCase();
	$.$(button).style.visibility = (stockText.indexOf("sold out") > -1 || el.selectedIndex == 0) ? "hidden" : "visible";
	
	if (stockText.indexOf("sold out") == -1 && el.selectedIndex > 0) {
	    $.$(button).onclick = function() {
	        if ($.$(qty).options[$.$(qty).selectedIndex].value == "0") {
	            alert("You must select a quantity");
	            return false;
	        }
	        cart.addFromQtyDdl(el.options[el.selectedIndex].value, qty);
	        //event.cancelBubble = true;
	        window.cancelBubble = true;
	        return false;
	    }
	}
	
	//show - inform me when in stock button?
	/*row = $("row"+rowId);
	if (row && row.className != null) {
		row.className = row.className == "added" ? "dissolve" : row.className != "dissolve" ? "" : "dissolve";
	}*/
}

function zoomImage() {
    url = ROOT_URL + "products/imagezoom.aspx?style=" + _productId + "&colour=" + _colour;
    //prompt("", url);
    width = window.screen.width - 10;
    height = window.screen.height - 60;
    extra = "top=0,left=0";
    return popupWindow(url, width, height, extra) 
}

function swapProductImage(src) {
	swapImage("productImage", src);		
}

function garmentInfo(elId) {
    var _url = ROOT_URL + "products/glossary.xml";
    //alert(_url);
    $.get(_url, function() {
        showGarmentInfo(data, elId);
    });   
    return false;
}

function getInnerText(node) {
    if (typeof node.textContent != 'undefined') {
        return node.textContent;
    }
    else if (typeof node.innerText != 'undefined') {
        return node.innerText;
    }
    else if (typeof node.text != 'undefined') {
        return node.text;
    }
    else {
        switch (node.nodeType) {
            case 3:
            case 4:
            return node.nodeValue;
            break;
            
            case 1:
            case 11:
            var innerText = '';
            for (var i = 0; i < node.childNodes.length; i++) {
                innerText += getInnerText(node.childNodes[i]);
            }
            return innerText;
            break;
            
            default:
            return '';
        }
    }
}

function showGarmentInfo(xmldoc, elId) {
    var isMSIE = $.browser.msie;
    var html = "";
    var _title = "";
    var _desc = "";

	if (isMSIE) {
	    for (i=0; i<xmldoc.documentElement.childNodes.length; i++) {
	        n = xmldoc.documentElement.childNodes[i];
	        if (n.tagName == "term" && n.getAttribute("id") == elId) {
	            for (j=0; j<n.childNodes.length; j++) {
	                nn = n.childNodes[j];
	                if (nn.tagName == "name") {
	                    _title = nn.text;
	                } else if (nn.tagName == "description") {
	                    _desc = nn.xml;
	                }
	            }
	        }
	    }      	    
	} else {
	    for (i=0; i<xmldoc.childNodes[0].childNodes.length; i++) {
	        n = xmldoc.childNodes[0].childNodes[i];
	        if (n.tagName == "term" && n.getAttribute("id") == elId) {
	            for (j=0; j<n.childNodes.length; j++) {
	                nn = n.childNodes[j];
	                if (nn.tagName == "name") {
	                    _title = nn.textContent;
	                } else if (nn.tagName == "description") {
                        var serializer = new XMLSerializer();
	                    _desc = serializer.serializeToString(nn);
	                }
	            }
	        }
	    }
	}
	
	html = "<h4>" + _title + "</h4>" + _desc;
	$("#garmentinfocontent").html(html);
    $("#garmentinfo").center().show();
}

function hideGarmentInfo() {
    $("#garmentinfo").hide();
}


/* depricated */
function initWishList() {
    page.ratings();
}

document.write("<style type=\"text/css\">.ajaxbutton { display: inline; }</style>");

