

/**
 * @class Quick shop class, shows and hides the quick shop image
 * that will be placed on top of the products.
 */
Core.QuickShop_Class=function (){
    /**
     * The HTML ID of the layer (div) for the quick shop class
     */
    this.QuickShop_DivID='QuickLook';

    /**
     * Code of cyrrent variant/product 
     */
    this.Code='';

    /**
     * Set to true if viewing a variant and set to false if viewing the whole product
     */
    this.IsVariant=true;
    
    this.VariantFilterExpression="";

    this.hasShades=false;
    
    this.FromProductBubble=false;
       
     this.timer;  
    /** 
     * Holds a reference to the parent control. If this value is present,
     * when attempting to show a new bubble, this control will attempt to hide
     * the parent
     */
    this.parentControlID=null;
        
    this.OutOfStock_ObjectID='OutOfStock_dhtmlObjectID';
    /**
     * This Method shows the quick look on top of a layer with id of RelativeObjectId
     * @param {string} RelativeObjectId The ID of the object where the quick look image/layer will be displayed as a hot spot
     * @param {string} Code ProductCode(SKU)
     * @param {bool} IsVariant true if it is variant, false otherwise
     */
    this.Show=function (RelativeObjectId,Code,IsVariant) {
         _ProductBubble_Class.FilterVariantList='';
        this.VariantFilterExpression="";
        this.Code=Code;
        this.IsVariant=IsVariant;
        MM_showHideLayers(this.QuickShop_DivID,'','show',RelativeObjectId);
    }
    /**
     * This Method shows the quick look on top of a dhtml object RelativeObject
     * If AbsoluteTop or Absoluteleft is let say 200 and 250, the displacement of quick look will
     * be 200 + plusTop and 250 + plusLeft. View the Code for more details
     * @param {string} RelativeObject Object where the quick look image (layer) will be displayed as a hot spot
     * @param {string} Code ProductCode(SKU)
     * @param {bool} IsVariant True if it is variant, false otherwise
     * @param {integer} plusTop integer like +20
     * @param {integer} plusLeft integer like +20
     * @hasShades {boolean} true if product has shades
     */
    this.ShowByObjectPosition=function (RelativeObject,Code,IsVariant,plusTop,plusLeft,hasShades) {
        this.VariantFilterExpression="";
        _ProductBubble_Class.FilterVariantList='';
        this.Code=Code;
        this.IsVariant=IsVariant;
        this.hasShades=hasShades;
        this.PositionLayerByRelativeObject(RelativeObject,$get(this.QuickShop_DivID),plusTop,plusLeft);
    }
    
   this.ShowOutOfSTockByObjectPosition=function (RelativeObject,Code,IsVariant,plusTop,plusLeft,hasShades) {
        this.VariantFilterExpression="";
        _ProductBubble_Class.FilterVariantList='';
        this.Code=Code;
        this.IsVariant=IsVariant;
        this.hasShades=hasShades;
        this.PositionLayerByRelativeObject(RelativeObject,$get(this.OutOfStock_ObjectID),plusTop,plusLeft);
    }
    
    
    this.PositionLayerByRelativeObject=function(RelativeObject,objid,plusTop,plusLeft) {
                  PositionLayerByRelativeObject(RelativeObject,objid,plusTop,plusLeft);
                  try {
                  clearTimeout(this.timer);
                  }
                  catch(err) {   }
                  this.timer=setTimeout("_QuickShop_Class.Hide();", 3000);
    }
        
     this.ShowIcon=function (RelativeObject,Code,IsVariant,plusTop,plusLeft,hasShades,StockWebNumber) {
        this.Hide();
        var StockItems=parseInt(StockWebNumber);
        var StockTresHold=1;
        try {
         StockTresHold=AJAX_GetTresHoldNumber();
        }
        catch (e) {   }
        
        if (AJAX_ENABLE_OUTOFSTOCK==false) {
            StockItems=100; //make the site allow the users to add items to stock. As long as it is greater then zero we're good.
        }
      
      
       if (StockItems>StockTresHold) {
            this.ShowByObjectPosition(RelativeObject,Code,IsVariant,plusTop,plusLeft,hasShades); 
  
       }
       else {
         this.ShowOutOfSTockByObjectPosition(RelativeObject,Code,IsVariant,plusTop,plusLeft,hasShades);
  
       }
      }
            
    this.ShowVariantFilterIcon=function (RelativeObject,Code,IsVariant,plusTop,plusLeft,hasShades,filterVariantList) {
        this.Code=Code;
        this.IsVariant=IsVariant;
        this.hasShades=hasShades;
        _ProductBubble_Class.FilterVariantList=filterVariantList;
         this.VariantFilterExpression="";
        this.PositionLayerByRelativeObject(RelativeObject,$get(this.QuickShop_DivID),plusTop,plusLeft); 
    }
    
       //THis method will be used when showing the product bubble but a filter expression is done based on extended properties
    // F.N 03.29.2007
    this.ShowProductFilterExpression=function (RelativeObject,Code,plusTop,plusLeft,hasShades,filterExpression) {
         _ProductBubble_Class.FilterVariantList="";
         this.VariantFilterExpression=filterExpression;
         this.Code=Code;
         this.IsVariant=false;
         this.hasShades=hasShades;
         this.PositionLayerByRelativeObject(RelativeObject,$get(this.QuickShop_DivID),plusTop,plusLeft); 
    }
    /**
     * Simply hides the quick shop image/layer
     */
    this.Hide=function() {
         //_ProductBubble_Class.FilterVariantList='';
         MM_showHideLayers( this.QuickShop_DivID,'','hide');
         MM_showHideLayers( this.OutOfStock_ObjectID,'','hide');
    }

    /**
     * When the quick shop bubble is shown, the user can click on that image.
     * This method is called when the user clicks on the image.
     * The method determines if it is a Variant or Product. Based on the requests, we
     * may need to do few more cases on this method.
     */
    this.ShowBubble=function() {
        if (this.IsVariant) {
            _ProductManager.LoadMakeupVariant(this.Code, this.parentControlID)
        }
        else {
            if(this.hasShades) {
             
               if (this.VariantFilterExpression=="" || typeof(this.VariantFilterExpression)=='undefined') {
                  _ProductManager.LoadMakeupProduct(this.Code, this.parentControlID);
                }
                else {
                   
                   //when passed filter exression on quick shop class
                   _ProductManager.LoadMakeupProductFilterVariants(this.Code, this.parentControlID,this.VariantFilterExpression);
                
                }
            }
            else {
                 if (this.VariantFilterExpression=="") {
                  _ProductManager.LoadSkinCareProduct(this.Code, this.parentControlID);
                }
                else {
                        //when passed filter exression on quick shop class
                     _ProductManager.LoadSkinCareFilterVariants(this.Code, this.parentControlID,this.VariantFilterExpression);
                
                }
            }
        }
    }
    
    
     /**
     * This method will be called from the bubbles to add a product on the
     *  favorites from quick shop
     */
    this.AddToFavoritesFromBubble=function() {
        if(CustomerSigned == true){
            var _prdType='Product';
            if (this.IsVariant) {
                _prdType='Variant';
            }
            //_CoreModalPopUp.Hide();
            _ProductManager.AddProductToFavorites(_prdType, AJAX_DEFAULT_RETAILER, this.Code);
        }else{
            _SignInBubble.ShowBubbleFromFavoritesBubble(this.Code);
        }
    }
    
    this.AddToFavorites=function(isVariant,Code) {
        this.FromProductBubble=true;
        this.IsVariant=isVariant;
        this.Code=Code;
        this.AddToFavoritesFromBubble();
    }
}

/*
 * It registers the QuickShop_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.QuickShop_Class.registerClass('Core.QuickShop_Class'); }


