/*
 brightcove.js
 Developer: Brandon Aaskov
 */
var player = "custom_player_02"; //shorthand for ExternalInterface calls
var gImages = [
	"images/main_nav-featured_02.gif", 
	"images/main_nav-fashion_02.gif", 
	"images/main_nav-music_02.gif", 
	"images/main_nav-culture_02.gif", 
	"images/main_nav-karmaloop_02.gif", 
	"images/main_nav-partners_02.gif", 
	"images/main_nav-top10_02.gif", 
	"images/main_nav-shop_karmaloop_02.gif", 
	"images/secondary_nav-featured_02.gif", 
	"images/secondary_nav-fashion_02.gif", 
	"images/secondary_nav-music_02.gif", 
	"images/secondary_nav-culture_02.gif", 
	"images/secondary_nav-karmaloop_02.gif", 
	"images/secondary_nav-partners_02.gif", 
	"images/secondary_nav-top10_02.gif",
	"images/secondary_sort_date_02.gif",
	"images/secondary_sort_title_02.gif",
	"images/secondary_sort_partner-complex_02.gif",
	"images/secondary_sort_partner-clintonsparks_02.gif",
	"images/secondary_sort_partner-ughh_02.gif",
	"images/secondary_sort_partner-robheppler_02.gif"
];
var gLineups = [];
var gLineupIds = [1295326981, 1295326982, 1297307576, 1297312042, 1305011352, 1297294611, 1297312043];
var gLineupName = "";
var gCurrentPartner;
var gCurrentLineup;
var gCurrentLineupId = null;
var gCurrentElement = "featured02";
var gInitialized = false;
var gSortMethod = "FEATURED_TITLE";
var gTitleFound = false;
var isIE6 = false;
if (BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6) isIE6 = true;

var gTitleId = null;
var gLineupId = null;

var url = window.location.toString(); //grabs the URL that's in the address bar
if (url.indexOf("?") !== -1) 
{
    var urlArray = url.split("?"); //splits the URL on the ? into two different chunks - the end chunk has the values we care about
    var bcValues = urlArray[1].split("&"); //splits all of the extra appended values on the ampersand
    for (var i = 0; i < bcValues.length; i++) 
    {
        if (bcValues[i].indexOf("bctid=") !== -1) gTitleId = bcValues[i].substr(6);
        if (bcValues[i].indexOf("bclid=") !== -1) gLineupId = bcValues[i].substr(6);
    }
}

//-------------------------------------------------- IMAGE PRELOADING
//This needs to be reconfigured to use in a loop
//Preloaded object not currently working (below)
//alert(gImages.length);
var image0 = new Image();
image0.src = gImages[0];
var image1 = new Image();
image1.src = gImages[1];
var image2 = new Image();
image2.src = gImages[2];
var image3 = new Image();
image3.src = gImages[3];
var image4 = new Image();
image4.src = gImages[4];
var image5 = new Image();
image5.src = gImages[5];
var image6 = new Image();
image6.src = gImages[6];
var image7 = new Image();
image7.src = gImages[7];
var image8 = new Image();
image8.src = gImages[8];
var image9 = new Image();
image9.src = gImages[9];
var image10 = new Image();
image10.src = gImages[10];
var image11 = new Image();
image11.src = gImages[11];
var image12 = new Image();
image12.src = gImages[12];
var image13 = new Image();
image13.src = gImages[13];
var image14 = new Image();
image14.src = gImages[14];
var image15 = new Image();
image15.src = gImages[15];
var image16 = new Image();
image16.src = gImages[16];
var image17 = new Image();
image17.src = gImages[17];
var image18 = new Image();
image18.src = gImages[18];
var image19 = new Image();
image19.src = gImages[19];
var image20 = new Image();
image20.src = gImages[20];
//--------------------------------------------------

//for the purposes of the external interface API with flash, since microsoft and mozilla have different references to the swf file
function thisMovie(movieName)
{
    if (navigator.appName.indexOf("Microsoft") != -1) 
    {
        return window[movieName];
    }
    else 
    {
        return document[movieName];
    }
}

function loadTitleById(pTitleId)
{
    thisMovie(player).loadTitleById(pTitleId);
    setCurrentTitle(pTitleId);
    jumpToTop();
}

function getLineupIds_Result(pLineupIds)
{
    gLineupIds = pLineupIds;
    init();
}

function bcInit()
{
    constructNav();
    (gLineupId) ? startRequest(gLineupId) : startRequest(gLineupIds[0]);
}

/*------------------------------------------------------------------------------------
 
 Preloader
 A very simple image preloader object
 Author: Warpspire (http://warpspire.com/tipsresources/interface-scripting/image-preloading-revisited/)
 
 Usage:
 
 Preloader.add(path);
 Preloader.onFinish(func);
 Preloader.load();
 
 path: 		A string or array of strings of image paths to preload
 func:     A function or array of functions to be called after images are loaded
 load():   Start the preloader
 
 ------------------------------------------------------------------------------------*/
