// JavaScript Document
var PDKpath = "http://"+window.location.host+"/theplatform/pdk";

var producerPlayerpath = (window.location.href.match("~rmolguin") == null)? "http://"+window.location.host+"/producerplayer" : (location.href.toString()).substring(0,(location.href.toString()).lastIndexOf('/')) ;


// JAVASCRIPT FILES FOR PLAYER =================================================
document.write('<script type="text/javascript" src="'+PDKpath+'/js/swfobject.js"></script>');
document.write('<script type="text/javascript" src="'+PDKpath+'/js/util.js"></script>');
/*document.write('<script type="text/javascript" src="'+PDKpath+'/js/qos.js"></script>');
document.write('<script type="text/javascript" src="'+PDKpath+'/js/qos_mps.js"></script>');*/


// XML OBJECT FOR LOADING SKIN THEMES ==========================================
// THIS METHOD IS TAKING FROM APPLE SO TO BE COMPATIBLE WITH SAFARI
// PREVIOUS METHOD WAS ONLY FUNCTIONING ON FIREFOX AND IE
// CODE SOURCE AND DOCUMENTATION CAN BE FOUND HERE: http://developer.apple.com/internet/webcontent/xmlhttpreq.html

var req;
var _component;

function loadXMLDoc(url, component) {
    req = false;
    _component = component;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
        try {
            req = new XMLHttpRequest();
        } catch(e) {
            req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
           try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
          } catch(e) {
            try {
                  req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                  req = false;
            }
        }
    }
    if(req) {
        req.onreadystatechange = processReqChange;
        req.open("GET",url, true);
        req.send("");
    }
}

function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
           if (_component == 'player') playerwidget();
           else if (_component == 'releaseList') releaselistwidget();
           else if (_component == 'categoryList') categorylistwidget();
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}

function getUrlVars(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for(var i = 0; i < hashes.length; i++){
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }

    return vars;
}
var GET_vars = getUrlVars();


// VARS FOR PRODUCER PLAYER ====================================================
var playerType;
var accountPortalID;
var account;
var feedServiceURL;
var category;
var showCategory; //REMOVE THIS ONCE ALL PRODUCERS HAVE FUNCTIONING CP ACCOUNTS
var keywords;
var videoPID;
var IsClip;
var releasesEndIndex;
var releaseCols;
var categoriesEndIndex;
var showsEndIndex;
var initVolume;

var playerShape;
var playerColorScheme;
var player_backgroundColor;
var player_controlBackgroundColor;
var player_controlColor;
var player_controlFrameColor;
var player_controlHighlightColor;
var player_controlHoverColor;
var player_controlSelectedColor;
var player_frameColor;
var player_loadProgressColor;
var player_pageBackgroundColor;
var player_playProgressColor;
var player_scrubberColor;
var player_scrubberFrameColor;
var player_scrubTrackColor;
var player_textBackgroundColor;
var player_textColor;

var releaseListShape;
var releaseListColorScheme;
var releaseListShape;
var releaseListColorScheme;
var releaseList_backgroundColor;
var releaseList_frameColor;
var releaseList_itemBackgroundColor;
var releaseList_itemBackgroundHoverColor;
var releaseList_itemBackgroundSelectedColor;
var releaseList_itemFrameColor;
var releaseList_itemShineHoverColor;
var releaseList_itemShineSelectedColor;
var releaseList_textColor;
var releaseList_textFrameColor;
var releaseList_textHighlightHoverColo;
var releaseList_textHighlightSelectedColor;
var releaseList_textHoverColor;
var releaseList_textSelectedColor;
var releaseList_thumbnailBackgroundColor;
var releaseList_thumbnailFrameColor;
var releaseList_thumbnailHighlightHoverColor;

//var showReleaseList;
//var showBanner;
var dockReleaseList;
var dockBanner;

var accounts = {};
    accounts["PBS DP KidsGo"] = "6HSLquMebdOkNaEygDWyPOIbkPAnQ0_C";
    accounts["PBS CP KidsGo"] = "rjSDErhLvLTAl4Q__FuvtUBOdfslKYDM";
    accounts["PBS CP Dinotrain"] = "nlu5cq0TAhJFmMxz6UHICDaQuwA3BM8l";
    accounts["PBS CP Dinotrain - Teachers Only"] = "KfgHX5RO3Cj_kbgnjO7pZD5Eg0dROxPq";
    accounts["PBS CP Design Squad"] = "evmPR63qFtMP_DTTMafPf6Xk0l0tYQhF";
    accounts["PBS CP Fizzy's Lunch Lab"] = "jiBv1nS4k8XVW2z1GDQh7vfQDVMCOsS_";
    accounts["PBS CP Fizzy's Lunch Lab - Teachers Only"] = "ft7m2IVrYpWIFD8VkTukl8GT8huDdhPb";

var hostAccount = ["PBS CP Dinotrain",    //"Dinosaur Train",
                   "PBS CP Dinotrain - Teachers Only",    //"Dinosaur Train Teachers",
                   "PBS CP Dinotrain - Teachers Only",    //"Dinosaur Train Teachers",
                   "PBS CP KidsGo",    //"Animalia",
                   "PBS CP KidsGo",    //"Arthur",
                   "PBS CP KidsGo",    //"Between the Lions",
                   "PBS CP KidsGo",    //"Cyberchase",
                   "PBS CP Design Squad",    //"Design Squad",
                   "PBS CP Design Squad",    //"Design Squad",
                   "PBS CP KidsGo",    //"DragonflyTV",
                   "PBS CP KidsGo",    //"FETCH! with Ruff Ruffman",
                   "PBS CP Fizzy's Lunch Lab",    //"Fizzy’s Lunch Lab",
                   "PBS CP Fizzy's Lunch Lab - Teachers Only",    //"Fizzy’s Lunch Lab",
                   "PBS CP Fizzy's Lunch Lab - Teachers Only",    //"Fizzy’s Lunch Lab",
                   "PBS CP KidsGo",    //"It's My Life",
                   "PBS CP KidsGo",    //"Kids World Sports",
                   "PBS CP KidsGo",    //"Kratts' Creatures",
                   "PBS CP KidsGo",    //"Martha Speaks",
                   "PBS CP KidsGo",    //"Maya & Miguel",
                   "PBS CP KidsGo",    //"Postcards from Buster",
                   "PBS CP KidsGo",    //"The Electric Company",
                   "PBS CP KidsGo",    //"WordGirl",
                   "PBS CP KidsGo",    //"ZOOM",
                   "PBS CP KidsGo",    //"The Greens",
                   "PBS CP KidsGo",    //"From the Top at Carnegie Hall",
                   "PBS CP KidsGo",    //"station"
                 ];

