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;
    this.currentView="Main";
}
Item.prototype.group;
Item.prototype.currentSubitem;
Item.prototype.preloadedImages;
Item.prototype.currentView;
Item.prototype.longDescription;
Item.prototype.var2;

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(http://assets.kompo.com/SteveMadden/layout/strike.gif);background-repeat:repeat-x;background-position:0% 5px;'>";
        if (this.GetMinOriginalPrice()!=this.GetMaxOriginalPrice())
        {
            priceHtml += "$" + CurrencyFormatted(this.GetMinOriginalPrice()) + " - $" + CurrencyFormatted(this.GetMaxOriginalPrice());
        }
        else
        {
            priceHtml += "$" + CurrencyFormatted(this.GetMinOriginalPrice());
        }
        priceHtml += "</span> ";
    }
    if (this.GetMinPrice()!=this.GetMaxPrice())
        priceHtml += "$" + CurrencyFormatted(this.GetMinPrice()) + " - $" + CurrencyFormatted(this.GetMaxPrice());
    else
        priceHtml += "$" + CurrencyFormatted(this.GetMinPrice());
        
    return priceHtml;
    
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	str = new String(i);
	if(str.indexOf('.') < 0) { str += '.00'; }
	if(str.indexOf('.') == (str.length - 2)) { str += '0'; }
	str = minus + str;
	return str;
}


Item.prototype.GetPreorderMessage = function()
{
    dtmAvailable = this.GetDateAvailable();
    strMessage = "Expected Ship Date: " + (dtmAvailable.getMonth()+1) + "/" + dtmAvailable.getDate() + "/" + dtmAvailable.getFullYear() + ".<br />Please note your card will not be charged until the item has shipped.";
    return strMessage;
}

Item.prototype.GetShippingInfo = function()
{    
    return "Usually Ships Next Business Day";
}

Item.prototype.IsBackordered = function()
{
    for (itemCT=0; itemCT<this.subitems.length; itemCT++)
    {
        if (this.subitems[itemCT].backordered)
            return true;
    }
    return false;
}

Item.prototype.IsCurrentSubItemBackordered = function()
{
    if (typeof(this.currentSubitem) == "string" && this.currentSubitem != "" && this.currentSubitem != "-1")
    {
        var subitem = this.FindSubitem(this.currentSubitem);
        return subitem.backordered;
    }

    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;
}