var Preloader = 
{
    callbacks: [],
    images: [],
    loadedImages: [],
    imagesLoaded: 0,
    
    add: function(image)
    {
        if (typeof image == 'string') this.images.push(image);
        if (typeof image == 'array' || typeof image == 'object') 
        {
            for (var i = 0; i < image.length; i++) 
            {
                this.images.push(image[i]);
            }
        }
    },
    onFinish: function(func)
    {
        if (typeof func == 'function') this.callbacks.push(func);
        if (typeof func == 'array' || typeof func == 'object') 
        {
            for (var i = 0; i < func.length; i++) 
            {
                this.callbacks.push(func[i]);
            }
        }
    },
    load: function()
    {
        for (var i = 0; i < this.images.length; i++) 
        {
            this.loadedImages[i] = new Image();
            this.loadedImages[i].onload = function()
            {
                Preloader.checkFinished.apply(Preloader)
            }
            this.loadedImages[i].src = this.images[i];
        }
    },
    
    checkFinished: function()
    {
        this.imagesLoaded++;
        if (this.imagesLoaded == this.images.length) this.fireFinish();
    },
    fireFinish: function()
    {
        for (var i = 0; i < this.callbacks.length; i++) 
        {
            this.callbacks[i]();
        }
        this.images = [];
        this.loadedImages = [];
        this.imagesLoaded = 0;
        this.callbacks = [];
    }
}

//Preloader.add(gImages);
//Preloader.load();

function constructNav()
{
    var navElements = ["Featured", "Fashion", "Music", "Culture", "Karmaloop", "Partners", "Top 10", "Viewer Created"];
    var topNavIds = ["featured01", "fashion01", "music01", "culture01", "karmaloop01", "partners01", "top10-01", "cgm-01"];
    var navIds = ["featured02", "fashion02", "music02", "culture02", "karmaloop02", "partners02", "top10-02", "cgm-02"];
    var navList = "\n";
    
    /*
     * Might need to add a fok in the code below to check if it's the karmaloop tab, and
     * if so then link somewhere else. If it's going to be in a lineup though, I need to
     * make sure to add that as a tab to the bottom as well
     */
    for (var i = 0; i < navElements.length; i++) 
    {
        navList += '<li id="' + topNavIds[i] + '"><a href="javascript:changeLineup(' + gLineupIds[i] + '); changeTabs(\'' + navIds[i] + '\', \'' + topNavIds[i] + '\');" onmouseover="javascript:navRollover(\'' + topNavIds[i] + '\')" onmouseout="javascript:navRollOut(\'' + topNavIds[i] + '\')">' + navElements[i] + '</a></li>\n';
    }
    
    navList += '<li id="shop"><a href="http://karmaloop.com" title="Karmaloop.com" target="_blank">Shop Karmaloop</a></li>\n';
    var primaryNav = document.getElementById("primaryNav");
    primaryNav.innerHTML = navList;
    
    
    
    navElements = ["Featured", "Fashion", "Music", "Culture", "Partners", "Top 10", "Viewer Created"];
    var navList = "\n";
    
    for (var i = 0; i < navElements.length; i++) 
    {
        navList += '<li id="' + navIds[i] + '"><a href="javascript:changeLineup(' + gLineupIds[i] + '); changeTabs(\'' + navIds[i] + '\', \'' + topNavIds[i] + '\');" onmouseover="javascript:tabRollover(\'' + navIds[i] + '\')" onmouseout="javascript:tabRollOut(\'' + navIds[i] + '\')">' + navElements[i] + '</a></li>\n';
    }
    
    var secondaryNav = document.getElementById("secondaryNav");
    secondaryNav.innerHTML = navList;
}

function sortLineup(pLineup, pKey, pTrim)
{
    /*
     * utility function used in the sortBy() method that first strips any titles that don't match the key
     * to be sorted on (as long as pTrim is set to true) and sorts them using Prototype's sortBy() method
     */
    var lineup = pLineup;
    
	//this if block is special for the partner sorting
    if ((pKey == "partner=complex") || (pKey == "partner=clintonsparks") || (pKey == "partner=ughh") || (pKey == "partner=heppler")) 
    {
        var keyValue = pKey.split("=");
        var key = keyValue[0];
        var val = keyValue[1];
        
        for (var i = 0; i < gCurrentLineup.length; i++) 
        {
            if (gCurrentLineup[i][key].toLowerCase() !== val) 
            {
                for (var k = 0; k < lineup.length; k++) //this seems like such a complex way to do such a simple thing...
                 {
                    if (gCurrentLineup[i].titleId == lineup[k].titleId) 
                    {
                        lineup.splice(k, 1); //remove the element with no sortKey from the array
                    }
                }
            }
        }
    }
    
    if (pTrim) //only remove elements from the array if pTrim is true
    {
        for (var i = 0; i < gCurrentLineup.length; i++) 
        {
			var breakpoint = gCurrentLineup[i][pKey];
            if (!gCurrentLineup[i][pKey]) 
            {
                for (var k = 0; k < lineup.length; k++) //this seems like such a complex way to do such a simple thing...
                 {
                    if (gCurrentLineup[i].titleId == lineup[k].titleId) 
                    {
                        lineup.splice(k, 1); //remove the element with no sortKey from the array
                    }
                }
            }
        }
    }
    
    var sortedLineup = lineup.sortBy(function(tag)
    {
        return tag[pKey];
    });
    
    return sortedLineup;
}

