﻿GoodNites.ProductFlash = function(serverVars) {
    this.ServerVars = serverVars;
    this.Initialize();
};
GoodNites.ProductFlash.prototype = {
    Initialize: function() {
        var path = '/Swf/';
        var baseDir = '/Swf/';
        switch (serverVars.ProductType) {
            case 'Boxer':
            case 'Underwear':
                path += serverVars.ProductType + 'Detail.swf';
                break;
            case 'Landing':
                path += 'ProductsOffers.swf';
                break;
            default:
                // Invalid product type
                if (window.console) {
                    window.console.log('GoodNites.ProductFlash requires a valid productType to be passed. Valid values include: Boxer, Underwear, and Landing');
                }
                return;
        }
        
        // If we are in the production or QA environment, 
        // we need to prepend the /na directory to root
        if (document.location.href.indexOf('goodnites.com') != -1) {
            path = '/na' + path;
            baseDir = '/na' + baseDir;
        }
        
        // If the user doesn't have the minimum version of Flash required we shoul
        // display the message to prompt them to install it.
        if (!$.hasFlashPlayerVersion('8')) {
            $(serverVars.ProductFlashSelector + ' p').css('display', 'block');
            return;
        }
        
        $(serverVars.ProductFlashSelector).flash({
            swf: path,
            width: 900,
            height: (serverVars.ProductType == 'Landing') ? 324 : 419,
            params: {
                wmode: 'transparent'
            },
            // to tell flash where to look for the embedded swfs
            flashvars: {
                baseURL: baseDir
            }
        });
    }
};
GoodNites.Extend(GoodNites.ProductFlash, GoodNites.Core);