var top = '<div class="dynamicbucket epromo" style="text-align: center;"><div class="buckettop">&nbsp;</div><h3><a href="/templates/people/">NPR Voices</a></h3><div class="bucketcontent"><div style="text-align: center;">';
var bottom = '</div><div class="more"><a href="/templates/people/">More Voices &raquo;</a></div></div><div class="bucketbottom">&nbsp;</div></div>';
var middle = '';
var k = 0;
var tempArray = new Array();
var tempArray2 = new Array();

// "fixes" the redirect issue
var hosts = new Array();
// ATC
hosts["mblock"] = "2100245";
hosts["mnorris"] = "2100974";
hosts["rsiegel"] = "2101185";
hosts["aseabrook"] = "2790202";
// ME
hosts["sinskeep"] = "4080709";
hosts["rmontagne"] = "2100929";
// Performance Today
// hosts["kcoleman"] = "2100373";
hosts["fchild"] = "2100334";
hosts["lsimeone"] = "2101205";
// TOTN
hosts["nconan"] = "2100380";
hosts["iflatow"] = "2100482";
// WATC
hosts["mblock"] = "2100245";
hosts["mnorris"] = "2100974";
hosts["rsiegel"] = "2101185";
// WESAT
hosts["ssimon"] = "3874941";
// WESUN
hosts["lhansen"] = "2100620";
// Farai Chideya
hosts["fchideya"] = "4529966";
// Fresh Air
hosts["tgross"] = "2100593";
// Tavis
//hosts["tsmiley"] = "";
hosts["tcox"] = "2100394";
// Motley Fool
hosts["dgardner"] = "2100501";
// Day to Day
hosts["mbrand"] = "2100281";
// World Cafe
hosts["ddye"] = "4717757";
// From the Top
hosts["coriley"] = "5074636";
// Tell Me More
hosts["mmartin"] = "5201175";
// Bryant Park
hosts["astewart"] = "10364918";



function voicesBanner(people, num_rotating)
    {
        for(i = 0; i < people.length; i++)
            {
                if(people[i][1] == 0)
                    {
                        makeMiddle(people[i][0]);
                    }
                else 
                    {
                        tempArray[k] = people[i][0];
                        k++;                        
                    }
            }
        for(q = 0; q < num_rotating; q++)
            {
                tempArray2[q] = getDiscreteNum();
                
            }
        for(u = 0; u < tempArray2.length; u++)
            {
                makeMiddle(tempArray[tempArray2[u]]);   
            }

        document.write(top + middle + bottom);
        
    }
    
function makeMiddle(person)
    {
        if(person == "motley")
            {
                middle += '<a href="http://www.npr.org/programs/fool/about.html"><img src="http://media.npr.org/include/nprvoices/banners/nprvoices_' + person + '.jpg" width="112" height="68" hspace="5" vspace="5" alt="' + person + '" border="0"></a>';
            }
        else if(person == "tsmiley")
            {
                middle += '<a href="http://www.npr.org/programs/tavis/about/"><img src="http://media.npr.org/include/nprvoices/banners/nprvoices_' + person + '.jpg" width="112" height="68" hspace="5" vspace="5" alt="' + person + '" border="0"></a>';
            }
        else
            {
                middle += '<a href="http://www.npr.org/templates/story/story.php?storyId=' + hosts[person] + '"><img src="http://media.npr.org/include/nprvoices/banners/nprvoices_' + person + '.jpg" width="112" height="68" hspace="5" vspace="5" alt="' + person + '" border="0" style="margin:0 7px;"></a>';
            }
    }
    
function getNum(num)
    {
        return Math.floor(Math.random() * num);
    }

function getDiscreteNum()
    {
        new_num = getNum(tempArray.length)
        
        for(z = 0; z < tempArray2.length; z++)
            {
                if(new_num == tempArray2[z])
                    {
                        getDiscreteNum(tempArray2, new_num);
                    }
            }   
        return new_num;
    }
    

// get program Id from URL
function getParams() {
    var idx = document.URL.indexOf('?');
    var params = new Array();
    if (idx != -1) {
        var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
        for (var i=0; i<pairs.length; i++) {
            nameVal = pairs[i].split('=');
            params[nameVal[0]] = nameVal[1];
        }
    }
    return params;
}
var params = getParams();
var prgId = Math.floor(params['prgId']);