var hostPrograms = ["pbskids.org/dinosaurtrain/",
                    ".org/teachers/dinosaurtrain/",
                    ".org/parents/dinosaurtrain/",
                    "pbskids.org/animalia/",
                    "pbskids.org/arthur/",
                    "pbskids.org/lions/",
                    "pbskids.org/cyberchase/",
                    "pbskids.org/designsquad/",
                    "pbs.org/designsquad/",
                    "pbskids.org/dragonflytv/",
                    "pbskids.org/fetch/",
                    "pbskids.org/lunchlab/",
                    ".org/teachers/lunchlab/",
                    ".org/parents/lunchlab/",
                    "pbskids.org/itsmylife/",
                    "pbskids.org/kws/",
                    "pbskids.org/krattscreatures/",
                    "pbskids.org/martha/",
                    "pbskids.org/mayaandmiguel/",
                    "pbskids.org/buster/",
                    "pbskids.org/electriccompany/",
                    "pbskids.org/wordgirl/",
                    "pbskids.org/zoom/",
                    "meetthegreens.pbskids.org/",
                    "www.pbs.org/wgbh/fromthetop/pages/",
                    "stationplayer.html"
                   ];

var showCategories = ["Dinosaur Train",
                      "Dinosaur Train",
                      "Dinosaur Train",
                      "Animalia",
                      "Arthur",
                      "Between the Lions",
                      "Cyberchase",
                      "Design Squad",
                      "Design Squad",
                      "DragonflyTV",
                      "FETCH! with Ruff Ruffman",
                      "Fizzy's Lunch Lab",
                      "Fizzy's Lunch Lab",
                      "Fizzy's Lunch Lab",
                      "It's My Life",
                      "Kids World Sports",
                      "Kratts' Creatures",
                      "Martha Speaks",
                      "Maya & Miguel",
                      "Postcards from Buster",
                      "The Electric Company",
                      "WordGirl",
                      "ZOOM",
                      "The Greens",
                      "From the Top at Carnegie Hall",
                      "station"
                 ];



// INITIATE PRODUCER PLAYER ====================================================
if(!this.pbs) this.pbs = {};
if(!pbs.kidsgo) pbs.kidsgo = {};
pbs.kidsgo.producerplayer = {};

