 
brand.product.videoPlayer = {
    config: {},
    lastCuePoint: 0,
    totalCuePoints: 0,
   
    init: function() {   
        //console.log("brand.product.videoPlayer.init"); 

        this.text_step = site.product.rb.step;
        this.text_of = site.product.rb.of;
        
        // for videos with cue points (deprecated)
        if (this.config.cue_points) {
            if(this.config.cue_points.length) {
                this.totalCuePoints = this.config.cue_points.length - 1;
                this.lastCuePointTime = Number(this.config.cue_points[this.totalCuePoints - 2].time);
            }
        }
     
        this.videoPlaceholder =  $("flash_placeholder");
        if (!this.videoPlaceholder) {
            return;
        }
        this.productContainer = $("video_prod_container");
        
        this.drawVideoPlayer();
        this.processRelatedProducts();

        // for videos with cue points (deprecated)
        if (this.config.cue_points) {
            var self = this;
            generic.events.observe("videoPlayer:cuePoint", self.setCuePoint.bind(self));
        }
        
        // for videos with cue points (deprecated)
        // make sure flash has loaded before trying to set cue points
        if (this.config.cue_points) {
            var timerCount = 0;
            // make sure flash has loaded before trying to set cue points
            var playerIsReady = function() {
                timerCount++;
                //console.log("playerIsReady: checking");
                var vp = $("howToVideoPlayer");
                try {
                    var queryTime = vp.queryTime();
                }
                catch(err) { console.log("video player vp.queryTime error: "+err) }
                if (vp && typeof queryTime !== "undefined") {
                    self.playerFlashObject = vp;
                    clearInterval(timer);
                    //self.processRelatedProducts();
                    self.setInitialView();
                } else if (timerCount > 10) {
                    clearInterval(timer);
                    console.log("getting method 'queryTime' of flash object failed.  giving up.");
                }  
            }  
            var timer = setInterval(playerIsReady, 500);
        }
    }, 
  
    drawVideoPlayer: function() {
        //console.log("brand.product.videoPlayer.drawVideoPlayer");
        var placeholderNode = this.videoPlaceholder;
        if (!placeholderNode) return;
        var params = { 
           bgcolor: "#000000",
           flashvars: { 
            conf_uri: placeholderNode.getAttribute("conf_uri"),
            showTitle: placeholderNode.getAttribute("show_title") || "true"
            //videoHeight: placeholderNode.getAttribute("video_height") || 276
           }  
        };
    
        if (placeholderNode.getAttribute("color") === "white") {
            params.flashvars.color = "white"; 
        } 
       
        var attr = {
            id: "howToVideoPlayer",
            name: "howToVideoPlayer",
            data: "/flash/_video_player/howToVideoPlayer_query.swf" 
        };
         
        generic.flash.embed(attr, params, "flash_placeholder"); 
    },
  
    processRelatedProducts: function() { 
        //console.log("brand.product.videoPlayer.processRelatedProducts");
        if (!$("vid_prods")) return; 
                   
        //if (this.productContainer) this.productContainer.addClassName("hidden");  
        // for videos with cue points (deprecated)
        //if (this.config.cue_points) {
            //$$("#vid_prods .rel_prod").invoke('addClassName', "hidden");
            //$$("#vid_prods .swatch_hex_container").invoke("show");
        //}
        //console.log('$$("#vid_prods .swatch_hex_container") = ',$$("#vid_prods .swatch_hex_container"));
        
        brand.mpp.item.init({
            data: page_data.video_products,
            initButtons: true,
            video_prod: true,
            type: "video"
        }); 
    },
   
    setInitialView: function() {
        //if (this.productContainer) {
            //this.productContainer.addClassName("hidden");
        //}
        $("tip_title").innerHTML = (this.config.title) ? this.config.title : "&nbsp;"; 
        $("tip_copy").innerHTML = (this.config.intro) ? this.config.intro : "&nbsp;";  
    },
  
    getTimeCode: function() {
        //console.log("brand.products.videoPlayer.getTimeCode");
        var vp = this.playerFlashObject;
        if (!vp) { return "0000"; }
        //console.log("Flash Player time: " + vp.queryTime() + " " + Math.round(vp.queryTime()));
        var time = Math.round(vp.queryTime()); 
        return time;
    },
  
    showCue: function(cidx) { 
        //console.log("brand.products.videoPlayer.showCue cidx: " + cidx); 
        if (cidx==-1) {
            this.setInitialView(); 
            return;
        } 
     
        var cue = this.config.cue_points[cidx];    
        var completed = (cidx == this.totalCuePoints);
      
        $("tip_title").innerHTML = (completed) ? "&nbsp;" : this.text_step + " " + (cidx+1) + " " + this.text_of + " " + this.totalCuePoints; 
        $("tip_copy").innerHTML = cue.copy;  
    
        /*
        var hasProducts = false;
        $$("#vid_prods .rel_prod").invoke('addClassName', "hidden");
        $$("#vid_prods .swatch_hex_container").invoke("hide");
     
        var str, productNode, productId, skuId, swatchNode;   
        cue.prods.each(function(catprodsku, idx) {
            //console.log("sku path: "+catprodsku); 
            catprodsku = catprodsku.strip();
            str = catprodsku.split("PROD")[1];
            productId = "PROD" + str.split("SKU")[0];
            skuId = str.split("SKU")[1];
            productNode = $("video_" + productId);
            swatchNode = $("video_swatch_SKU" + skuId);
           
            if (!!productNode) { 
                hasProducts = true;
                //$("vid_prods").appendChild(product); // NEEDED?
                productNode.removeClassName("hidden");    
                if (!!swatchNode) swatchNode.style.display = "block"; 
            } 
        });
    
        if (hasProducts && this.productContainer) this.productContainer.removeClassName("hidden");  
        */
    },
  
    setCuePoint: function(idx) { 
        //console.log("brand.products.videoPlayer.setCuePoint "); 
        var time = this.getTimeCode();
        if (time == "0000") { return; }
  
        var cuePoint = -1;  
    
        for (var i=0;i<=this.totalCuePoints;i++) { 
            if (time >= this.config.cue_points[i].time) {
                if (i==this.totalCuePoints) cuePoint = i; //outro 
            } else { 
                cuePoint = i-1;   
                break;
            }
        }  
     
        this.showCue(cuePoint); 
    }  
};