function sortBy(pType)
{
    var lineup = [];
    
    for (var j = 0; j < gCurrentLineup.length; j++) 
    {
        lineup.push(gCurrentLineup[j]);
    }
    
    var sortedLineup = lineup; //in case it's not one of these, at least make it display the same lineup
    /*
     //------------------------ SET SORT STATES TO NORMAL
     $("primarySortDate").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_date_01.gif)";
     $("secondarySortDate").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_date_01.gif)";
     $("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
     $("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
     if (gSortMethod == "BRAND")
     {
     $("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_brand_01.gif)";
     $("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_brand_01.gif)";
     }
     if(gSortMethod == "ARTIST")
     {
     $("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_artist_01.gif)";
     $("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_artist_01.gif)";
     }
     if(pType.indexOf("PARTNER") !== -1) //if we're in the partners section...
     {
     $("partner_Complex01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-complex_01.gif)";
     $("partner_Complex02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-complex_01.gif)";
     $("partner_ClintonSparks01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-clintonsparks_01.gif)";
     $("partner_ClintonSparks02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-clintonsparks_01.gif)";
     $("partner_UGHH01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-ughh_01.gif)";
     $("partner_UGHH02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-ughh_01.gif)";
     }
     //------------------------
     */
    //$("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_02.gif)";
    //$("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_02.gif)";
    if (pType == "PARTNER_COMPLEX") 
    {
        gCurrentPartner = pType;
        //$("partner_Complex01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-complex_02.gif)";
        //$("partner_Complex02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-complex_02.gif)";
        sortedLineup = sortLineup(lineup, "partner=complex", false); //trim is false since there's a custom trim for partners
    }
    if (pType == "PARTNER_CLINTONSPARKS") 
    {
        gCurrentPartner = pType;
        //$("partner_ClintonSparks01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-clintonsparks_02.gif)";
        //$("partner_ClintonSparks02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-clintonsparks_02.gif)";
        sortedLineup = sortLineup(lineup, "partner=clintonsparks", false); //trim is false since there's a custom trim for partners
    }
    if (pType == "PARTNER_UGHH") 
    {
        gCurrentPartner = pType;
        //$("partner_UGHH01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-ughh_02.gif)";
        //$("partner_UGHH02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-ughh_02.gif)";
        sortedLineup = sortLineup(lineup, "partner=ughh", false); //trim is false since there's a custom trim for partners
    }
    if (pType == "PARTNER_ROBHEPPLER") 
    {
        gCurrentPartner = pType;
        sortedLineup = sortLineup(lineup, "partner=heppler", false); //trim is false since there's a custom trim for partners
    }
    if (pType == "DATE") 
    {
        //$("primarySortDate").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_date_02.gif)";
        //$("secondarySortDate").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_date_02.gif)";
        sortedLineup = lineup;
    }
    else 
    {
        if (gSortMethod == "BRAND") 
        {
            //$("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_brand_02.gif)";
            //$("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_brand_02.gif)";
            sortedLineup = sortLineup(lineup, "brand", true);
        }
        if (gSortMethod == "ARTIST") sortedLineup = sortLineup(lineup, "artist", true);
        if (gSortMethod == "FEATURED_TITLE") sortedLineup = sortLineup(lineup, "featuredtitle", true);
        if (gSortMethod == "CULTURE_TITLE") sortedLineup = sortLineup(lineup, "culturetitle", false);
        if (gSortMethod == "KARMALOOP_TITLE") sortedLineup = sortLineup(lineup, "karmalooptitle", false);
    }
    
    setCurrentLineup(sortedLineup);
}

function changeLineup(pLineupId)
{
    startRequest(pLineupId);
}