pbs.kidsgo.producerplayer.init = function (_stationID, _supersite, _configObj) {
    hostProgram = ((window.location.href.toString()).indexOf(".org/producerplayer/") != -1 || (window.location.href.toString()).indexOf("~rmolguin/") != -1) ? _configObj.hostProgram : window.location.href.toString();
    category = _configObj && _configObj.category ? _configObj.category : "" ;
    
    if (category == 'Teachers' && hostProgram == "pbskids.org/dinosaurtrain/") {
        hostProgram = ".org/teachers/dinosaurtrain/";
    }
    
    if (category == 'Teachers' && hostProgram == "pbskids.org/lunchlab/") {
        hostProgram = ".org/teachers/lunchlab/";
    }

    for (var i = 0 ;  i < hostPrograms.length ; i++){
        if(hostProgram.indexOf(hostPrograms[i]) != -1){
            account = accounts[hostAccount[i]];
            showCategory = showCategories[i] ;//if (account == accounts["PBS DP KidsGo"] || account == accounts["PBS CP KidsGo"]) showCategory = categories[i] ;
            break;
        }
    }
    
    
   //GET PID FROM URL ==================================================================
    accountPortalID = _configObj && _configObj.feedID ? _configObj.feedID : account; //production feed if not other feed is set
    feedServiceURL  = _configObj && _configObj.feedURL ? _configObj.feedURL : "http://feeds.theplatform.com/ps/JSON/PortalService/2.2";
    autoPlay = _configObj && _configObj.autoPlay ? _configObj.autoPlay : "true"; 

    keywords = _configObj && _configObj.keywords ? _configObj.keywords.replace(/\s/g,"").split(',') : {};
    videoPID = (GET_vars["pid"]) ? GET_vars["pid"] : _configObj && _configObj.videoPID ? _configObj.videoPID : "" ;
    IsClip = _configObj && _configObj.IsClip ? _configObj.IsClip : "" ;

    releasesEndIndex = _configObj && _configObj.releaseEndIndex ? _configObj.releaseEndIndex : 20;
    categoriesEndIndex = _configObj && _configObj.categoriesEndIndex ? _configObj.categoriesEndIndex : 75;
    showsEndIndex = _configObj && _configObj.showsEndIndex ? _configObj.showsEndIndex : 30;
    initVolume = (_configObj && _configObj.initVolume) || _configObj.initVolume == 0 ? _configObj.initVolume : 50;

    // SKIN AND POSITION COMPONENTS =====================================================
    playerShape = _configObj && _configObj.playerShape ? _configObj.playerShape : "skinKidsGoSquared";
    playerColorScheme = _configObj && _configObj.customizePlayerTheme != "true" ? _configObj && _configObj.playerColorScheme ? _configObj.playerColorScheme : "go-theme" : "" ;
    player_backgroundColor  = (_configObj && _configObj.player_backgroundColor) ? _configObj.player_backgroundColor : "";
    player_controlBackgroundColor  = (_configObj && _configObj.player_controlBackgroundColor) ? _configObj.player_controlBackgroundColor : "";
    player_controlColor  = (_configObj && _configObj.player_controlColor) ? _configObj.player_controlColor : "";
    player_controlFrameColor  = (_configObj && _configObj.player_controlFrameColor) ? _configObj.player_controlFrameColor : "";
    player_controlHighlightColor  = (_configObj && _configObj.player_controlHighlightColor) ? _configObj.player_controlHighlightColor : "";
    player_controlHoverColor  = (_configObj && _configObj.player_controlHoverColor) ? _configObj.player_controlHoverColor : "";
    player_controlSelectedColor  = (_configObj && _configObj.player_controlSelectedColor) ? _configObj.player_controlSelectedColor : "";
    player_frameColor  = (_configObj && _configObj.player_frameColor) ? _configObj.player_frameColor : "";
    player_loadProgressColor  = (_configObj && _configObj.player_loadProgressColor) ? _configObj.player_loadProgressColor : "";
    player_pageBackgroundColor  = (_configObj && _configObj.player_pageBackgroundColor) ? _configObj.player_pageBackgroundColor : "";
    player_playProgressColor  = (_configObj && _configObj.player_playProgressColor) ? _configObj.player_playProgressColor : "";
    player_scrubberColor  = (_configObj && _configObj.player_scrubberColor) ? _configObj.player_scrubberColor : "";
    player_scrubberFrameColor  = (_configObj && _configObj.player_scrubberFrameColor) ? _configObj.player_scrubberFrameColor : "";
    player_scrubTrackColor  = (_configObj && _configObj.player_scrubTrackColor) ? _configObj.player_scrubTrackColor : "";
    player_textBackgroundColor  = (_configObj && _configObj.player_textBackgroundColor) ? _configObj.player_textBackgroundColor : "";
    player_textColor  = (_configObj && _configObj.player_textColor) ? _configObj.player_textColor : "";

    releaseListShape = _configObj && _configObj.releaseListShape ? _configObj.releaseListShape : "skinKidsGoSquared";
    releaseListColorScheme = _configObj && _configObj.customizeReleaseListTheme != "true" ? _configObj && _configObj.releaseListColorScheme ? _configObj.releaseListColorScheme : "go-theme" : "" ;
    releaseList_backgroundColor = (_configObj && _configObj.releaseList_backgroundColor) ? _configObj.releaseList_backgroundColor : "";
    releaseList_frameColor = (_configObj && _configObj.releaseList_frameColor) ? _configObj.releaseList_frameColor : "";
    releaseList_itemBackgroundColor = (_configObj && _configObj.releaseList_itemBackgroundColor) ? _configObj.releaseList_itemBackgroundColor : "";
    releaseList_itemBackgroundHoverColor = (_configObj && _configObj.releaseList_itemBackgroundHoverColor) ? _configObj.releaseList_itemBackgroundHoverColor : "";
    releaseList_itemBackgroundSelectedColor = (_configObj && _configObj.releaseList_itemBackgroundSelectedColor) ? _configObj.releaseList_itemBackgroundSelectedColor : "";
    releaseList_itemFrameColor = (_configObj && _configObj.releaseList_itemFrameColor) ? _configObj.releaseList_itemFrameColor : "";
    releaseList_itemShineHoverColor = (_configObj && _configObj.releaseList_itemShineHoverColor) ? _configObj.releaseList_itemShineHoverColor : "";
    releaseList_itemShineSelectedColor = (_configObj && _configObj.releaseList_itemShineSelectedColor) ? _configObj.releaseList_itemShineSelectedColor : "";
    releaseList_textColor = (_configObj && _configObj.releaseList_textColor) ? _configObj.releaseList_textColor : "";
    releaseList_textFrameColor = (_configObj && _configObj.releaseList_textFrameColor) ? _configObj.releaseList_textFrameColor : "";
    releaseList_textHighlightHoverColor = (_configObj && _configObj.releaseList_textHighlightHoverColor) ? _configObj.releaseList_textHighlightHoverColor : "";
    releaseList_textHighlightSelectedColor = (_configObj && _configObj.releaseList_textHighlightSelectedColor) ? _configObj.releaseList_textHighlightSelectedColor : "";
    releaseList_textHoverColor = (_configObj && _configObj.releaseList_textHoverColor) ? _configObj.releaseList_textHoverColor : "";
    releaseList_textSelectedColor = (_configObj && _configObj.releaseList_textSelectedColor) ? _configObj.releaseList_textSelectedColor : "";
    releaseList_thumbnailBackgroundColor = (_configObj && _configObj.releaseList_thumbnailBackgroundColor) ? _configObj.releaseList_thumbnailBackgroundColor : "";
    releaseList_thumbnailFrameColor = (_configObj && _configObj.releaseList_thumbnailFrameColor) ? _configObj.releaseList_thumbnailFrameColor : "";
    releaseList_thumbnailHighlightHoverColor = (_configObj && _configObj.releaseList_thumbnailHighlightHoverColor) ? _configObj.releaseList_thumbnailHighlightHoverColor : "";
    releaseList_thumbnailHighlightSelectedColor = (_configObj && _configObj.releaseList_thumbnailHighlightSelectedColor) ? _configObj.releaseList_thumbnailHighlightSelectedColor : "";
    releaseList_thumbnailPaddingColor = (_configObj && _configObj.releaseList_thumbnailPaddingColor) ? _configObj.releaseList_thumbnailPaddingColor : "";
    releaseList_scrollButBackgroundColor = (_configObj && _configObj.releaseList_scrollButBackgroundColor) ? _configObj.releaseList_scrollButBackgroundColor : "";
    releaseList_scrollButArrowColor = (_configObj && _configObj.releaseList_scrollButArrowColor) ? _configObj.releaseList_scrollButArrowColor : "";
    releaseList_scrollButFrameColor = (_configObj && _configObj.releaseList_scrollButFrameColor) ? _configObj.releaseList_scrollButFrameColor : "";

    dockReleaseList = _configObj && _configObj.dockReleaseList ? _configObj.dockReleaseList : "left";
    //showReleaseList = _configObj && _configObj.showReleaseList ? _configObj.showReleaseList : "true";
    dockBanner = _configObj && _configObj.dockBanner ? dockReleaseList == "false" && _configObj.dockBanner == "releaseListTop" ? "false" : _configObj.dockBanner : dockReleaseList == "false" ? "false": "releaseListTop";
    //showBanner = dockBanner == "releaseListTop" && showReleaseList == "false" ? "false" : _configObj && _configObj.showBanner ? _configObj.showBanner : "true";

    dockScrollButtons = _configObj && _configObj.dockScrollButtons ? _configObj.dockScrollButtons : "bottom";

    playerWidth = _configObj && _configObj.playerWidth ? Math.max(_configObj.playerWidth, 280) : 480;
    //playerWidth +=    8; // add 4px to each side of the player for the width of the border
    playerHeight = playerWidth/4 * 3 + 4 + 4 + 65;

    bannerHeight = ( (dockReleaseList == "false" && dockBanner == "releaseListTop") || (dockBanner == "false")) ? 0 : 77;

    releaseListWidth = (dockReleaseList == "false") ? 1 : (dockReleaseList == "top" || dockReleaseList == "bottom") ? playerWidth : _configObj && _configObj.releaseListWidth ? Math.max(_configObj.releaseListWidth, 220) : playerWidth;

    bannerWidth = (dockBanner == "releaseListTop") ? releaseListWidth : playerWidth;

    releaseListHeight = (dockReleaseList == "false") ? 1 : (dockReleaseList == "left" || dockReleaseList == "right") ? (dockBanner != "false") ? (dockBanner == "releaseListTop") ? playerHeight - bannerHeight: playerHeight + bannerHeight - 10: playerHeight - 10: _configObj && _configObj.releaseListHeight ? _configObj.releaseListHeight : (dockBanner != "false") ? playerHeight - bannerHeight: playerHeight ;

    navHeight = (dockReleaseList == "false" || dockScrollButtons == "top") ? 0 : 40;

    releaseListHeight =  releaseListHeight - navHeight;
    
    categoryListHeight = bannerHeight + releaseListHeight + navHeight;
    categoryListWidth = releaseListWidth;
    
    itemsPerPage = releasesEndIndex;
    
    backButtonMargin_left = 5;
    backButtonMargin_right = 0;
    backButtonMargin_bottom = 9;
    backButtonHeight = 29;
    backButtonWidth = 65;

    containerXpos = _configObj && _configObj.containerXpos ? _configObj.containerXpos : 0;
    containerYpos = _configObj && _configObj.containerYpos ? _configObj.containerYpos : 0;
    
    releaseCols = _configObj && _configObj.releaseCols ? _configObj.releaseCols : 1;
    
    PositionComponents();
}

