function Item(itemId, name, description, color, shortcutUrl, hasCustomization)
{
    this.itemId = itemId;
    this.name = name;
    this.description = description;
    this.color=color;
    this.subitems = new Array();
    this.images = new Array();
    this.shortcutUrl=shortcutUrl;
    this.hasCustomization=hasCustomization;
}
Item.prototype.group;
Item.prototype.currentSubitem;
Item.prototype.preloadedImages;

Item.prototype.AddSubitem = function(objSubitem)
{
    objSubitem.item=this;
    this.subitems[this.subitems.length]=objSubitem;
    this.subitems.sort(this.SubitemSizeCompare);
}
Item.prototype.AddImage = function(objImage)
{
  this.images[this.images.length] = objImage;
}
Item.prototype.GetImagesByType = function(strType)
{
  var resImages = new Array();
  for(ct=0; ct<this.images.length; ct++)
  {
    if (this.images[ct].type==strType)
      resImages[resImages.length] = this.images[ct];
  }
  
  return resImages;
}
Item.prototype.GetImage = function(strType, strName)
{
  var resImages = new Array();
  for(itemCT=0; itemCT<this.images.length; itemCT++)
  {
    if (this.images[itemCT].type==strType && this.images[itemCT].name==strName)
      return this.images[itemCT];
  }
  
  return null;
}
Item.prototype.PreloadImages = function()
{
    this.preloadedImages = new Array();
    for (itemCT=0; itemCT<this.images.length; itemCT++)
    {
        this.preloadedImages[itemCT] = new Image();
        this.preloadedImages[itemCT].src = this.images[itemCT].path;
    }
    
}



Item.prototype.FindSubitem = function(subitemId)
{
    for (itemCT=0; itemCT<this.subitems.length; itemCT++)
    {
        if (this.subitems[itemCT].subitemId==subitemId)
            return this.subitems[itemCT];
    }
    
    return null;
}

Item.prototype.SubitemSizeCompare = function(a, b)
{
    if (!isNaN(a.size) || !isNaN(b.size))
    {
        var asize = parseFloat(a.size);
        var bsize = parseFloat(b.size);
        if (asize<bsize)
            return -1;
        if (asize==bsize)
            return 0;
        if (asize>bsize)
            return 1;
    }
    else
    {
        if (a.size.toString()<b.size.toString())
            return -1;
        if (a.size.toString()==b.size.toString())
            return 0;
        if (a.size.toString()>b.size.toString())
            return 1;
    }
}

Item.prototype.GetMinPrice = function()
{
    minPrice=0;
    for (itemCT=0; itemCT<this.subitems.length; itemCT++)
    {
        if (itemCT==0)
            minPrice = this.subitems[itemCT].price;
            
        if (minPrice>this.subitems[itemCT].price)
            minPrice = this.subitems[itemCT].price;
    }
    return minPrice
}
Item.prototype.GetMaxPrice = function()
{
    maxPrice=0;
    for (itemCT=0; itemCT<this.subitems.length; itemCT++)
    {
        if (maxPrice<this.subitems[itemCT].price)
            maxPrice = this.subitems[itemCT].price;
    }
    return maxPrice;
}
Item.prototype.GetMinOriginalPrice = function()
{
    minPrice=0;
    for (itemCT=0; itemCT<this.subitems.length; itemCT++)
    {
        if (itemCT==0)
            minPrice = this.subitems[itemCT].originalprice;
            
        if (minPrice>this.subitems[itemCT].originalprice)
            minPrice = this.subitems[itemCT].originalprice;
    }
    
    return minPrice;
}

Item.prototype.GetMaxOriginalPrice = function()
{
    maxPrice=0;
    for (itemCT=0; itemCT<this.subitems.length; itemCT++)
    {
        if (maxPrice<this.subitems[itemCT].originalprice)
            maxPrice = this.subitems[itemCT].originalprice;
    }
    return maxPrice;
}

Item.prototype.GetPriceHtml = function()
{
    priceHtml = "";
    if (this.GetMinOriginalPrice()!=this.GetMinPrice() || this.GetMaxOriginalPrice()!=this.GetMaxPrice() || this.GetMinOriginalPrice()!=this.GetMaxPrice() || this.GetMaxOriginalPrice()!=this.GetMinPrice())
    {
        priceHtml += "<span style='color:red;background-image:url(//delmanshoes.com/assets/layout/strike.gif);background-repeat:repeat-x;background-position:0% 5px;'>";
        if (this.GetMinOriginalPrice()!=this.GetMaxOriginalPrice())
        {
            priceHtml += "$" + this.GetMinOriginalPrice() + " - $" + this.GetMaxOriginalPrice();
        }
        else
        {
            priceHtml += "$" + this.GetMinOriginalPrice();
        }
        priceHtml += "</span> ";
    }
    if (this.GetMinPrice()!=this.GetMaxPrice())
        priceHtml += "$" + this.GetMinPrice() + " - $" + this.GetMaxPrice();
    else
        priceHtml += "$" + this.GetMinPrice();
        
    return priceHtml;
    
}

Item.prototype.GetPreorderMessage = function()
{
    dtmAvailable = this.GetDateAvailable();
    strMessage = "The " + this.name + " is currently available to pre-order. Place your order now and it will be shipped no later than " + (dtmAvailable.getMonth()+1) + "/" + dtmAvailable.getDate() + "/" + dtmAvailable.getFullYear() + ". <br /> *Please note that your card will not be charged for this transaction until the item is shipped.";
    return strMessage;
}

Item.prototype.IsBackordered = function()
{
    for (itemCT=0; itemCT<this.subitems.length; itemCT++)
    {
        if (this.subitems[itemCT].backordered)
            return true;
    }
    return false;
}

Item.prototype.GetDateAvailable = function()
{
    dateAvailable = this.subitems[0].availabledate;
    for (itemCT=0; itemCT<this.subitems.length; itemCT++)
    {
        if (this.subitems[itemCT].availabledate>dateAvailable)
            dateAvailable=this.subitems[itemCT].availabledate;
    }

    return dateAvailable;
}
