
Product.prototype.getDetailId = Product_getDetailId;
Product.prototype.setDetailId = Product_setDetailId;
Product.prototype.getDetail = Product_getDetail;
Product.prototype.getCurrentDetail = Product_getCurrentDetail;

Product.prototype.getDetailImageId = Product_getDetailImageId;
Product.prototype.setDetailImageId = Product_setDetailImageId;

Product.prototype.showDetailView = Product_showDetailView;
Product.prototype.hideDetailView = Product_hideDetailView;
Product.prototype.setDetailView = Product_setDetailView;

Product.prototype.getSliceId = Product_getSliceId;
Product.prototype.setSliceId = Product_setSliceId;
Product.prototype.getSlice = Product_getSlice;

Product.prototype.getSize = Product_getSize;
Product.prototype.getShipWindow = Product_getShipWindow;
Product.prototype.getAvailFlag = Product_getAvailFlag;
Product.prototype.updateSizes = Product_updateSizes;
Product.prototype.sizeChange = Product_sizeChange;

Product.prototype.getSelectedSku = Product_getSelectedSku;

Product.prototype.isValid = Product_isValid;

function Product(id, acIndex)
{
    this.productId = id;
    this.currentSliceId = "slice0";
    this.currentDetailId = "detail0";
    this.currentDetailImageId = "detail0";
    this.currentSize = null;
    this.acIndex = acIndex;
}

function Product_getDetailId()
{
    return this.currentDetailId;
}

function Product_setDetailId(detailId)
{
    this.currentDetailId = detailId;
}

function Product_getDetail(detailId)
{
    return productData[this.productId].details[detailId];
}

function Product_getCurrentDetail()
{
    return this.getDetail(this.currentDetailId);
}

function Product_getDetailImageId()
{
    return this.currentDetailImageId;
}

function Product_setDetailImageId(detailImageId)
{
    this.currentDetailImageId = detailImageId;
}

function Product_showDetailView(detailId)
{
    swapElements(
            this.productId + this.getDetailImageId() + "Main",
            this.productId + detailId + "Main"
            );
}

function Product_hideDetailView(detailId)
{
    swapElements(
            this.productId + detailId + "Main",
            this.productId + this.getDetailImageId() + "Main"
            );
}

function Product_setDetailView(detailId)
{
    var detailImageId = detailId;
    var detail = this.getDetail(detailId);
    if(detail && detail.isFront)
    {
        detailImageId = this.getSliceId();
    }
    swapElements(
            this.productId + this.getDetailImageId() + "Main",
            this.productId + detailImageId + "Main"
        );
    swapClass(
            this.productId + this.getDetailId() + "DetailThumb",
            this.productId + detailId + "DetailThumb",
            "on"
        );
    this.setDetailId(detailId);
    this.setDetailImageId(detailImageId);
}

function Product_getSliceId()
{
    return this.currentSliceId;
}

function Product_setSliceId(sliceId)
{
    this.currentSliceId = sliceId;
}

function Product_getSlice()
{
    var slice = null;
    if(this.currentSliceId)
    {
        return productData[this.productId].slices[this.currentSliceId];
    }
    return slice;
}

function Product_getSize()
{
    return this.currentSize;
}

function Product_getShipWindow()
{
    var shipWindow = null;
    var selectedSku = this.getSelectedSku();
    if(selectedSku)
    {
        var slice = this.getSlice();
        shipWindow = slice.shipWindow[selectedSku].shipWindowMsg;
    }
    return shipWindow;
}

function Product_getAvailFlag()
{
    var availFlag = null;
    var selectedSku = this.getSelectedSku();
    if(selectedSku)
    {
        var slice = this.getSlice();
        availFlag = slice.skuMap[selectedSku].availFlag;
    }
    return availFlag;
}

function Product_updateSizes()
{
    var sizeEl = document.getElementById(this.productId + "Sku");
    var slice = this.getSlice();
    var skuMap = slice.skuMap;
    if(slice.hasSizes)
    {
        var options = sizeEl.options;
        options.length = 1;
        for(var sku in skuMap)
        {
            var size = skuMap[sku].size;
            var opt = new Option();
            options[options.length] = opt;
            opt.innerHTML = size;
            opt.value = sku;
            if(size == this.currentSize)
            {
                opt.selected = true;
            }
        }
        if(this.currentSize == null)
        {
            options[0].selected = true;
        }
    }
    else
    {
        for(var sku in skuMap)
        {
            sizeEl.value = sku;
        }
    }
}

function Product_sizeChange()
{
    var selectedSku = this.getSelectedSku();
    if(selectedSku)
    {
        var slice = this.getSlice();
        this.currentSize = slice.skuMap[selectedSku].size;
    }
    else
    {
        this.currentSize = null;
    }
}

function Product_getSelectedSku()
{
    var el = document.getElementById(this.productId + "Sku");
    if(el.selectedIndex == 0)
    {
        return null;
    }
    return el.value;
}

function Product_isValid()
{
    var slice = this.getSlice();
    if(slice && (!slice.hasSizes || (slice.hasSizes && this.currentSize)))
    {
        return true;
    }
    return false;
}