// STYLES TO HANDLE COMPONET POSITIONS AND BACKGROUND SETTINGS =================
function PositionComponents() {
    styles = "<style type='text/css'>";

    styles += ".holder {";
    styles += " position:relative;";
    styles += dockReleaseList == "left" || dockReleaseList == "right"? "width:"+(playerWidth + releaseListWidth + 5 )+"px;" : " width:"+playerWidth+"px;";
/*    styles += " left:"+containerXpos+"px;";
    styles += " top:"+containerYpos+"px;";*/
    styles += dockReleaseList == "bottom" || dockReleaseList == "top" ?  " height:"+ (playerHeight + releaseListHeight + navHeight + bannerHeight) +"px;" : dockBanner == "playerTop" ? "height:"+(playerHeight + bannerHeight) +"px;" :"height:"+(playerHeight) +"px;" ;
    styles += "}";

    styles += "\r.player {";
    styles += " float:left;";
    styles += " position:relative;";
    styles += " top:0px;";
    styles += " left:0px;";
    styles += " z-index:2;";
    styles += "}";

    styles += "\r.releaseList {";
    styles += (playerType == "stationPlayer") ? " display:none;" : "";
    styles += " float:left;";
    styles += " position:relative;";
    styles += " top:0px;";
    styles += " left:0px;";
    styles += (dockReleaseList == "false") ? "width:0px" : " width:"+releaseListWidth+"px;";
    styles += (dockReleaseList == "false") ? "height:0px" : "";
    styles += (dockBanner == "releaseListTop") ? "padding:0xp;" :  "padding: 10px 0px 0px;";
    styles += "}";

    styles += "\r.playerContainer {";
    styles += (dockReleaseList == "left" && account!=undefined) ? " float:right;" : "";
    styles += " position:relative;";
    styles += " top:0px;";
    styles += " left:0px;";
    styles += " width:"+playerWidth+"px;";
    styles += "}";

    styles += "\r.releaseListContainer {";
    styles += (dockReleaseList == "right") ? " float:right;" : "";
    styles += " position:relative;";
    styles += " top:0px;";
    styles += " left:0px;";
    styles += " width:"+releaseListWidth+"px;";
    styles += "}";

    styles += "\r.bannerContainer {";
    styles += (playerType == "stationPlayer") ? " display:none;" : "";
    styles += " float:left;";
    styles += " position:relative;";
    styles += " top:0px;";
    styles += " left:0px;";
    styles += " height:"+bannerHeight+"px;";
    styles += " z-index: 5;";
    styles += "}";
    
    styles += "\r.categoryList {";
    styles += " float:left;";
    styles += " position:relative;";
    styles += " top:0px;";
    styles += " left:0px;";
    styles += " width:"+releaseListWidth+"px;";
    styles += (dockBanner == "releaseListTop") ? "padding:0xp;" :  "padding: 10px 0px 0px;";
    styles += (playerType != "stationPlayer") ? " display:none;" : "";
    styles += "}";
    
    styles += "\r.backToCategories {";
    styles += " display:none;";
    styles += " position:relative;";
    styles += " top:-"+(backButtonHeight+backButtonMargin_bottom)+"px;";
    styles += " margin-left:"+backButtonMargin_left+"px;";
    styles += " margin-right:"+backButtonMargin_right+"px;";
    styles += " height:0px;";
    styles += " width:"+backButtonWidth+"px;";
    styles += "}";
    styles += "</style>";
    document.write(styles);

    drawplayer();
}

// DRAW DIVS FOR COMPONENTS ====================================================
function drawplayer() {
    playerHolder  = '    <div class="playerContainer" id="playerContainerDiv">';
    playerHolder += (dockBanner == "playerTop") ? '        <div class="bannerContainer" id="bannerContainerDiv"></div>' : '';
    playerHolder += '        <div class="player" id="playerDiv">';
    playerHolder += '            <p style="font:10pt Verdana; color:#FFF4EB">To view this site, you need to have Flash Player 9.0 or later installed. Click ';
    playerHolder += '                <a href="http://www.macromedia.com/go/getflashplayer/"target=\'_blank\' style="color:#FFF4EB">here</a>';
    playerHolder += '                to get the latest Flash player.';
    playerHolder += '            </p>';
    playerHolder += '        </div>';
    playerHolder += '    </div>';

    releaseListHolder  = '    <div class="releaseListContainer" id="releaseListContainerDiv">';
    releaseListHolder += (dockBanner == "releaseListTop") ? '        <div class="bannerContainer" id="bannerContainerDiv"></div>' : '';
    releaseListHolder += '        <div class="releaseList" id="releaseListDiv"></div>';
    releaseListHolder += '        <div class="categoryList" id="categoryListDiv"></div>';
    releaseListHolder += '        <div class="categoryModel" id="categoryModelDiv"></div>';/////////////////////////////////////////////////////
    releaseListHolder += '        <div class="releaseModel" id="releaseModelDiv"></div>';
    releaseListHolder += '        <div class="backToCategories" id="backToCategories"></div>';
    releaseListHolder += '    </div>';

    document.write('<div class="holder" id="pdkHolder">');
    if (dockReleaseList == "left" || dockReleaseList == "bottom" || dockReleaseList == "false") document.write(playerHolder);
    if (account!=undefined) document.write(releaseListHolder);
    if (dockReleaseList == "right" || dockReleaseList == "top") document.write(playerHolder);
    document.write('</div>');

    // INITIATE COMMUNICATION MANAGER ============================
    // First, set the ID for the communication manager.
    // This function also initializes the PDK internals.
    // Do this before doing anything else with PDK components.
    tpSetCommManagerID("communicationwidget",true,PDKpath+"/swf/commManager.swf");

    // LOAD XML FOR PLAYER COLOR SCHEME ===============================
    if (playerColorScheme != "") loadXMLDoc(producerPlayerpath+"/themes/"+playerColorScheme+".xml", 'player');
    else playerwidget();

}

