﻿var Home = function(){
    function setText(id, text){
        var el = document.getElementById(id);
        if(el) el.innerHTML = text;
    }
    
    return {
        featuredProducts : {},

        showFeaturedProduct : function(data) {
            setText("producttitle", data.title);
            setText("productdesc", data.text);
            setText("productprice", data.price);
            
            var bvinEl = document.getElementById("productbvin");
            bvinEl.value = data.bvin;
            
            var addToCartEl = document.getElementById("productaddtocartbutton");
            addToCartEl.onclick = function(){
                AddTo.addToCart(data.bvin, document.getElementById('quantity').value, AddTo.standardAddToCartCallback);
                return false;
                };
            
            var linkEl = document.getElementById("producturl");
            linkEl.href = data.url;
            
            var imageEl = document.getElementById("productimage");
            imageEl.src = data.image;
            
            var videoUrl = "/store/videos/" + data.video;
            var videoEl = document.getElementById("home-video");
            videoEl.innerHTML = '<object id="video_object" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="320" height="256"><param name="src" value="' + videoUrl + '"><param name="autoplay" value="false"><param name="controller" value="true"><param name="loop" value="false"><param name="type" value="video/quicktime"><param name="scale" value="ASPECT"><embed id="video_embed" src="' + videoUrl + '" pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" width="320" height="256" autoplay="false" controller="true" loop="false" scale="ASPECT"></object>';

            var html = "";
            if(data.related){
                for(var i=0;i<data.related.length;i++){
                    var rp = data.related[i];
                    html += '<div>';
                    html += '<img src=' + rp.image + ' width="57" align="left" class="productimage">';
                    html += '<a href="' + rp.url + '" class="productname">' + rp.title + '</a><br>';
                    html += rp.price + '<br>';
                    html += '<a href="#" onclick="AddTo.addToCart(\'' + rp.bvin + '\', 1, AddTo.standardAddToCartCallback);return false;" class="linkbutton"><span class="linkbuttonchar">+</span> Add To Cart</a>';
                    html += '</div>';
                }
            }
            var relatedproductlist = document.getElementById("relatedproductlist");
            relatedproductlist.innerHTML = html;
        }
    }
}();