function changeTabs(pBottomElement, pTopElement)
{
    gCurrentPartner = null;
    gCurrentElement = pBottomElement;
    var sortDate02 = document.getElementById("secondarySortDate").getElementsByTagName("a")[0];
    var sortBrand02 = document.getElementById("secondarySortBrand").getElementsByTagName("a")[0];
    var partnerComplex02 = document.getElementById("partner_Complex02").getElementsByTagName("a")[0];
    var partnerClintonSparks02 = document.getElementById("partner_ClintonSparks02").getElementsByTagName("a")[0];
    var partnerUGHH02 = document.getElementById("partner_UGHH02").getElementsByTagName("a")[0];
    
    sortDate02.style.display = "inline";
    sortBrand02.style.display = "inline";
    $("primarySortDate").getElementsByTagName("a")[0].style.display = "inline";
    $("primarySortBrand").getElementsByTagName("a")[0].style.display = "inline";
    partnerComplex02.style.display = "none";
    partnerClintonSparks02.style.display = "none";
    partnerUGHH02.style.display = "none";
    $("partner_Complex01").getElementsByTagName("a")[0].style.display = "none";
    $("partner_ClintonSparks01").getElementsByTagName("a")[0].style.display = "none";
    $("partner_UGHH01").getElementsByTagName("a")[0].style.display = "none";
    $("partner_RobHeppler01").getElementsByTagName("a")[0].style.display = "none";
    $("partner_RobHeppler02").getElementsByTagName("a")[0].style.display = "none";
    
    var navItem = document.getElementById(pBottomElement);
    var navItemLink = navItem.getElementsByTagName("a");
    var navIds = ["featured02", "fashion02", "music02", "culture02", "karmaloop02", "partners02", "top10-02", "cgm-02"];
    
    var topNavItem = document.getElementById(pTopElement);
    var topNavItemLink = topNavItem.getElementsByTagName("a");
    var topNavIds = ["featured01", "fashion01", "music01", "culture01", "karmaloop01", "partners01", "top10-01", "cgm-01"];
    
    $("secondarySort").style.visibility = "visible";
    $("primarySort").style.visibility = "visible";
    
    if (pBottomElement == "featured02" || pTopElement == "featured01") 
    {
        gSortMethod = "FEATURED_TITLE";
        topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-featured_02.gif)';
        navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-featured_02.gif)';
        document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
        document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
    }
    if (pBottomElement == "fashion02" || pTopElement == "fashion01") 
    {
        gSortMethod = "BRAND";
        topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-fashion_02.gif)';
        navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-fashion_02.gif)';
        document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_brand_01.gif)";
        document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_brand_01.gif)";
    }
    if (pBottomElement == "music02" || pTopElement == "music01") 
    {
        gSortMethod = "ARTIST";
        topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-music_02.gif)';
        navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-music_02.gif)';
        document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_artist_01.gif)";
        document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_artist_01.gif)";
    }
    if (pBottomElement == "culture02" || pTopElement == "culture01") 
    {
        gSortMethod = "CULTURE_TITLE";
        topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-culture_02.gif)';
        navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-culture_02.gif)';
        document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
        document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
    }
    if (pBottomElement == "karmaloop02" || pTopElement == "karmaloop01") 
    {
        gSortMethod = "KARMALOOP_TITLE";
        topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-karmaloop_02.gif)';
        navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-karmaloop_02.gif)';
        document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
        document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
    }
    if (pBottomElement == "partners02" || pTopElement == "partners01") 
    {
        gSortMethod = "PARTNER";
        topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-partners_02.gif)';
        navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-partners_02.gif)';
        sortDate02.style.display = "none";
        sortBrand02.style.display = "none";
        //----- TOP NAV
        $("primarySortDate").getElementsByTagName("a")[0].style.display = "none";
        $("primarySortBrand").getElementsByTagName("a")[0].style.display = "none";
        $("partner_Complex01").getElementsByTagName("a")[0].style.display = "inline";
        $("partner_Complex01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-complex_01.gif)";
        $("partner_ClintonSparks01").getElementsByTagName("a")[0].style.display = "inline";
        $("partner_ClintonSparks01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-clintonsparks_01.gif)";
        $("partner_UGHH01").getElementsByTagName("a")[0].style.display = "inline";
        $("partner_UGHH01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-ughh_01.gif)";
        $("partner_RobHeppler01").getElementsByTagName("a")[0].style.display = "inline";
        $("partner_RobHeppler01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-robheppler_01.gif)";
        //-----
        partnerComplex02.style.display = "inline";
        partnerComplex02.style.backgroundImage = "url(images/secondary_sort_partner-complex_01.gif)";
        partnerClintonSparks02.style.display = "inline";
        partnerClintonSparks02.style.backgroundImage = "url(images/secondary_sort_partner-clintonsparks_01.gif)";
        partnerUGHH02.style.display = "inline";
        partnerUGHH02.style.backgroundImage = "url(images/secondary_sort_partner-ughh_01.gif)";
        $("partner_RobHeppler02").getElementsByTagName("a")[0].style.display = "inline";
        $("partner_RobHeppler02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-robheppler_01.gif)";
        //document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner_01.gif)";
        //document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner_01.gif)";
    }
    if (pBottomElement == "top10-02" || pTopElement == "top10-01") 
    {
        topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-top10_02.gif)';
        navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-top10_02.gif)';
        document.getElementById("secondarySort").style.visibility = "hidden";
        $("primarySort").style.visibility = "hidden";
    }
    if (pBottomElement == "cgm-02" || pTopElement == "cgm-01") 
    {
        topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-cgm_02.gif)';
        navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-cgm_02.gif)';
        document.getElementById("secondarySort").style.visibility = "hidden";
    }
    
    //---------------------------------------------------------------- TOP NAV
    for (var i = 0; i < topNavIds.length; i++) 
    {
        if (topNavIds[i] == pTopElement) topNavIds.splice(i, 1);
    }
    
    for (var j = 0; j < topNavIds.length; j++) //switch all others to the unselected state
     {
        topNavItem = document.getElementById(topNavIds[j]);
        topNavItemLink = topNavItem.getElementsByTagName("a");
        
        if (topNavIds[j] == "featured01") topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-featured_01.gif)';
        if (topNavIds[j] == "fashion01") topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-fashion_01.gif)';
        if (topNavIds[j] == "music01") topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-music_01.gif)';
        if (topNavIds[j] == "culture01") topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-culture_01.gif)';
        if (topNavIds[j] == "karmaloop01") topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-karmaloop_01.gif)';
        if (topNavIds[j] == "partners01") topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-partners_01.gif)';
        if (topNavIds[j] == "top10-01") topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-top10_01.gif)';
        if (topNavIds[j] == "cgm-01") topNavItemLink[0].style.backgroundImage = 'url(images/main_nav-cgm_01.gif)';
    }
    //----------------------------------------------------------------
    
    //---------------------------------------------------------------- BOTTOM NAV
    for (var i = 0; i < navIds.length; i++) 
    {
        if (navIds[i] == pBottomElement) navIds.splice(i, 1);
    }
    
	//.length - 1 because we're not using the CGM tab right now so it has no properties
    for (var j = 0; j < (navIds.length - 1); j++) //switch all others to the unselected state
    {
        //navItem = document.getElementById(navIds[j]);
        navItemLink = $(navIds[j]).getElementsByTagName("a");
        
        if (navIds[j] == "featured02") navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-featured_01.gif)';
        if (navIds[j] == "fashion02") navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-fashion_01.gif)';
        if (navIds[j] == "music02") navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-music_01.gif)';
        if (navIds[j] == "culture02") navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-culture_01.gif)';
        if (navIds[j] == "karmaloop02") navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-karmaloop_01.gif)';
        if (navIds[j] == "partners02") navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-partners_01.gif)';
        if (navIds[j] == "top10-02") navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-top10_01.gif)';
        if (navIds[j] == "cgm-02") navItemLink[0].style.backgroundImage = 'url(images/secondary_nav-cgm_01.gif)';
    }
    //----------------------------------------------------------------
}