// FUNCTIONS TO INITIATE COMPONENTS ============================================
function playerwidget() {
    // The first line registers the component name with the framework
    tpRegisterID("playerwidget");

    // The next line creates the component object in memory.
    // The first parameter is the path to the component's Flash movie file.
    // The second parameter is the component's registration name.
    // The third and fourth parameters are the width and height of the component.
    // The fifth parameter sets the minimum required Adobe Flash player version.
    var so = new SWFObject(PDKpath+"/swf/flvPlayer.swf", "playerwidget",  playerWidth, playerHeight, "9.0.0.0", "#000000");

    // These items set some sensible defaults on the Flash browser control.
    so.addParam("scale", "noscale");
    so.addParam("salign", "tl");
    so.addParam("menu", "false");
    so.addParam("wmode", "transparent");


    // This is an important one for the FLVPlayer, but not the other components.
    so.addParam("allowFullScreen", "true");

    // Next come the variables for the component itself.

    // Tell the component what its unique ID is.
    so.addVariable("ID", "playerwidget");

    // Set the logging level for the component.
    // This is equivalent to the default.
    so.addVariable("logLevel", "warn");

    // Even though we told the Flash control to allow full screen,
    // we also have to tell the component itself.
    so.addVariable("allowFullScreen", "true");

    // Earlier we told the Flash control what its size is.
    // Now we also have to tell the component how big to be.
    so.addVariable("height", playerHeight);
    so.addVariable("width",  playerWidth);


   if (playerWidth > 359) {
       so.addVariable("layoutURL", producerPlayerpath+"/data/metaLayout.xml");    // Use this variable to import a custom control layout data file.
       so.addVariable("skinURL", producerPlayerpath+"/swf/"+playerShape+".swf");    // Next we tell the component which skin to use.
   } else if (playerWidth > 279) {
       so.addVariable("layoutURL", producerPlayerpath+"/data/metaLayout_med.xml");
       so.addVariable("skinURL", producerPlayerpath+"/swf/"+playerShape+"_med.swf");
   } else {
       so.addVariable("layoutURL", producerPlayerpath+"/data/metaLayout_small.xml");
        so.addVariable("skinURL", producerPlayerpath+"/swf/"+playerShape+"_small.swf");
   }
    //so.addVariable("plugin0", "type=control|URL=swf/sampleControlPlugIn.swf|scale=false");

    // True to start playing onload   ;  False: to let the user start playback by clicking the play overlay.
    so.addVariable("autoPlay",autoPlay);
    
    if(videoPID != "") {
        // Select a release for playback.
        so.addVariable("releaseURL", "http://release.theplatform.com/content.select?pid="+videoPID);
    }

    var _link  = window.location.href.toString();
        _link += window.location.href.toString().indexOf("?") == -1 ? "?pid={releasePID}" : "&pid={releasePID}";
    so.addVariable("playerURL", _link);

    tpController.setVolume(initVolume);

    // Set a "bug" overlay image in the lower-right
    //so.addVariable("overlayImageURL", "images/logo_bug.png");

   //so.addVariable("plugin0", "type=control|URL=swf/sampleControlPlugIn.swf");

    // Near the end we set color values for the items in the component and the skin.
    if (playerColorScheme != "") {
        playerSkin = req.responseXML.getElementsByTagName("skins")[0].getElementsByTagName("player")[0];

        if (playerSkin.getElementsByTagName("backgroundColor")[0])         so.addVariable("backgroundColor", playerSkin.getElementsByTagName("backgroundColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("controlBackgroundColor")[0])  so.addVariable("controlBackgroundColor", playerSkin.getElementsByTagName("controlBackgroundColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("controlColor")[0])            so.addVariable("controlColor", playerSkin.getElementsByTagName("controlColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("controlFrameColor")[0])       so.addVariable("controlFrameColor", playerSkin.getElementsByTagName("controlFrameColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("controlHighlightColor")[0])   so.addVariable("controlHighlightColor", playerSkin.getElementsByTagName("controlHighlightColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("controlHoverColor")[0])       so.addVariable("controlHoverColor", playerSkin.getElementsByTagName("controlHoverColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("controlSelectedColor")[0])    so.addVariable("controlSelectedColor", playerSkin.getElementsByTagName("controlSelectedColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("frameColor")[0])              so.addVariable("frameColor", playerSkin.getElementsByTagName("frameColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("loadProgressColor")[0])       so.addVariable("loadProgressColor", playerSkin.getElementsByTagName("loadProgressColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("pageBackgroundColor")[0])     so.addVariable("pageBackgroundColor", playerSkin.getElementsByTagName("pageBackgroundColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("playProgressColor")[0])       so.addVariable("playProgressColor", playerSkin.getElementsByTagName("playProgressColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("scrubberColor")[0])           so.addVariable("scrubberColor", playerSkin.getElementsByTagName("scrubberColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("scrubberFrameColor")[0])      so.addVariable("scrubberFrameColor", playerSkin.getElementsByTagName("scrubberFrameColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("scrubTrackColor")[0])         so.addVariable("scrubTrackColor", playerSkin.getElementsByTagName("scrubTrackColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("textBackgroundColor")[0])     so.addVariable("textBackgroundColor", playerSkin.getElementsByTagName("textBackgroundColor")[0].childNodes[0].nodeValue);
        if (playerSkin.getElementsByTagName("textColor")[0])               so.addVariable("textColor", playerSkin.getElementsByTagName("textColor")[0].childNodes[0].nodeValue);
    } else {
        if (player_backgroundColor != "")         so.addVariable("backgroundColor", player_backgroundColor);
        if (player_controlBackgroundColor != "")  so.addVariable("controlBackgroundColor", player_controlBackgroundColor);
        if (player_controlColor != "")            so.addVariable("controlColor", player_controlColor);
        if (player_controlFrameColor != "")       so.addVariable("controlFrameColor", player_controlFrameColor);
        if (player_controlHighlightColor != "")   so.addVariable("controlHighlightColor", player_controlHighlightColor);
        if (player_controlHoverColor != "")       so.addVariable("controlHoverColor", player_controlHoverColor);
        if (player_controlSelectedColor != "")    so.addVariable("controlSelectedColor", player_controlSelectedColor);
        if (player_frameColor != "")              so.addVariable("frameColor", player_frameColor);
        if (player_loadProgressColor != "")       so.addVariable("loadProgressColor", player_loadProgressColor);
        if (player_pageBackgroundColor != "")     so.addVariable("pageBackgroundColor", player_pageBackgroundColor);
        if (player_playProgressColor != "")       so.addVariable("playProgressColor", player_playProgressColor);
        if (player_scrubberColor != "")           so.addVariable("scrubberColor", player_scrubberColor);
        if (player_scrubberFrameColor != "")      so.addVariable("scrubberFrameColor", player_scrubberFrameColor);
        if (player_scrubTrackColor != "")         so.addVariable("scrubTrackColor", player_scrubTrackColor);
        if (player_textBackgroundColor != "")     so.addVariable("textBackgroundColor", player_textBackgroundColor);
        if (player_textColor != "")               so.addVariable("textColor", player_textColor);
    }
    // The last step is to write the settings information into the HTML document.
    so.write("playerDiv");

    if(playerType != "stationPlayer") releasemodelwidget();
    if(playerType == "stationPlayer") loadXMLDoc(producerPlayerpath+"/themes/"+releaseListColorScheme+".xml", 'categoryList');

}

function bannercontainer() {
    // The first line registers the component name with the framework
    tpRegisterID("bannercontainer");

    // The next line creates the component object in memory.
    // The first parameter is the path to the component's Flash movie file.
    // The second parameter is the component's registration name.
    // The third and fourth parameters are the width and height of the component.
    // The fifth parameter sets the minimum required Adobe Flash player version.
    var so = new SWFObject(producerPlayerpath+"/swf/bannercontainer.swf", "bannercontainer", bannerWidth, bannerHeight, "9.0.0.0");

    // These items set some sensible defaults on the Flash browser control.
    so.addParam("wmode", "transparent");
    so.addParam("scale", "noscale");
    so.addParam("salign", "t");
    so.addParam("menu", "false");

    // Next come the variables for the component itself.

    // Tell the component what its unique ID is.
    so.addVariable("ID", "bannercontainer");

    // Set the logging level for the component.
    // This is equivalent to the default.
    so.addVariable("logLevel", "warn");

    // Earlier we told the Flash control what its size is.
    // Now we also have to tell the component how big to be.


    // without requiring any user intervention.
    so.addVariable("category", showCategory);
    so.addVariable("accountPortalID", accounts["PBS DP KidsGo"]);

    // Near the end we set color values for the items in the component and the skin to match the color of the releaseListSkin background.
    if (dockBanner == "playerTop") {
        if (playerColorScheme != "")  {
            if (playerSkin.getElementsByTagName("backgroundColor")[0]) so.addVariable("backgroundColor", playerSkin.getElementsByTagName("backgroundColor")[0].childNodes[0].nodeValue);
        } else
            if (player_backgroundColor != "") so.addVariable("backgroundColor", player_backgroundColor);

    } else {
        if (releaseListColorScheme != "") {
            if (releaseListSkin.getElementsByTagName("backgroundColor")[0]) so.addVariable("backgroundColor", releaseListSkin.getElementsByTagName("backgroundColor")[0].childNodes[0].nodeValue);
        } else
            if (releaseList_backgroundColor != "") so.addVariable("backgroundColor", releaseList_backgroundColor);
    }


    so.addVariable("backgroundWidth", bannerWidth);
    so.addVariable("backgroundHeight", bannerHeight);


    // The last step is to write the settings information into the HTML document.
    so.write("bannerContainerDiv");
}


function releaselistwidget() {
    // The first line registers the component name with the framework
    tpRegisterID("releaselistwidget");

    // The next line creates the component object in memory.
    // The first parameter is the path to the component's Flash movie file.
    // The second parameter is the component's registration name.
    // The third and fourth parameters are the width and height of the component.
    // The fifth parameter sets the minimum required Adobe Flash player version.
    var so = new SWFObject(PDKpath+"/swf/releaseList.swf", "releaselistwidget", releaseListWidth+"px", (releaseListHeight + navHeight)+"px", "9.0.0.0");

    // These items set some sensible defaults on the Flash browser control.
    so.addParam("wmode", "transparent");
    so.addParam("scale", "noscale");
    so.addParam("salign", "tl");
    so.addParam("menu", "false");

    // Next come the variables for the component itself.

    // Tell the component what its unique ID is.
    so.addVariable("ID", "releaselistwidget");

    // Set the logging level for the component.
    // This is equivalent to the default.
    so.addVariable("logLevel", "warn");

    // Earlier we told the Flash control what its size is.
    // Now we also have to tell the component how big to be.
    so.addVariable("height", releaseListHeight);
    so.addVariable("width", releaseListWidth + 15);

    // Next we tell the component which skin to use.
    so.addVariable("skinURL", producerPlayerpath+"/swf/"+releaseListShape+".swf");

    // Set the column count for the list and the number of
    // items total to display at any one time. In this case
    // we set a high limit and let the user scroll through the list.
    so.addVariable("allowScrolling", "true");
    so.addVariable("itemsPerPage", itemsPerPage);
    so.addVariable("columns", releaseCols);

    // Next we tell the component how much of each clip's
    // descriptive data should be visible to the user.
    so.addVariable("showAirdate", "false");
    so.addVariable("showAuthor", "false");
    so.addVariable("showBitrate", "false");
    so.addVariable("showDescription", "true");
    so.addVariable("showFormat", "false");
    so.addVariable("showLength", "true");
    so.addVariable("showThumbnail", "true");
    so.addVariable("showTitle", "true");

    // If we show thumbnails in the list, we can also set size params.
    // Graphics will be scaled to fit into this size.
    so.addVariable("thumbnailHeight", 60);
    so.addVariable("thumbnailWidth", 80);

    // We want the canvas to automatically play the first clip
    // in the release list. We also want to play all the clips
    // without requiring any user intervention.
    so.addVariable("autoPlay", autoPlay);
    so.addVariable("playAll", "true");

    // Creates space at the top of the list to overlay another component.
    // In this canvas the if the scroll buttons are to be docked above the ReleaseList
    // then "hasOverlay" is set to "true" so the buttons appear within the release list's
    // top border area. The amount of space created is set in the skin file.
    if (dockScrollButtons == "top") so.addVariable("hasOverlay", "true");

    so.addVariable("dockScrollButtons", dockScrollButtons);
    
    
    if (playerType == "stationPlayer") so.addVariable("backButton", "true");
    else so.addVariable("backButton", "false");

    so.addVariable("backButtonWidth", backButtonWidth); 
    so.addVariable("backButtonMargin_left", backButtonMargin_left);
    so.addVariable("backButtonMargin_right", backButtonMargin_right);    

    // Near the end we set color values for the items in the component and the skin.
    if (releaseListColorScheme != "") {
        releaseListSkin = req.responseXML.getElementsByTagName("skins")[0].getElementsByTagName("releaseList")[0];

        if (releaseListSkin.getElementsByTagName("backgroundColor")[0])                 so.addVariable("backgroundColor", releaseListSkin.getElementsByTagName("backgroundColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("frameColor")[0])                      so.addVariable("frameColor", releaseListSkin.getElementsByTagName("frameColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("itemBackgroundColor")[0])             so.addVariable("itemBackgroundColor", releaseListSkin.getElementsByTagName("itemBackgroundColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("itemBackgroundHoverColor")[0])        so.addVariable("itemBackgroundHoverColor", releaseListSkin.getElementsByTagName("itemBackgroundHoverColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("itemBackgroundSelectedColor")[0])     so.addVariable("itemBackgroundSelectedColor", releaseListSkin.getElementsByTagName("itemBackgroundSelectedColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("itemFrameColor")[0])                  so.addVariable("itemFrameColor", releaseListSkin.getElementsByTagName("itemFrameColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("itemShineHoverColor")[0])             so.addVariable("itemShineHoverColor", releaseListSkin.getElementsByTagName("itemShineHoverColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("itemShineSelectedColor")[0])          so.addVariable("itemShineSelectedColor", releaseListSkin.getElementsByTagName("itemShineSelectedColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("textColor")[0])                       so.addVariable("textColor", releaseListSkin.getElementsByTagName("textColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("textFrameColor")[0])                  so.addVariable("textFrameColor", releaseListSkin.getElementsByTagName("textFrameColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("textHighlightHoverColor")[0])         so.addVariable("textHighlightHoverColor", releaseListSkin.getElementsByTagName("textHighlightHoverColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("textHighlightSelectedColor")[0])      so.addVariable("textHighlightSelectedColor", releaseListSkin.getElementsByTagName("textHighlightSelectedColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("textHoverColor")[0])                  so.addVariable("textHoverColor", releaseListSkin.getElementsByTagName("textHoverColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("textSelectedColor")[0])               so.addVariable("textSelectedColor", releaseListSkin.getElementsByTagName("textSelectedColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("thumbnailBackgroundColor")[0])        so.addVariable("thumbnailBackgroundColor", releaseListSkin.getElementsByTagName("thumbnailBackgroundColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("thumbnailFrameColor")[0])             so.addVariable("thumbnailFrameColor", releaseListSkin.getElementsByTagName("thumbnailFrameColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("thumbnailHighlightHoverColor")[0])    so.addVariable("thumbnailHighlightHoverColor", releaseListSkin.getElementsByTagName("thumbnailHighlightHoverColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("thumbnailHighlightSelectedColor")[0]) so.addVariable("thumbnailHighlightSelectedColor", releaseListSkin.getElementsByTagName("thumbnailHighlightSelectedColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("thumbnailPaddingColor")[0])           so.addVariable("thumbnailPaddingColor", releaseListSkin.getElementsByTagName("thumbnailPaddingColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("scrollButBackgroundColor")[0])           so.addVariable("scrollButBackgroundColor", releaseListSkin.getElementsByTagName("scrollButBackgroundColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("scrollButArrowColor")[0])           so.addVariable("scrollButArrowColor", releaseListSkin.getElementsByTagName("scrollButArrowColor")[0].childNodes[0].nodeValue);
        if (releaseListSkin.getElementsByTagName("scrollButFrameColor")[0])           so.addVariable("scrollButFrameColor", releaseListSkin.getElementsByTagName("scrollButFrameColor")[0].childNodes[0].nodeValue);

        if (releaseListSkin.getElementsByTagName("backgroundColor")[0]) {
            document.getElementById("releaseListContainerDiv").style.background = "#" + releaseListSkin.getElementsByTagName("backgroundColor")[0].childNodes[0].nodeValue.substring(releaseListSkin.getElementsByTagName("backgroundColor")[0].childNodes[0].nodeValue.indexOf("x")+1);
        }
        
    } else {
        if (releaseList_backgroundColor != "")                 so.addVariable("backgroundColor", releaseList_backgroundColor);
        if (releaseList_frameColor != "")                      so.addVariable("frameColor", releaseList_frameColor);
        if (releaseList_itemBackgroundColor != "")             so.addVariable("itemBackgroundColor", releaseList_itemBackgroundColor);
        if (releaseList_itemBackgroundHoverColor != "")        so.addVariable("itemBackgroundHoverColor", releaseList_itemBackgroundHoverColor);
        if (releaseList_itemBackgroundSelectedColor != "")     so.addVariable("itemBackgroundSelectedColor", releaseList_itemBackgroundSelectedColor);
        if (releaseList_itemFrameColor != "")                  so.addVariable("itemFrameColor", releaseList_itemFrameColor);
        if (releaseList_itemShineHoverColor != "")             so.addVariable("itemShineHoverColor", releaseList_itemShineHoverColor);
        if (releaseList_itemShineSelectedColor != "")          so.addVariable("itemShineSelectedColor", releaseList_itemShineSelectedColor);
        if (releaseList_textColor != "")                       so.addVariable("textColor", releaseList_textColor);
        if (releaseList_textFrameColor != "")                  so.addVariable("textFrameColor", releaseList_textFrameColor);
        if (releaseList_textHighlightHoverColor != "")         so.addVariable("textHighlightHoverColor", releaseList_textHighlightHoverColor);
        if (releaseList_textHighlightSelectedColor != "")      so.addVariable("textHighlightSelectedColor", releaseList_textHighlightSelectedColor);
        if (releaseList_textHoverColor != "")                  so.addVariable("textHoverColor", releaseList_textHoverColor);
        if (releaseList_textSelectedColor)                      so.addVariable("textSelectedColor", releaseList_textSelectedColor);
        if (releaseList_thumbnailBackgroundColor != "")        so.addVariable("thumbnailBackgroundColor", releaseList_thumbnailBackgroundColor);
        if (releaseList_thumbnailFrameColor != "")             so.addVariable("thumbnailFrameColor", releaseList_thumbnailFrameColor);
        if (releaseList_thumbnailHighlightHoverColor != "")    so.addVariable("thumbnailHighlightHoverColor", releaseList_thumbnailHighlightHoverColor);
        if (releaseList_thumbnailHighlightSelectedColor != "") so.addVariable("thumbnailHighlightSelectedColor", releaseList_thumbnailHighlightSelectedColor);
        if (releaseList_thumbnailPaddingColor != "")           so.addVariable("thumbnailPaddingColor", releaseList_thumbnailPaddingColor);
        if (releaseList_scrollButBackgroundColor != "")        so.addVariable("scrollButBackgroundColor", releaseList_scrollButBackgroundColor);
        if (releaseList_scrollButArrowColor != "")             so.addVariable("scrollButArrowColor", releaseList_scrollButArrowColor);
        if (releaseList_scrollButFrameColor != "")             so.addVariable("scrollButFrameColor", releaseList_scrollButFrameColor);

        if (releaseList_backgroundColor != "")    document.getElementById("releaseListContainerDiv").style.background = "#" + releaseList_backgroundColor.substring(releaseList_backgroundColor.indexOf("x")+1);
    }


    // The last step is to write the settings information into the HTML document.
    so.write("releaseListDiv");
    if (dockBanner != "false") bannercontainer();

}


function categorylistwidget () {
    // The first line registers the component name with the framework
    //tpRegisterID("categorylistwidget");

    // The next line creates the component object in memory.
    // The first parameter is the path to the component's Flash movie file.
    // The second parameter is the component's registration name.
    // The third and fourth parameters are the width and height of the component.
    // Note the use of percentages here, since the component expands when users
    // select subcategories. See the notes below for more information about how
    // this component is sized.
    // The fifth parameter sets the minimum required Adobe Flash player version.
    var so = new SWFObject("swf/categoryList-GO.swf", "categorylistwidget", categoryListWidth+"px", categoryListHeight+"px", "9.0.0.0");
    var so_back = new SWFObject("swf/skinKidsGOsquare-backToCategories.swf", "backButton", 91+"px", 29+"px", "9.0.0.0");
    
    // Category list requires a wmode of transparent, else it will cover the entire
    // player area when a user expands one of its menus. It also requires 
    // scale be set to noscale and salign be set to tl, else it won't render properly.
     so.addParam("wmode", "transparent");
     so.addParam("scale", "noscale");
     so.addParam("salign", "tl");
     
     so_back.addParam("wmode", "transparent");
     so_back.addParam("scale", "noscale");
     so_back.addParam("salign", "tl");

    // Tell the component what its unique ID is.
    so.addVariable("ID", "categorylistwidget");

    // Set the logging level for the component. 
    // This is equivalent to the default. 
    //so.addVariable("logLevel", "warn");

    // Since the category list expands for showing subcategories,
    // the component has to be told the ID of its parent div element.
    //so.addVariable("divID", "categoryListDiv");

    // Because the category list expands when a user selects an item with
    // subcategories, we have to list two pairs of sizes. The first pair is the
    // base size, the second pair is the maximum amount of space to use
    // when showing child items and submenus.
    // Refer to the PDK User's Guide for details.
    so.addVariable("height", categoryListHeight);
    so.addVariable("width", categoryListWidth);
    /*so.addVariable("expandedHeight", 300);
    so.addVariable("expandedWidth", 795);*/

    // Next we tell the component which skin to use.
    so.addVariable("skinURL", producerPlayerpath+"/swf/"+releaseListShape+".swf");

    // The category list supports some pseudo categories that aren't based
    // off of the content in the feed. These won't appear in the list
    // without being given a position. The text is optional,
    // as each has a default value.
/*    so.addVariable("allChoiceIndex", 1);
    so.addVariable("allChoiceLabel", "All");
    so.addVariable("mostPopularChoiceIndex", 2);
    so.addVariable("mostPopularChoiceLabel", "Most Popular");
*/
    //so.addVariable("flow", "horizontal");
    // Near the end we set color values for the items in the component and the skin.
     if (releaseListColorScheme != "") {
        categoryListSkin = req.responseXML.getElementsByTagName("skins")[0].getElementsByTagName("releaseList")[0];
        
        if (categoryListSkin.getElementsByTagName("scrollButBackgroundColor")[0])      so.addVariable("scrollButBackgroundColor", categoryListSkin.getElementsByTagName("scrollButBackgroundColor")[0].childNodes[0].nodeValue);
        if (categoryListSkin.getElementsByTagName("scrollButArrowColor")[0])           so.addVariable("scrollButArrowColor", categoryListSkin.getElementsByTagName("scrollButArrowColor")[0].childNodes[0].nodeValue);
        if (categoryListSkin.getElementsByTagName("scrollButFrameColor")[0])           so.addVariable("scrollButFrameColor", categoryListSkin.getElementsByTagName("scrollButFrameColor")[0].childNodes[0].nodeValue);
        if (categoryListSkin.getElementsByTagName("backgroundColor")[0])               so.addVariable("backgroundColor", categoryListSkin.getElementsByTagName("backgroundColor")[0].childNodes[0].nodeValue);
     } else {
        if (releaseList_scrollButBackgroundColor != "")        so.addVariable("scrollButBackgroundColor", releaseList_scrollButBackgroundColor);
        if (releaseList_scrollButArrowColor != "")             so.addVariable("scrollButArrowColor", releaseList_scrollButArrowColor);
        if (releaseList_scrollButFrameColor != "")             so.addVariable("scrollButFrameColor", releaseList_scrollButFrameColor);
        if (releaseList_backgroundColor != "")                 so.addVariable("backgroundColor", releaseList_backgroundColor);
     }
         
    //so.addVariable("backgroundColor", "0x383838");
    //so.addVariable("expanderColor", "0xBEBEBE");
    //so.addVariable("expanderHoverColor", "0xBEBEBE");
    //so.addVariable("expanderSelectedColor", "0x00CCFF");
    so.addVariable("frameColor", "0x545759");
    so.addVariable("itemBackgroundColor", "0x383838");
    so.addVariable("itemFrameColor", "0x020202");
    so.addVariable("itemShineColor", "0x545759");
    so.addVariable("itemShineHoverColor", "0xBEBEBE");
    so.addVariable("itemShineSelectedColor", "0x00CCFF");
    //so.addVariable("textColor", "0xBEBEBE");
    //so.addVariable("textFrameColor", "0x242424");
    //so.addVariable("textFrameHoverColor", "0xBEBEBE");
    //so.addVariable("textFrameSelectedColor", "0x00CCFF");
    //so.addVariable("textHoverColor", "0xBEBEBE");
    //so.addVariable("textSelectedColor", "0x00CCFF");

    // The last step is to write the settings information into the HTML document.
    so.write("categoryListDiv");
    if (playerType == "stationPlayer") so_back.write("backToCategories");
    
    releasemodelwidget();
}

/*function categorymodelwidget() {
    // The first line registers the component name with the framework
    tpRegisterID("categorymodelwidget");

    // The next line creates the component object in memory.
    // The first parameter is the path to the component's Flash movie file.
    // The second parameter is the component's registration name.
    // The third and fourth parameters are the width and height of the component.
    // Even though the component isn't visible, it still has to have a nonzero size.
    // The fifth parameter sets the minimum required Adobe Flash player version.
    var so = new SWFObject("swf/categoryModel.swf", "categorymodelwidget", "1", "1", "9.0.0.0");

    // There's no UI for this component, so make it transparent
    so.addParam("wmode", "transparent");

    // Next come the variables for the component itself.

    // Tell the component what its unique ID is.
    so.addVariable("ID", "categorymodelwidget");

    // Set the logging level for the component. 
    // This is equivalent to the default. 
    so.addVariable("logLevel", "warn");

    // Next we tell the component where to obtain its feed data.
    // Give it a server endpoint and a PID. This should be the same as
    // what is set for the releaseModel component.
    so.addVariable("feedPID", accountPortalID);
    so.addVariable("feedsServiceURL",feedServiceURL);

    // The last step is to write the settings information into the HTML document.
    so.write("categoryModelDiv");
    
    categorylistwidget();
}*/

function releasemodelwidget() {
    // The first line registers the component name with the framework
    tpRegisterID("releasemodelwidget");

    // The next line creates the component object in memory.
    // The first parameter is the path to the component's Flash movie file.
    // The second parameter is the component's registration name.
    // The third and fourth parameters are the width and height of the component.
    // Even though the component isn't visible, it still has to have a nonzero size.
    // The fifth parameter sets the minimum required Adobe Flash player version.
    var so = new SWFObject(PDKpath+"/swf/releaseModel.swf", "releasemodelwidget", "1", "1", "9.0.0.0");

    // There's no UI for this component, so make it transparent
    so.addParam("wmode", "transparent");

    // Next come the variables for the component itself.

    // Tell the component what its unique ID is.
    so.addVariable("ID", "releasemodelwidget");

    // Set the logging level for the component.
    // This is equivalent to the default.
    so.addVariable("logLevel", "warn");

    // Next we tell the component where to obtain its feed data.
    // Give it a server endpoint and a PID. This should be the same as
    // what is set for the categoryModel component.


    so.addVariable("feedPID", accountPortalID);
    so.addVariable("feedsServiceURL", feedServiceURL);


    // Next we have to tell the model how many releases will be visible
    // in each page of the ReleaseList in the player. This is based off of
    // some of the ReleaseList FlashVar values.
    so.addVariable("startIndex", 1);
    so.addVariable("endIndex",releasesEndIndex);

    // Set the category/channel/show to list
    if (category != "") so.addVariable("category", category);
    params = "field=contentid";
    params += (IsClip != "") ? "&query=ContentCustomBoolean|IsClip|" + IsClip : "" ;
    params += (showCategory != undefined && account != accounts["PBS CP Dinotrain - Teachers Only"]) ? "&query=Categories|" + showCategory : "";
    for(var i = 0; i < keywords.length; i++){
        params += "&query=KeywordsSearch|" + keywords[i];
    }

    if (params != "") so.addVariable("params", params);

    // Next you can add sort parameters if you want.
    // This would sort items alphabetically by title.
    // The component normally arranges them in
    // the order they are provided by the Feeds Service.
    //so.addVariable("sortDescending", "true");
    //so.addVariable("sortField", "title");

    // The last step is to write the settings information into the HTML document.
    so.write("releaseModelDiv");

    // LOAD XML FOR PLAYER COLOR SCHEME ===============================
    if (releaseListColorScheme == "" || dockReleaseList == "false") releaselistwidget();
    else loadXMLDoc(producerPlayerpath+"/themes/"+releaseListColorScheme+".xml", 'releaseList');
}

function refreshReleaseList(_category){
    //if (category != _category) {
        //alert("refresh Releaselist");
        category = _category;
        tpController.refreshReleaseModel(category, null, null, null);
        bannercontainer();
    //}
    document.getElementById("bannerContainerDiv").style.display = "block";
    document.getElementById("releaseListDiv").style.display = "block";
    document.getElementById("backToCategories").style.display = "block";
    document.getElementById("categoryListDiv").style.display = "none";
}

function backToCategories(){
    /*category = "GO";
    tpController.refreshReleaseModel(category, null, null, null);*/
    document.getElementById("releaseListDiv").style.display = "none";
    document.getElementById("backToCategories").style.display = "none";
    document.getElementById("bannerContainerDiv").style.display = "none";
    document.getElementById("categoryListDiv").style.display = "block";
}