/* Source: topspin_purchase.js, as of Mon Jan 25 12:06:42 -0800 2010 */


/* Source: /var/www/apps/topspin/releases/20100125193210/public/javascripts/TSConfig.js, last modified at Mon Jan 25 12:04:49 -0800 2010 */
TSConfig = {
    APP_URL:     "http://app.topspin.net/",
    SSL_APP_URL: "https://app.topspin.net/",
    FLASH_URL:   "http://app.topspin.net/flash/",
    IMAGE_URL:   "http://app.topspin.net/images/",
    CDN_URL:     "http://cdn.topspin.net/",
    BEACON_URL:  "http://px.topspin.net/ev?env=production"
};
if (window.location.href.toString().indexOf("https") == 0) TSConfig.APP_URL = TSConfig.SSL_APP_URL;

/* Source: /var/www/apps/topspin/releases/20100125193210/public/javascripts/TSPurchase.js, last modified at Mon Jan 25 11:33:08 -0800 2010 */
// Do not execute the contents of this file if TSPurchase has already been
// initialized; this is done to prevent redundant processing when this file
// has been included more than once on the same page.
if (!window.TSPurchase) {

/* TSFLASH */
/**
 * Functions for embedding Flash elements on the page.
 * Flash movies currently in use must be recompiled to use the Flash methods.
 * Uses swfobject 2.0.
 */
TSFlash = {
    /**
     * Embeds a flash movie on the page. Requires a full path to the SWF, a container element,
     * and an options object. At a minimum, you need to pass options.width, options.height,
     * options.instance (a unique ID for the movie). If options.facing is not supplied, this
     * defaults to 'fan' facing, using fan redirects & min version standards. The other valid
     * option is currently 'artist'. Other optional params include options.redirectURL -- a custom
     * URL to redirect to that doesn't correspond to the stock fan- or artist- facing URL;
     * options.redirectParams -- appended to the end of the redirect URL.
     * If params are not supplied we will supply a high quality
     *
     * @param    swfName   the full path to the swf file to be embedded.
     * @param    container the element that the Flash movie will be embedded in.
     * @param    options   an object with options. Minimum requirement is width, height,
     *                     instanceName and loadParams.
     * @requires swfbject  swfobject 2.0 is required for embeds.
     */
    embed: function(swfName, container, options) {
        if (!options) {
            return;
        }
        if (typeof(options.params) == "undefined") {
		    options.params = {
		        quality: "high",
		        wmode: TSFlash.isLinux() ? "" : "transparent",
		        allowscriptaccess: "always",
		        menu: false
		    };
        }
        // redirect, etc have been pulled as swfobject 2.0 does not currently support it.
        // Variables should still be passed in but it's pulledfor lightness of code.
        swfobject.embedSWF(swfName, container, options.width, options.height, TSFlash.minVersion[options.facing], null, options.variables, options.params);
    },
    /**
     * Allows flash to call out to resize its parent container
     *
     * @param target        the id of element to be redimensioned
     * @param height        the new desired height
     * @param jsIdentifier  JS Identifier for widget making call
     */
    redimensionMovie: function(target, height, jsIdentifier){
        // TODO: convert to a JSON model of CSS atribs & values & change that way
        var elem = document.getElementById(target);
        height = parseInt(height) + 23;
        elem.style.height = height + "px";
        elem.parentNode.style.height = height + "px";
    },
    /**
     * Checks to see if minimum version of flash player is present for the supplied facing.
     * Assumes "fan" if no facing is supplied.
     *
     * @param  facing   the facing that needs to be checked for min flash version.
     * @return boolean  true if sufficient flash player version exists, false if not.
     */
    checkMinVersion: function(facing) {
        if (typeof(facing) == 'undefined') {
            facing = 'fan';
        }
        var version = swfobject.getFlashPlayerVersion();
        var reqVersions = TSFlash.minVersion[facing].split('.');
        var compatibleVersion = false;
        if (parseInt(version.major) > parseInt(reqVersions[0])) {
            // MAJ > MAJ -- compat
            compatibleVersion = true;
        } else {
            // check the minor version
            if (parseInt(version.minor) > parseInt(reqVersions[1]) && parseInt(version.major) == parseInt(reqVersions[0])) {
                // MAJ == MAJ; MIN > MIN -- compat
                compatibleVersion = true;
            } else {
                // check the revision
                if (parseInt(version.release) >= parseInt(reqVersions[2]) && parseInt(version.minor) == parseInt(reqVersions[1])) {
                    // MAJ == MAJ, MIN == MIN, REV > REV -- compat
                    compatibleVersion = true;
                }
            }
        }
        return compatibleVersion;
    },
    /**
     * Minimum flash versions needed for different areas of the site.
     */
    minVersion: {
        artist:"9.0.115",
        fan:"9.0.115"
    },
    isLinux: function() {
        var exp = /Linux/;
        return (exp.exec(navigator.platform));
    },
    /**
     * Javascript functions used by Flash players to transact. This may be moved to Widgets
     * eventually.
     */
    PlayerHooks: {
        /**
         * Transact is the primary player hook for flash and kicks off the purchase flow.
         *
         * @param JSONData  JSON string containing transactionMode (share or download),
         *                  event info, and APIDs to transact upon.
         */
        transact: function(JSONData) {
            var jsonObj = eval( "(" + JSONData + ")");
            (!jsonObj.jsIdentifier) ? ts_load_purch_flow(jsonObj.purchases, jsonObj.transactionMode) : ts_load_purch_flow(jsonObj.purchases, jsonObj.transactionMode, jsonObj.jsIdentifier);
        }
    }
};
/* END TSFLASH */
/* WIDGETS.JS */
/*
TODO: make getElementsByClassName faster
TODO: clean up error overlay
*/


/**
 * Namespace that wraps all widget code.
 */
var TSWidget = {
    /**
     * The Util namespace encompasses static utility functions that are either dependencies of
     * other classes, or are commonly used by the individual or general widget code.
     * Util encompasses DOM manipulation, logging and debugging, URL parsing, String manipulation
     * functions, and the like. In general most of this functionality has been developed elsewhere
     * and collected here.
     * It borrows heavily from the Prototype library and Peter Michaux's Fork library.
     */
    Util: {},
    /**
     * The Widgets namespace is used to declare functions and variables related
     * to displaying and managing widgets
     */
    Widgets: {},
    /**
     * The Config namespace is used to declare configuration variables.
     * These variables can be modified by widget users.
     * Any variables that are modified by deploy scripts should be declared here.
     */
    Config: {}
};


/**
 * This function adds the fields (and corresponding values) of the source to the destination.
 * It has many uses, like merging associative arrays, extending classes with new functionality,
 * and overwriting methods.
 * It is taken wholesale from the Prototype library (Object.extend).
 *
 * @param {Object} destination The object to be extended.
 * @param {Object} source The object whose fields are to be copied.
 * @return {Object} The destination object after extension.
 */
TSWidget.Util.extend = function(destination, source) {
    for (var property in source) {
        destination[property] = source[property];
    }
    return destination;
};


/* =====      TSWidget.Util      ===== */
TSWidget.Util.extend(TSWidget.Util, {

    getOverlayDimensions: function() {
        var windowWidth;
        var windowHeight;
        if (window.innerWidth) {
            // Not IE
            windowWidth = window.innerWidth;
            windowHeight = window.innerHeight;
        } else if (document.documentElement && document.documentElement.clientWidth) {
            // IE Strict Mode
            windowWidth = document.documentElement.clientWidth;
		    windowHeight = document.documentElement.clientHeight;
        } else {
            // Everyone else
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }

        var bodyWidth;
        var bodyHeight;
        if (window.innerHeight && window.scrollMaxY) {
            // Not IE
            bodyWidth = window.innerWidth + window.scrollMaxX;
            bodyHeight = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight) {
            // All but IE mac
            bodyWidth = document.body.scrollWidth;
            bodyHeight = document.body.scrollHeight;
        } else {
            // Everyone else
            bodyWidth = document.body.offsetWidth;
            bodyHeight = document.body.offsetHeight;
        }

        var overlayWidth  = (windowWidth  > bodyWidth)  ? windowWidth  : bodyWidth;
        var overlayHeight = (windowHeight > bodyHeight) ? windowHeight : bodyHeight;

        /*
         * Returns the largest element on the page (in terms of pixel height)
         * regardless of display, position, or visibility CSS style settings
         */
        function getMaxElementHeight() {
            var arr = document.getElementsByTagName("*");
        	var max = 0;

        	function getDimensions(element) {
        	    var display = element.style.display;
        	    if (display != 'none' && display != null) { // Safari bug
        	        return {width: element.offsetWidth, height: element.offsetHeight};
                }
                // All *Width and *Height properties give 0 on elements with display none,
        	    // so enable the element temporarily
        	    var els = element.style;
                var originalVisibility = els.visibility;
        	    var originalPosition = els.position;
        	    var originalDisplay = els.display;
        	    els.visibility = 'hidden';
        	    els.position = 'absolute';
        	    els.display = 'block';
        	    var originalWidth = element.clientWidth;
        	    var originalHeight = element.clientHeight;
        	    els.display = originalDisplay;
        	    els.position = originalPosition;
        	    els.visibility = originalVisibility;
        	    return { width: originalWidth, height: originalHeight };
        	};

        	for (var i=0; i < arr.length; i++) {
        		var h = getDimensions(arr[i]).height;
        		if (h > max) { max = h; }
        	}

            return max;
        };

        if (bodyHeight == 0 || bodyHeight == windowHeight) {
            overlayHeight = getMaxElementHeight();
        }

        var overlayDimensions = {
            width: overlayWidth,
            height: overlayHeight
        };
        return overlayDimensions;
    },
    redimensionOverlay: function() {
        var overlay = document.getElementById('TSOverlayBGDiv');
        var overlayDims = TSWidget.Util.getOverlayDimensions();
        overlay.style.height = overlayDims.height + "px";
        overlay.style.width = overlayDims.width + "px";
    },
    showFlash: function() {
        var flashNodes = document.getElementsByTagName('object');
        for (var i=0;i<flashNodes.length;i++) {
            flashNodes[i].parentNode.style.textIndent = "0px";
            if (flashNodes[i].style.visibility == "hidden") {
                flashNodes[i].style.visibility = "visible";
            }
        }
    },
    hideFlash: function() {
        var flashNodes = document.getElementsByTagName('object');
        for (var i=0;i<flashNodes.length;i++) {
            var flashNode = flashNodes[i];
            if (flashNode.style.visibility != "hidden" && flashNode.id != "pf_alt_1") {
                flashNode.style.visibility = "hidden";
                flashNode.parentNode.style.textIndent = "-9999px";
            }
        }
    },
    showOverlay: function() {
        TSWidget.Util.hideFlash();

        var overlay = document.getElementById('TSOverlayBGDiv');

        if (!overlay) {
            overlay = document.createElement('div');
            overlay.id = "TSOverlayBGDiv";
            overlay.innerHTML = "&nbsp;";

            var dBody = document.getElementsByTagName('body')[0];
            dBody.appendChild(overlay, dBody);
        }

        // NOTE: Setting the dimensions for the overlay is primarily for < IE6;
        //       this step should not be required for browsers that support
        //       fixed positioned elements.
        TSWidget.Util.redimensionOverlay();

        overlay.style.display = "block";
    },
    hideOverlay: function() {
        var overlay = document.getElementById('TSOverlayBGDiv');
        if (overlay) {
            overlay.style.display = "none";
        }
        TSWidget.Util.showFlash();
    },
    errorMessage: function(message, actionLink, jsIdentifier) {
        var pFlow = document.getElementById('ts_ol_pflow');
        if (typeof(pFlow) != 'undefined') {
            var newDiv = document.createElement('div');
            newDiv.innerHTML = "blah";
            pFlow.style.display = "none";
        }
        var ua = new String(navigator.userAgent);
        var errorPane = document.createElement('div');
        errorPane.id = "tsUsrErrMsgLbox";
        errorPane.style.background = "url('"+ TSConfig.CDN_URL + "images/widgetSupport/errorPane/errorIcon.jpg') no-repeat 25px 30px #000000";

        if (ua.indexOf("MSIE") > -1) {
            errorPane.style.top = 120 + parseInt(document.documentElement.scrollTop) + "px";
            errorPane.style.left = parseInt(document.documentElement.clientWidth)/2 - 347 + "px";
        } else {
            //errorPane.style.top = parseInt(window.pageYOffset) + 120 + "px";
            errorPane.style.left = parseInt(window.innerWidth)/2 - 347 + "px";
        }

        var errorHeadline = document.createElement('h3');
        var errorMessage = document.createElement('div');
        var errorAction = document.createElement('a');
        var errorClose = document.createElement('a');

        errorPane.appendChild(errorHeadline);
        errorPane.appendChild(errorMessage);
        errorPane.appendChild(errorAction);
        errorPane.appendChild(errorClose);

        var dBody = document.getElementsByTagName('body')[0];
        dBody.insertBefore(errorPane, dBody.firstChild);
        setTimeout("TSWidget.Util.paneScroll('tsUsrErrMsgLbox', 120)",2);

        errorHeadline.innerHTML = message.headline;
        errorMessage.innerHTML = message.text;
        errorAction.innerHTML = "&raquo; " + actionLink.text;
        errorAction.href = actionLink.href;
        errorAction.onclick = actionLink.onclick;
        errorAction.setAttribute("onclick", actionLink.onclick);
        errorAction.className = "tsErrActionLink";

        errorClose.innerHTML = "Cancel and Go Back";
        errorClose.href = "javascript:void(0);";
        errorClose.onclick = "javascript:TSWidget.Util.closeError('"+errorPane.id+"')";
        errorClose.setAttribute("onclick","javascript:TSWidget.Util.closeError('"+errorPane.id+"')");

        errorPane.innerHTML = errorPane.innerHTML; // IE
        TSPurchFlowResizeHandler = function () {
            TSWidget.Util.centerPane('tsUsrErrMsgLbox', 350);
            TSWidget.Util.redimensionOverlay();
        };
        TSPurchFlowScrollHandler = function () {
            TSWidget.Util.paneScroll('tsUsrErrMsgLbox', 120);
        };
        TSWidget.Util.DOM.addEventHandler(window, "resize", TSPurchFlowResizeHandler);
        TSWidget.Util.DOM.addEventHandler(window, "scroll", TSPurchFlowScrollHandler);
        return;
    },
    closeError : function(paneId) {
       var ePane = document.getElementById(paneId);
       ePane.parentNode.removeChild(ePane);
       TSWidget.Util.hideOverlay();
       //document.onscroll = "";
       TSWidget.Util.DOM.removeEventHandler(window, "resize", TSPurchFlowResizeHandler);
       TSPurchFlowResizeHandler = null;
       TSWidget.Util.DOM.removeEventHandler(window, "scroll", TSPurchFlowScrollHandler);
       //TSWidget.Util.DOM.removeEventHandler(document.documentElement, "scroll", TSPurchFlowScrollHandler);
       TSPurchFlowScrollHandler = null;
    },
    centerPane : function(elementId, offset) {
        var ePane = document.getElementById(elementId);
        var val = (parseInt(document.body.clientWidth))/2 - offset + "px";
        ePane.style.left = val;
    },
    paneScroll: function(elementId, offset) {
        var ePane = document.getElementById(elementId);
        var ua = new String(navigator.userAgent);
        var rawVal;
        if (ua.indexOf("MSIE") > -1) {
            rawVal = parseInt(document.documentElement.scrollTop);
        } else {
            rawVal = parseInt(window.pageYOffset);
        }
        var val = offset + rawVal + "px";
        ePane.style.top = val;
    },
    /**
     * The DOM namespace covers basic DOM manipulation functions such as insertions and search functions.
     */
    DOM: {
        /**
         * Adds an event handler function as an event listener to a DOM element
         *
         * @param element  DOM element to which the event handler should be added
         * @param eventType  Event type excluding "on" prefix
         * @param handler  Event handler function
         */
        addEventHandler: function (element, eventType, handler) {
            if (typeof element.addEventListener != "undefined") {
                element.addEventListener(eventType, handler, false); // DOM2
            } else if (typeof element.attachEvent != "undefined") {
                element.attachEvent("on"+eventType, handler); // IE
            }
        },
        /**
         * Removes an event handler function from a DOM element
         *
         * @param element  DOM element from which the event handler should be removed
         * @param eventType  Event type excluding "on" prefix
         * @param handler  Event handler function
         */
        removeEventHandler: function (element, eventType, handler) {
            if (typeof element.removeEventListener != "undefined") {
                element.removeEventListener(eventType, handler, false); // DOM2
            } else if (typeof element.detachEvent != "undefined") {
                element.detachEvent("on"+eventType, handler); // IE
            }
        }
    }
});

/* END WIDGETS.JS */
/* WIDGET POPULATORS */

TSWidget.Util.extend(TSWidget.Widgets, {
    FlashHooks:{
		purchaseFlowPath: "widgets/purchase/TSPF4.swf",

        /**
         * @deprecated  Use TSWidget.Widgets.Helpers.closeLightBox instead -- needs to be changed in flash
         */
        downloadFormCancel: function (jsIdentifier){
            TSWidget.Widgets.Helpers.closeLightBox(jsIdentifier);
        },
        paypalPurchase: function (paypalURL, jsIdentifier){
            var WindowObjectReference = window.open(paypalURL,'targetURL');
            if (!WindowObjectReference) {
                var message = {
                    headline: "Sorry",
                    text: "Your browser has prevented a pop-up window from opening.<br/><br/>"
                };
                message.text += "You may wish to disable pop-up blocking to make the download process a little easier. Otherwise, you can still continue by opening this link in a new window.";
                var actionLink = {
                    href:"javascript:void(0);",
                    text:"Go to PayPal in a New Window",
                    onclick:"javascript:window.open('"+paypalURL+"');TSWidget.Util.closeError('ts_usrErrMsg_lbox');"
                };
                TSWidget.Util.errorMessage(message, actionLink, jsIdentifier);
            }
        },
        openURLFromFlash: function(targetURL, jsIdentifier) {
            var WindowObjectReference = window.open(targetURL,'targetURL');
            if (!WindowObjectReference) {
                var message = {
                    headline: "Sorry",
                    text: "Your browser has prevented a pop-up window from opening.<br/><br/>"
                };
                message.text += "You may wish to disable pop-up blocking to make the process a little easier. Otherwise, you can still continue by opening this link in a new window. ";
                var actionLink = {
                    href:"javascript:void(0);",
                    text:"Open Link in a New Window",
                    onclick:"javascript:window.open('"+targetURL+"');TSWidget.Util.closeError('ts_usrErrMsg_lbox');"
                };
                TSWidget.Util.errorMessage(message, actionLink, jsIdentifier);
            }
        },
        refreshPage: function (jsIdentifier) {
            window.location = window.location;
        },
        loadPurchaseFlow: function (productList, mode, widgetId, width, campaignId, persistVal, artistIdVal, theme, highlightColor) {
            var lightBox = TSWidget.Widgets.Helpers.renderLightBox(widgetId);
            var lightBoxWrapper = lightBox.parentNode;
            persistVal = (typeof(persistVal) == 'undefined' || persistVal == null) ? true : persistVal;
            theme = (typeof(theme) == 'undefined' || theme == null) ? "black" : theme;
			      highlightColor = (typeof(highlightColor) == 'undefined' || highlightColor == null) ? "0x00A1FF" : highlightColor;
            var key = "";
            // TODO: Need to determine where to get the subject from. Global data object is not the right place.
            //var emailSubject = (typeof(data.subject) != 'undefined') ? data.subject : "";
            var emailSubject = "";
            campaignId = campaignId || "";
            mode = mode || "download";
            width = 480;
            var height = 570;
            
            var timestamp = "?ts=" + parseInt(new Date().getTime() / 900000);
		    var flashURL = TSConfig.CDN_URL + TSWidget.Widgets.FlashHooks.purchaseFlowPath + timestamp;

            if (mode == "share") {
                lightBoxWrapper.className += " share";
                width = 400;
                height = 334;
                flashURL = TSConfig.SSL_APP_URL + "flash/share/TSShareFlow.swf";
            }
            var paypalReturnURLBase = TSConfig.SSL_APP_URL + "shop";
            var options = {
                facing: 'fan',
                variables: {
                    persist: persistVal,
                    baseUrl: TSConfig.SSL_APP_URL.replace(/\/$/,''),
                    cdnUrl: TSConfig.CDN_URL.replace(/\/$/,''),
                    ppUrl: paypalReturnURLBase,
                    shareSubj: emailSubject,
                    divW: width,
                    artistId: artistIdVal,
                    pList: productList,
                    key: key,
                    campaignId: campaignId,
                    jsIdentifier: widgetId,
                    theme : theme,
					          highlightColor : highlightColor,
                    movieId: lightBox.id
                },
                params: {
                    quality: "high",
                    allowscriptaccess: "always",
                    menu: "false",
                    bgcolor: "#000000"
                },
                width: width,
                height: height,
                instance: lightBox.id
            };

            TSFlash.embed(flashURL, lightBox.id, options);

            function adblockCheck() {
                var abCheck = lightBoxWrapper.getElementsByTagName('a');
                var hideFlag = false;
                for (var i=0;i<abCheck.length;i++) {
                    if (abCheck[i].className.indexOf('abp-obj') >= 0) {
                        hideFlag = true;
                    }
                }
                if (hideFlag) {
                    for (var i=0;i<abCheck.length;i++) {
                        if (hideFlag && abCheck[i].className.indexOf('abp-obj') == -1) {
                            abCheck[i].style.left = "0px";
                            abCheck[i].style.cssFloat = "left";
                            abCheck[i].style.textAlign = "left";
                            abCheck[i].parentNode.style.textAlign = "left";
                        }
                    }
                }
            };
            setTimeout(adblockCheck, 100);
        }
    },
    Helpers: {
        /**
         * Renders empty modal light box - temp
         *
         * @param id  The identifier used to create the light box media container
         * @return The light box media container element
         */
        renderLightBox: function (id) {
            TSWidget.Util.showOverlay();

            var wrapper = document.getElementById('ts_ol_pflow');
            if (wrapper != null) {
                wrapper.parentNode.removeChild(wrapper);
            }
            wrapper = document.createElement('div');
            wrapper.id = "ts_ol_pflow";
            wrapper.className = "ts_download_form";

            var tBar = document.createElement('div');
            tBar.id = "ts_pflow_control";
            var tBarLink = document.createElement('a');
            tBarLink.href = "javascript:void(0);";
            var closeURL = TSConfig.CDN_URL + "images/widgetSupport/purchFlow/close1.gif";
            tBarLink.innerHTML = "<img src='"+closeURL+"' border='0' alt='Close'/>";
            TSWidget.Util.DOM.addEventHandler(tBarLink, "click", TSWidget.Widgets.Helpers.closeLightBox);
            tBar.appendChild(tBarLink);

            var contentBox = document.createElement('span');
            contentBox.id = "pf_alt_" + id;
            contentBox.className = "TSFlash_alt";
            contentBox.style.display = "block";
            contentBox.style.position = "absolute";
            contentBox.style.fontSize = "12px";
            contentBox.style.fontFamily = "Verdana, Arial, Helvetica";
            contentBox.style.backgroundColor = "transparent";
            contentBox.style.width = "100%";
            contentBox.style.border = "none";
            contentBox.style.color = "#ffffff";
            contentBox.innerHTML = "You do not have the required minimum version of<br/>Adobe Flash&reg;.<br/><br/> <a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' target='_blank' style='color:#01cdff;font-weight:bold;'>Click here to upgrade</a>.<br/><br/><a href='#' style='color:#01cdff' onclick='javascript:TSWidget.Widgets.Helpers.closeLightBox();'>Cancel</a>";

            wrapper.appendChild(tBar);
            wrapper.appendChild(contentBox);

            var yOffset;
            if (window.pageYOffset) {
                // Not IE
                yOffset = window.pageYOffset;
            } else if (document.documentElement && document.documentElement.scrollTop) {
                // IE strict mode
                yOffset = document.documentElement.scrollTop;
            } else {
                // IE other
                yOffset = document.body.scrollTop;
            }
            wrapper.style.top = 80 + parseInt(yOffset) + "px";
            wrapper.style.left = (document.body.clientWidth)/2 - 212 + "px";

            var bodyNode = document.getElementsByTagName('body')[0];
            bodyNode.insertBefore(wrapper, bodyNode.firstChild.nextSibling);

            // Declare event handlers within global scope so they can be referenced when removing
            TSLightBoxResizeHandler = function () {
                TSWidget.Util.centerPane("ts_ol_pflow", 212);
                TSWidget.Util.redimensionOverlay();
            };
            TSWidget.Util.DOM.addEventHandler(window, "resize", TSLightBoxResizeHandler);

            return contentBox;
        },
        /**
         * Closes a modal light box
         *
         * @param id  The identifier used to create the light box media container
         */
        closeLightBox: function (id) {
            /// THIS TOOK JSIDENTIFIER... NEEDS TO ACTUALLY TAKE ID NOW
            var pf = document.getElementById('ts_ol_pflow');
            //pf.innerHTML = "";
            TSWidget.Util.DOM.removeEventHandler(window, "resize", TSLightBoxResizeHandler);
            TSLightBoxResizeHandler = null;

            TSWidget.Util.hideOverlay();
            pf.style.display = "none";
            //pf.parentNode.removeChild(pf);
        }

    }
});

/* END WIDGET POPULATORS */
/* TSPURCHASE */

TSPurchase = (function () {
    /**
     * Handles initial set up for TSPurchase related elements included on the page
     */
    function init() {
        if (!document.getElementById('topspin_style_addition')) {
            var styleTag = document.createElement('link');
            styleTag.media = 'screen';
            styleTag.rel = 'stylesheet';
            styleTag.type = 'text/css';
            styleTag.id = 'topspin_style_addition';
            styleTag.href = TSConfig.CDN_URL + "stylesheets/widget.css";
            var headNode = document.getElementsByTagName('head')[0];
            var headChild = headNode.firstChild;
            headNode.insertBefore(styleTag, headChild);

            var genericImageTag = document.createElement('img');
            genericImageTag.className = "invisible_image";

            var bodyNode = document.getElementsByTagName('body')[0];

            var allAnchors = document.getElementsByTagName('a');
            var anchorLength = allAnchors.length;

            // CHECK: Is this still necessary?
            for (var i=0;i<anchorLength;i++) {
                var anchor = allAnchors[i];
                if (anchor.href.indexOf('https://app.topspin.net/purchase/') >= 0) {
                    var urlArr = anchor.href.split('/');
                    var artistID = urlArr[5];
                    var campaignID = urlArr[6];
                    anchor.href = "javascript:void(0);";
                    anchor.onclick = "TSPurchase.load({aId:"+artistID+",bId:22737,cId:"+campaignID+",persist:true});";
                }
            }

            for (i=0;i<anchorLength;i++) {
                var clickStr = new String(allAnchors[i].onclick);
                if (clickStr.indexOf('TSPurchase.load') >= 0) {
                    var data = eval(clickStr.substring(clickStr.indexOf('TSPurchase.load') + 'TSPurchase.load'.length, clickStr.length-1));
                    var beaconImageTag = genericImageTag.cloneNode(true);
                    beaconImageTag.src = TSConfig.BEACON_URL +
                                         "&et=0&es=2&c=" + data['cId'] + "&u=" + encodeURIComponent(window.location.href.toString()) + "&timestamp=" + new Date().getTime();
                    bodyNode.appendChild(beaconImageTag);
                }
            }
        }
    }

    return {
        initialize: init,

        load: function(params) {
           TSWidget.Widgets.FlashHooks.loadPurchaseFlow(params.bId, null, 1, 435, params.cId, params.persist, params.aId, params.theme, params.highlightColor);
        }
    };
})();

TSWidget.Util.DOM.addEventHandler(window, "load", TSPurchase.initialize);

/* END TSPURCHASE */


} // End wrapping TSPurchase initialization check