//
// output voices bucket
var people = new Array();

switch (prgId) {
    
    case 2:     // All Things Considered

        people[0] = new Array();
        people[1] = new Array();
        people[2] = new Array();

        people[0][0] = "mblock";
        people[0][1] = 0;

        people[1][0] = "mnorris";
        people[1][1] = 0;

        people[2][0] = "rsiegel";
        people[2][1] = 0;

        voicesBanner(people, 0);
        break

    case 3:     // Morning Edition
        
        people[0] = new Array();
        people[1] = new Array();
        
        people[0][0] = "sinskeep";
        people[0][1] = 0;
        
        people[1][0] = "rmontagne";
        people[1][1] = 0;

        voicesBanner(people, 0);
        break
        
    case 4:     // Performance Today
    
        people[0] = new Array();
        people[1] = new Array();

        people[0][0] = "fchild";
        people[0][1] = 0;

        people[1][0] = "lsimeone";
        people[1][1] = 0;

        voicesBanner(people, 0);
        break;

    case 5:     // TOTN
    
        people[0] = new Array();
        people[1] = new Array();
        
        people[0][0] = "nconan";
        people[0][1] = 0;
        
        people[1][0] = "iflatow";
        people[1][1] = 0;

        voicesBanner(people, 0);
        break;
    
    case 6:     // WATC
    
        people[0] = new Array();
        people[1] = new Array();
        people[2] = new Array();
        people[3] = new Array();


        people[0][0] = "mblock";
        people[0][1] = 0;

        people[1][0] = "mnorris";
        people[1][1] = 0;

        people[2][0] = "rsiegel";
        people[2][1] = 0;
        
        voicesBanner(people, 0);
        break;
    
    case 7:     // WESAT
    
        people[0] = new Array();
        
        people[0][0] = "ssimon";
        people[0][1] = 0;
        
        voicesBanner(people, 0);
        break;
        
    case 10:        // WESUN
    
        people[0] = new Array();
        
        people[0][0] = "lhansen";
        people[0][1] = 0;
        
        voicesBanner(people, 0);
        break;
        
    case 11:        // Farai Chideya
    
        people[0] = new Array();
        
        people[0][0] = "fchideya";
        people[0][1] = 0;
        
        voicesBanner(people, 0);
        break;
        
    case 13:        // Fresh Air
    
        people[0] = new Array();
        
        people[0][0] = "tgross";
        people[0][1] = 0;
        
        voicesBanner(people, 0);
        break;
        
    case 14:        // Tavis
    
        people[0] = new Array();
        people[1] = new Array();
        
        people[0][0] = "tsmiley";
        people[0][1] = 0;
        people[1][0] = "tcox";
        people[1][1] = 0;
        
        voicesBanner(people, 0);
        break;
        
    case 15:        // Motley Fool
    
        people[0] = new Array();
        
        people[0][0] = "dgardner";
        people[0][1] = 0;
        
        voicesBanner(people, 0);
        break;
        
    case 17:        // Day to Day
    
        people[0] = new Array();

        people[0][0] = "mbrand";
        people[0][1] = 0;
        
        voicesBanner(people, 0);
        break;
        
    case 39:        // World Cafe
    
        people[0] = new Array();
        
        people[0][0] = "ddye";
        people[0][1] = 0;
        
        voicesBanner(people, 0);
        break;
		
    case 43:        // From the Top
    
        people[0] = new Array();
        
        people[0][0] = "coriley";
        people[0][1] = 0;
        
        voicesBanner(people, 0);
        break;
		
    case 46:        // Tell Me More
    
        people[0] = new Array();
        
        people[0][0] = "mmartin";
        people[0][1] = 0;
        
        voicesBanner(people, 0);
        break;
		
    case 47:     // Bryant Park Project
    
        people[0] = new Array();
        people[1] = new Array();

        people[0][0] = "astewart";
        people[0][1] = 0;
       
        
        voicesBanner(people, 0);
        break;				

}
    
    
    
    