function navRollover(pElement)
{
    if (pElement == "featured01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-featured_02.gif)";
    if (pElement == "fashion01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-fashion_02.gif)";
    if (pElement == "music01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-music_02.gif)";
    if (pElement == "culture01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-culture_02.gif)";
    if (pElement == "karmaloop01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-karmaloop_02.gif)";
    if (pElement == "partners01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-partners_02.gif)";
    if (pElement == "top10-01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-top10_02.gif)";
}

function navRollOut(pElement)
{
    if (pElement == "featured01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-featured_01.gif)";
    if (pElement == "fashion01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-fashion_01.gif)";
    if (pElement == "music01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-music_01.gif)";
    if (pElement == "culture01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-culture_01.gif)";
    if (pElement == "karmaloop01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-karmaloop_01.gif)";
    if (pElement == "partners01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-partners_01.gif)";
    if (pElement == "top10-01") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/main_nav-top10_01.gif)";
    if (pElement == gCurrentElement.replace("02", "01")) navRollover(pElement); //makes sure that if we roll off a selected item, it stays selected
}

function tabRollover(pElement)
{
    if (pElement == "featured02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-featured_02.gif)";
    if (pElement == "fashion02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-fashion_02.gif)";
    if (pElement == "music02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-music_02.gif)";
    if (pElement == "culture02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-culture_02.gif)";
    if (pElement == "karmaloop02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-karmaloop_02.gif)";
    if (pElement == "partners02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-partners_02.gif)";
    if (pElement == "top10-02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-top10_02.gif)";
}

function tabRollOut(pElement)
{
    if (pElement == "featured02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-featured_01.gif)";
    if (pElement == "fashion02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-fashion_01.gif)";
    if (pElement == "music02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-music_01.gif)";
    if (pElement == "culture02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-culture_01.gif)";
    if (pElement == "karmaloop02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-karmaloop_01.gif)";
    if (pElement == "partners02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-partners_01.gif)";
    if (pElement == "top10-02") $(pElement).getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_nav-top10_01.gif)";
    if (pElement == gCurrentElement) tabRollover(pElement); //makes sure that if we roll off a selected item, it stays selected
}

function primarySortMouseOver()
{
    if (gCurrentElement == "featured02") document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_02.gif)";
    if (gCurrentElement == "fashion02") document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_brand_02.gif)";
    if (gCurrentElement == "music02") document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_artist_02.gif)";
    if (gCurrentElement == "culture02") document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_02.gif)";
    if (gCurrentElement == "karmaloop02") document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_02.gif)";
    if (gCurrentElement == "partners02") document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner_02.gif)";
}

function primarySortMouseOut()
{
    if (gCurrentElement == "featured02") document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
    if (gCurrentElement == "fashion02") document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_brand_01.gif)";
    if (gCurrentElement == "music02") document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_artist_01.gif)";
    if (gCurrentElement == "culture02") document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
    if (gCurrentElement == "karmaloop02") document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
    if (gCurrentElement == "partners02") document.getElementById("primarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner_01.gif)";
}

function secondarySortMouseOver()
{
    if (gCurrentElement == "featured02") document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_02.gif)";
    if (gCurrentElement == "fashion02") document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_brand_02.gif)";
    if (gCurrentElement == "music02") document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_artist_02.gif)";
    if (gCurrentElement == "culture02") document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_02.gif)";
    if (gCurrentElement == "karmaloop02") document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_02.gif)";
    if (gCurrentElement == "partners02") document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner_02.gif)";
}

function secondarySortMouseOut()
{
    if (gCurrentElement == "featured02") document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
    if (gCurrentElement == "fashion02") document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_brand_01.gif)";
    if (gCurrentElement == "music02") document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_artist_01.gif)";
    if (gCurrentElement == "culture02") document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
    if (gCurrentElement == "karmaloop02") document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_title_01.gif)";
    if (gCurrentElement == "partners02") document.getElementById("secondarySortBrand").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner_01.gif)";
}

function partnerSortMouseOver(pPartner)
{
    if (pPartner == "COMPLEX01") $("partner_Complex01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-complex_02.gif)";
    if (pPartner == "CLINTONSPARKS01") $("partner_ClintonSparks01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-clintonsparks_02.gif)";
    if (pPartner == "UGHH01") $("partner_UGHH01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-ughh_02.gif)";
    if (pPartner == "ROBHEPPLER01") $("partner_RobHeppler01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-robheppler_02.gif)";
    
    if (pPartner == "COMPLEX02") $("partner_Complex02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-complex_02.gif)";
    if (pPartner == "CLINTONSPARKS02") $("partner_ClintonSparks02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-clintonsparks_02.gif)";
    if (pPartner == "UGHH02") $("partner_UGHH02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-ughh_02.gif)";
    if (pPartner == "ROBHEPPLER02") $("partner_RobHeppler02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-robheppler_02.gif)";
}

function partnerSortMouseOut(pPartner)
{
    if (pPartner == "COMPLEX01") $("partner_Complex01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-complex_01.gif)";
    if (pPartner == "CLINTONSPARKS01") $("partner_ClintonSparks01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-clintonsparks_01.gif)";
    if (pPartner == "UGHH01") $("partner_UGHH01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-ughh_01.gif)";
    if (pPartner == "ROBHEPPLER01") $("partner_RobHeppler01").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-robheppler_01.gif)";
    
    if (pPartner == "COMPLEX02") $("partner_Complex02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-complex_01.gif)";
    if (pPartner == "CLINTONSPARKS02") $("partner_ClintonSparks02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-clintonsparks_01.gif)";
    if (pPartner == "UGHH02") $("partner_UGHH02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-ughh_01.gif)";
    if (pPartner == "ROBHEPPLER02") $("partner_RobHeppler02").getElementsByTagName("a")[0].style.backgroundImage = "url(images/secondary_sort_partner-robheppler_01.gif)";
    //partnerSortMouseOver(gCurrentPartner.substr(8));
}

function setCurrentLineup(pLineupDTO)
{
    //---------------------------------------------------------------- CURRENT LINEUP
    var lineupName = gLineupName.substr(14);
    $("currentLineupName").innerHTML = lineupName; //for semantics
    if (lineupName == "Featured") $("currentLineupName").style.backgroundImage = "url(images/current_lineup_header_featured_01.gif)";
    if (lineupName == "Fashion") $("currentLineupName").style.backgroundImage = "url(images/current_lineup_header_fashion_01.gif)";
    if (lineupName == "Music") $("currentLineupName").style.backgroundImage = "url(images/current_lineup_header_music_01.gif)";
    if (lineupName == "Culture") $("currentLineupName").style.backgroundImage = "url(images/current_lineup_header_culture_01.gif)";
    if (lineupName == "Karmaloop") $("currentLineupName").style.backgroundImage = "url(images/current_lineup_header_karmaloop_01.gif)";
    if (lineupName == "Partners") $("currentLineupName").style.backgroundImage = "url(images/current_lineup_header_partners_01.gif)";
    if (lineupName == "Top 10") $("currentLineupName").style.backgroundImage = "url(images/current_lineup_header_top10_01.gif)";
    if (gCurrentPartner == "PARTNER_COMPLEX") $("currentLineupName").style.backgroundImage = "url(images/current_lineup_header_partners_complex_01.gif)";
	if (gCurrentPartner == "PARTNER_CLINTONSPARKS") $("currentLineupName").style.backgroundImage = "url(images/current_lineup_header_partners_clintonsparks_01.gif)";
	if (gCurrentPartner == "PARTNER_UGHH") $("currentLineupName").style.backgroundImage = "url(images/current_lineup_header_partners_ughh_01.gif)";
	if (gCurrentPartner == "PARTNER_ROBHEPPLER") $("currentLineupName").style.backgroundImage = "url(images/current_lineup_header_partners_robheppler_01.gif)";
	
    var currentLineup = "";
    
    for (var l = 0; l < pLineupDTO.length; l++) 
    {
        var titleId = pLineupDTO[l].titleId;
        var displayName = pLineupDTO[l].displayName;
		var url = pLineupDTO[l].thumbnailURL.split("/");
        var thumbnailURL = url[url.length - 1].split("?")[0];
        
        currentLineup += "<li id='list_" + titleId + "' onmouseover='javascript:showOverlay(\"list_" + titleId + "\");' onmouseout='javascript:hideOverlay(\"list_" + titleId + "\");' onclick='javascript:loadTitleById(" + titleId + ");'>\n";
        currentLineup += "\t<img src='./images/thumbnails/" + thumbnailURL + "' onClick='javascript:loadTitleById(" + titleId + ");' />\n";
        currentLineup += "\t<a href='javascript:loadTitleById(" + titleId + ");' title='" + displayName + "'>\n";
        currentLineup += "\t" + displayName + "</a>\n";
        currentLineup += (!isIE6) ? "\t<div class='thumbOverlay01'></div>\n" : "\t<div class='thumbOverlay01_IE6'></div>\n";
        currentLineup += "</li>\n\n";
    }
	currentLineup += '<h3 id="viewMore" onclick="javascript:jumpToBottom();">View More Videos</h3>';
    currentLineup += "\n";
    $("currentLineup").innerHTML = currentLineup;
    //----------------------------------------------------------------
    
    
    //---------------------------------------------------------------- THUMBNAIL DISPLAY
    var thumbnailDisplay = document.getElementById("thumbnailDisplay");
    currentLineup = "<ul>\n";
    
    for (var l = 0; l < pLineupDTO.length; l++) //MODIFIED
     {
        var titleId = pLineupDTO[l].titleId;
        var thumbnailURL = pLineupDTO[l].thumbnailURL;
        var displayName = (pLineupDTO[l].displayName.length >= 26) ? pLineupDTO[l].displayName.substring(0, 26) + "..." : pLineupDTO[l].displayName;
        
        currentLineup += "<li id='thumb_" + titleId + "' onmouseover='javascript:showOverlay(\"thumb_" + titleId + "\");' onmouseout='javascript:hideOverlay(\"thumb_" + titleId + "\");' onclick='javascript:loadTitleById(" + titleId + ");'>\n";
        currentLineup += "\t<a href='javascript:loadTitleById(" + titleId + ")' title='" + displayName + "'>\n";
        currentLineup += "\t<img width='157' height='87' src='" + thumbnailURL + "' />\n";
        currentLineup += "\t</a>\n";
        currentLineup += "\t<span>" + displayName + "</span>\n";
        currentLineup += (!isIE6) ? "\t<div class='thumbOverlay02'></div>\n" : "\t<div class='thumbOverlay02_IE6'></div>\n";
        currentLineup += "</li>\n";
    }
    
    currentLineup += "</ul>\n\n";
    thumbnailDisplay.innerHTML = currentLineup;
    //----------------------------------------------------------------
    
    
    //---------------------------------------------------------------- LIST DISPLAY
    var listDisplay = document.getElementById("listDisplay");
    currentLineup = "<ul>\n";
    
    for (var l = 0; l < pLineupDTO.length; l++) //MODIFIED
     {
        var titleId = pLineupDTO[l].titleId;
        //var displayName = pLineupDTO[l].displayName;
        var displayName = (pLineupDTO[l].displayName.length >= 26) ? pLineupDTO[l].displayName.substring(0, 26) + "..." : pLineupDTO[l].displayName;
        var thumbnailURL = pLineupDTO[l].thumbnailURL;
        
        currentLineup += "<li>\n";
        currentLineup += "\t<a href='javascript:loadTitleById(" + titleId + ")' title='" + displayName + "'>\n";
        currentLineup += "\t" + displayName + "\n";
        currentLineup += "\t</a>\n";
        currentLineup += "</li>\n";
    }
    currentLineup += "</ul>\n\n";
    listDisplay.innerHTML = currentLineup;
    //----------------------------------------------------------------
}

function setCurrentTitle(pTitleId)
{
    for (var i = 0; i < gCurrentLineup.length; i++) 
    {
        if (gCurrentLineup[i].titleId == pTitleId) 
        {
            var displayName = gCurrentLineup[i].displayName;
            var description = gCurrentLineup[i].description;
            //gTitleFound = true;
            updateCurrentTitleInfo(displayName, description);
        }
    }
    
    //if(!gTitleFound) thisMovie(player).fetchTitleDTO(gTitleId);
}

function updateCurrentTitleInfo(pDisplayName, pDescription)
{
    var currentTitleInfo = document.getElementById("currentTitleInfo");
    var htmlString = "";
    htmlString += "<div class='container'>\n";
    htmlString += "\t<h2>" + pDisplayName + "</h2>\n";
    htmlString += "\t<p>" + pDescription + "</p>\n";
    htmlString += "</div>\n";
    
    currentTitleInfo.innerHTML = htmlString;
}

function showOverlay(pElement)
{
    $(pElement).getElementsByTagName("div")[0].style.display = "inline";
    $(pElement).getElementsByTagName("a")[0].style.color = "#444444";
}

function hideOverlay(pElement)
{
    $(pElement).getElementsByTagName("div")[0].style.display = "none";
}

function browserDetect()
{
    var appName = navigator.appName;
    var appVersion = navigator.appVersion;
}

function getNumberOfItems(pObject)
{
    var count = 0;
    for (var prop in pObject) 
    {
        count++;
    }
    
    return count;
}

function jumpToTop()
{
    window.scrollTo(0, 0);
}

function jumpToBottom()
{
	window.scrollTo(0, 630);
}



//----------------------------------------------------------------------------------------- START AJAX FUNCTIONS/CALLS
var xmlHttp;

function createXMLHttpRequest()
{
    if (window.ActiveXObject) //for IE
    {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else 
        if (window.XMLHttpRequest) // Mozilla, Safari, ...
        {
            xmlHttp = new XMLHttpRequest();
            xmlHttp.overrideMimeType('text/xml'); // in case the mime type isn't specified
        }
}

function startRequest(pLineupId)
{
    gCurrentLineupId = pLineupId;
    var url = "http://link.brightcove.com/services/link/bclid" + pLineupId + "/bcpid1287040724?action=mrss";
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.open("POST", "../php/get_xml_01.php", true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //this makes PHP return the right format
    xmlHttp.send("url=" + escape(url)); //sends the url of the MRSS feed to the php script 
}

function handleStateChange()
{
    if (xmlHttp.readyState == 4) //load is complete
    {
        if (xmlHttp.status == 200 || xmlHttp.status == 304) //the request has succeeded or there was no change
        {
            parseMRSS(xmlHttp.responseXML); //once the server returns the XML, pass all the XML to the parseXML() function
        }
        else 
        {
            alert("the xml failed to load");
        }
    }
}

//-----------------------------------------------------------------------------------------





//----------------------------------------------------------------------------------------- PARSE THE XML
function parseMRSS(pXML)
{
    var lineup = [];
	var imageURLs = [];
    
    if (!document.getElementsByTagName) return false;
    if (!document.getElementById) return false;
    
    //var channel = pXML.getElementsByTagName("channel")[0].getElementsByTagName("title")[0].firstChild.nodeValue;
    //var title = channel[0].getElementsByTagName("title");
    gLineupName = pXML.getElementsByTagName("channel")[0].getElementsByTagName("title")[0].firstChild.nodeValue;
    
    var itemsArray = pXML.getElementsByTagName("item"); //gets all of the item elements and puts them in an array
    for (var i = 0; i < itemsArray.length; i++) 
    {
        var lDisplayName = null;
        var lDescription = null;
        var lThumbnailURL = null;
        var lVideoStill = null;
        var lTitleId = null;
        var lBrand = null;
        var lArtist = null;
        var lPartner = null;
        var lTimestamp = null;
        var lFeaturedSortTitle = null;
        var lCultureSortTitle = null;
        var lKarmaloopSortTitle = null;
        
        
        var itemChildren = itemsArray[i].getElementsByTagName("*"); //this gets all of the elements for an item node
        var thumbnailExists = null;
        
        for (j = 0; j < itemChildren.length; j++) 
        {
            if (itemChildren[j].nodeName == "title") lDisplayName = itemChildren[j].firstChild.nodeValue;
            if (itemChildren[j].nodeName == "description") lDescription = itemChildren[j].firstChild.nodeValue;
            if (itemChildren[j].nodeName == "bc:titleid") lTitleId = itemChildren[j].firstChild.nodeValue;
            
            //--------------------------------- TAG PARSING
            if (itemChildren[j].nodeName == "media:keywords" && itemChildren[j].firstChild) 
            {
                var tagsArray = itemChildren[j].firstChild.nodeValue.split(",");
                
                for (var q = 0; q < tagsArray.length; q++) 
                {
                    var index = tagsArray[q].indexOf("=");
                    if (index > 0) 
                    {
                        var keyValues = tagsArray[q].split("=");
                        var key = keyValues[0].toLowerCase();
                        var val = keyValues[1].toLowerCase();
                        if (key == "brand") lBrand = val;
                        if (key == "artist") lArtist = val;
                        if (key == "partners") lPartner = val;
                        if (key == "timestamp") lTimestamp = val;
                        if (key == "featuredtitle") lFeaturedSortTitle = val;
                        if (key == "culturetitle") lCultureSortTitle = val;
                        if (key == "karmalooptitle") lKarmaloopSortTitle = val;
                    }
                }
            }
            //--------------------------------- 
			//1185080984_1309619785_957ff682190197aac2beb2dcc044e7d9b11df9f3.jpg
			//1185080984_1309619785_957ff682190197aac2beb2dcc044e7d9b11df9f3.jpg
            
            if (itemChildren[j].nodeName == "media:thumbnail" && (itemChildren[j].getAttribute("height") == 90)) 
            {
				imageURLs.push(itemChildren[j].getAttribute("url"));
                lThumbnailURL = itemChildren[j].getAttribute("url");
                thumbnailExists = true;
            }
            if (itemChildren[j].nodeName == "media:thumbnail" && (itemChildren[j].getAttribute("height") == 360)) lVideoStill = itemChildren[j].getAttribute("url");
            
            if (j == (itemChildren.length - 1) && !thumbnailExists) lThumbnailURL = ""; //if no thumbnail is available, assign it to nothing
        }
        lineup.push(
        {
            displayName: lDisplayName,
            description: lDescription,
            thumbnailURL: lThumbnailURL,
            videoStill: lVideoStill,
            titleId: lTitleId,
            brand: lBrand,
            artist: lArtist,
            partner: lPartner,
            timestamp: lTimestamp,
            featuredtitle: lFeaturedSortTitle,
            culturetitle: lCultureSortTitle,
            karmalooptitle: lKarmaloopSortTitle
        });
    }
    
    gCurrentLineup = lineup;
    setCurrentLineup(gCurrentLineup);
    
    if (!gInitialized) 
    {
        (gTitleId) ? setCurrentTitle(gTitleId) : setCurrentTitle(gCurrentLineup[0].titleId);
        gInitialized = true;
    }
	
	//alert(imageURLs.inspect());
	
	new Ajax.Request("../php/thumbnails.php", {
		method: "post",
		postBody: "imageURLs=" + imageURLs,
		onSuccess: function(){}
	});
	
}

//-----------------------------------------------------------------------------------------