var CollectionObj=Class.create({initialize:function(collectionData){this.collectionData=collectionData;this.collectionParent=new Object();this.collectionChildren=new Array();if(this.collectionData!=undefined){this.setCollectionParent();this.setCollectionChildren()}},setCollectionParent:function(){if(this.collectionData.collectionParent!=undefined){try{this.collectionParent=new ParentObj(this.collectionData.collectionParent)}catch(e){}}},setCollectionChildren:function(){if(this.collectionData.products!=undefined){for(var item in this.collectionData.products){this.collectionChildren[item]=new ParentObj(this.collectionData.products[item])}}},getCollectionChild:function(asin){return this.collectionChildren[asin]},getCollectionChildren:function(){return this.collectionChildren},getCollectionParent:function(){return this.collectionParent}});var ParentObj=Class.create({initialize:function(detailInfo){this.colorData=[];this.asinData=[];this.currentAsinData=new Object();this.sizeColorMap=new Object();this.sizeList=new Object();this.priceMap=[];this.detailData=detailInfo;try{this.loadAsinInfo()}catch(e){}try{this.loadPriceMap()}catch(e){}try{this.loadColorData()}catch(e){}try{this.loadSizeColorMap()}catch(e){}try{this.loadSizes()}catch(e){}try{this.currentAsinData=new AsinObj(this.detailData.currentAsinData)}catch(e){}},loadAsinInfo:function(){for(var asin in this.detailData.asinData){this.asinData[asin]=new AsinObj(this.detailData.asinData[asin])}},loadColorData:function(){for(var color in this.detailData.colorData){this.colorData[color]=new AsinObj(this.detailData.colorData[color])}},loadSizeColorMap:function(){this.sizeColorMap=new SizeColorMap(this.detailData.sizeColorMap)},loadPriceMap:function(){try{for(var asin in this.detailData.asinData){this.priceMap[this.detailData.asinData[asin].FormattedPrice.replace(/\.00$/,"").replace(/\$/,"")]=this.getAsinData(asin)}}catch(e){}},loadSizes:function(){this.sizeList=new Sizes(this.detailData.sizeList)},getCurrentAsinData:function(){return this.currentAsinData},getAsinData:function(Asin){return this.asinData[Asin]},getColor:function(color){var colorInfo=this.colorData[color];if(colorInfo==undefined||(colorInfo.getMainImage()==undefined&&colorInfo.getMainImage()!="")){colorInfo=this.currentAsinData}return colorInfo},getPriceAsin:function(Price){return this.priceMap[Price]},getSizeColorAsin:function(size,color){var asin=this.sizeColorMap.getItemAsin(size,color);return this.asinData[asin]},isAllChildrenEMWA:function(){var hasEmwaItem=false;for(var color in this.colorData){if(typeof this.colorData[color]=="function"||typeof this.colorData[color]=="undefined"){continue}var sizes=this.colorData[color].getSizes();for(var size in sizes){if(typeof sizes[size]=="function"||typeof sizes[size]=="undefined"){continue}var asin=this.sizeColorMap.getItemAsin(sizes[size],color);var product=this.asinData[asin];var isEmwa=(product.getEMWAEnabled()&&product.getOutOfStock()&&(product.getOfferId()==""||product.getOfferId()==undefined));if(!isEmwa){return false}else{hasEmwaItem=true}}}return hasEmwaItem}});var Sizes=Class.create({initialize:function(sizeArray){this.sizeArray=new Array;for(var i=0;i<sizeArray.length;i++){if(this.sizeArray.indexOf(sizeArray[i])==-1){this.sizeArray.push(sizeArray[i])}}},getSizes:function(){return this.sizeArray}});var SizeColorMap=Class.create({initialize:function(colorMap){this.colorMap=colorMap},getItemAsin:function(size,color){var key=size+"_"+color;return this.colorMap[key]},toString:function(tabs){tabs=tabs!=undefined?tabs:"\t";var info=tabs+"[\n";info=info+tabs+"I AM AN ASIN OBJECT, \n";info=info+tabs+"].SizeColorMap\n";return info}});var AsinObj=Class.create({initialize:function(asinInfo){this.asinInfo=asinInfo;this.hasRichMedia=this.getHasRichMedia();this.images=this.setMainImages()},getAsin:function(){return this.asinInfo.Asin},getBrandName:function(){return this.asinInfo.BrandName},getColor:function(){return this.asinInfo.color},getDescription:function(){return this.asinInfo.Description},getDisplayOnlyPrice:function(){return this.asinInfo.DisplayOnlyPrice},getEMWAEnabled:function(){return this.asinInfo.emwaEnabled},getFeatures:function(){return this.asinInfo.Features},getFormattedBuyingPrice:function(){return this.asinInfo.formattedBuyingPrice},getFormattedListPrice:function(){return this.asinInfo.formattedListPrice},getFormattedPrice:function(){return this.asinInfo.FormattedPrice},getFormattedSalePrice:function(){return this.asinInfo.FormattedSalePrice},getIsAsinAvailable:function(){return this.asinInfo.isAsinAvailable},getIsBuyable:function(){return this.asinInfo.IsBuyable},getIsEmailMeWhenAvailable:function(){return this.asinInfo.isEmailMeWhenAvailable},getMainImage:function(){return this.images.main},getMerchantSku:function(){return this.asinInfo.MerchantSku},getOfferId:function(){return this.asinInfo.offerId},getOutOfStock:function(){return this.asinInfo.outOfStock},getPriceLabel:function(){return this.asinInfo.priceLabel},getRichMediaImages:function(){return this.asinInfo.richMediaImages},getSeoDescription:function(){return this.asinInfo.SeoDescription},getShortAvailabilityMessage:function(){return this.asinInfo.ShortAvailabilityMessage},getScarcityMessage:function(){return this.asinInfo.scarcityMessage},getSize:function(){return this.asinInfo.size},getSizes:function(){return this.asinInfo.sizes},getSwatchImages:function(){return this.asinInfo.swatchImages},getTitle:function(){return this.asinInfo.Title},getVariantList:function(){return this.variantList},getVariantImage:function(variant){return this.images[variant]},getYouSaveAmount:function(){return this.asinInfo.youSaveAmount},getYouSavePercent:function(){return this.asinInfo.youSavePercent},getHasRichMedia:function(){if(this.hasRichMedia==undefined){if(this.asinInfo!=undefined){try{if(this.asinInfo.richMediaImages!=undefined&&this.asinInfo.richMediaImages[0]!=undefined){this.hasRichMedia=true}else{this.hasRichMedia=false}}catch(e){this.hasRichMedia=false}}else{this.hasRichMedia=false}}return this.hasRichMedia},setMainImages:function(){var images=new Object();var variantList=new Array();images.main=new AsinImage(this.asinInfo.mainImages[0],this.getHasRichMedia());images.MAIN=images.main;for(var i=0;i<this.asinInfo.variantImages.length;i++){var key="PT0"+(i+1);images[key]=new AsinImage(this.asinInfo.variantImages[i],this.getHasRichMedia());variantList.push(key)}this.variantList=variantList;return images}});var AsinImage=Class.create({initialize:function(imageHash,hasRichMedia){if(imageHash==undefined){return }this.imageHash=imageHash;this.hasRichMedia=hasRichMedia;if(imageHash.largeImage){this.largeImage=new ImageObj(imageHash.largeImage)}if(imageHash.mediumImage){this.mediumImage=new ImageObj(imageHash.mediumImage)}if(imageHash.swatchImage){this.swatchImage=new ImageObj(imageHash.swatchImage)}if(imageHash.thumbnailImage){this.thumbnailImage=new ImageObj(imageHash.thumbnailImage)}if(imageHash.tinyImage){this.tinyImage=new ImageObj(imageHash.tinyImage)}},getLargeImage:function(){return this.largeImage},getMediumImage:function(){return this.mediumImage},getSwatchImage:function(){return this.swatchImage},getThumbnailImage:function(){return this.thumbnailImage},getTinyImage:function(){return this.tinyImage},getHasRichMedia:function(){return this.hasRichMedia}});var ImageObj=Class.create({initialize:function(info,hasRichMedia){if(info==undefined){return }this.hasRichMedia=hasRichMedia;this.height=info.HEIGHT;this.url=info.URL;this.width=info.WIDTH},getHeight:function(){return this.height},getUrl:function(){return this.url},getWidth:function(){return this.width},getHasRichMedia:function(){return this.hasRichMedia}});
