/**
* IWD, 22 Feb 2006
* Allows for a randomly rotating image and caption to appear
* in the "feature" box of each page.
*/

// NB: Safari does not allow trailing commas in object literals, although Firefox seems to.
// Neither of them mind trailing commas in arrays.
var featureImages = [
/* Template for copy-and-paste:
    {
        src: '',
        caption: '',
        student: '',
        lab: '',
        lab_url: '',
        cite: '',
        cite_url: ''
    },
*/
    {
        src: 'iwd_backrub.jpg',
        caption: 'High resolution crystal structures reveal a common but subtle mode of local backbone motion -- the "backrub".',
        student: 'Ian Davis',
        lab: 'Richardson',
        lab_url: 'http://kinemage.biochem.duke.edu/lab/Richardson/richardson.php',
        cite: 'Structure. 2006 Feb;14(2):265-74',
        cite_url: 'http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=pubmed&dopt=Abstract&list_uids=16472746&query_hl=1&itool=pubmed_docsum'
    },
    {
        src: 'lwm_rna_distributions.jpg',
        caption: 'Conformations of RNA backbone are described by complex, seven-dimensional distributions.',
        student: 'Laura Murray',
        lab: 'Richardson',
        lab_url: 'http://kinemage.biochem.duke.edu/lab/Richardson/richardson.php',
        cite: 'Proc Natl Acad Sci U S A. 2003 Nov 25;100(24):13904-9',
        cite_url: 'http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=pubmed&dopt=Abstract&list_uids=14612579&query_hl=3&itool=pubmed_docsum'
    },
    {
        src: 'Oas_40states.jpg',
        caption: 'The calculated folding mechanism through 38 partially folded substrates of wild type monomeric lambda repressor. Each circle corresponds to one of five helices in the molecule, in either folded (white) or unfolded (black) conformations. The colored bars in each sub-state represent one of eight inter-helical "bonds" from a diffusion/collision reaction. The width of lines between substrates corresponds to the relative rates of substrate formation. Notice that the substrate with all helices formed except helix 3 (a particularly unstable helix with 2 glycine residues) represents the bottleneck in the folding reaction. This substrate is predicted to transiently accumulate to a significant population (represented by the darkness of each substrate symbol.)',
        student: '',
        lab: 'Oas',
        lab_url: '',
        cite: '',
        cite_url: ''
    },
    {
        src: 'Haase_cellcycle.jpg',
        caption: 'Microscope images showing a yeast cell as it buds and divides. DNA is stained blue and spindle pole bodies (SPBs) are stained in green.',
        student: '',
        lab: 'Haase',
        lab_url: 'http://www.biology.duke.edu/haaselab/research/index.html',
        cite: '',
        cite_url: ''
    },
    {
        src: 'Zhou_AaLpxC-TU514.jpg',
        caption: '',
        student: '',
        lab: 'Zhou',
        lab_url: 'http://zhoulab.biochem.duke.edu/ZhouLab/pzresearch.html',
        cite: '',
        cite_url: ''
    },
    {
        src: 'Bomar-Brief_350.jpg',
        caption: '',
        student: 'Martha Bomar',
        lab: 'Zhou',
        lab_url: 'http://zhoulab.biochem.duke.edu/ZhouLab/pzresearch.html',
        cite: '',
        cite_url: ''
    },
    {
        src: 'Gregas-Brief_350.jpg',
        caption: '',
        student: 'Molly Gregas',
        lab: 'Vo-Dinh',
        lab_url: 'http://fds.duke.edu/db/pratt/BME/faculty/tuan.vodinh',
        cite: '',
        cite_url: ''
    },
    {
        src: 'Block-Brief_350.jpg',
        caption: '',
        student: 'Jeremy Block',
        lab: 'Richardson',
        lab_url: 'http://kinemage.biochem.duke.edu/',
        cite: '',
        cite_url: ''
    },
    {
        src: 'Headd-Brief_350.jpg',
        caption: '',
        student: 'Jeff Headd',
        lab: 'Edelsbrunner & Richardson',
        lab_url: 'http://kinemage.biochem.duke.edu/',
        cite: '',
        cite_url: ''
    },
    {
        src: 'Keedy-Brief_350.jpg',
        caption: '',
        student: 'Daniel Keedy',
        lab: 'Richardson',
        lab_url: 'http://kinemage.biochem.duke.edu/',
        cite: '',
        cite_url: ''
    },

//    {
//        src: 'Endo-Streeter-Brief_350.jpg',
//        caption: '',
//        student: 'Stuart Endo-Streeter',
//        lab: 'York',
//        lab_url: 'http://pharmacology.mc.duke.edu/faculty/york.htm',
//        cite: '',
//        cite_url: ''
//    },

    {
        src: 'Hughes-Brief_350.jpg',
        caption: '',
        student: 'Roy Hughes',
        lab: 'Oas',
        lab_url: 'http://www.biochem.duke.edu/faculty/terrence-oas',
        cite: '',
        cite_url: ''
    },
    {
        src: 'Chang-Brief_350.jpg',
        caption: '',
        student: 'Yu-Chu Chang',
        lab: 'Oas',
        lab_url: 'http://www.biochem.duke.edu/faculty/terrence-oas',
        cite: '',
        cite_url: ''
    },

]

   

// Seeds the random number generator just once at script start
//var now = new Date();
//var seed = now.getSeconds();
//var randomNumber = Math.random(seed);
Math.random((new Date()).getSeconds);
var randomImgIdx = Math.floor(Math.random() * featureImages.length);

// Called at intervals to swap out the current image for a new one
// Can be passed an argument that controls the direction of cycling
function swapFeatureImage()
{
    if(arguments.length >= 1)   randomImgIdx += arguments[0];
    else                        randomImgIdx += 1;
    if(randomImgIdx >= featureImages.length) randomImgIdx = 0;
    if(randomImgIdx < 0) randomImgIdx = featureImages.length-1;
    
    var randomImg = featureImages[ randomImgIdx ]

    var caption = '<p>'+randomImg.caption+'</p>'
    caption += '<p>SBB student '+randomImg.student+', '
    if(randomImg.lab_url != '') caption += '<a href="'+randomImg.lab_url+'">'
    caption += randomImg.lab+' lab'
    if(randomImg.lab_url != '') caption += '</a>'
    if(randomImg.cite != '')
    {
        caption += '<br>'
        if(randomImg.cite_url != '') caption += '<a href="'+randomImg.cite_url+'">'
        caption += randomImg.cite
        if(randomImg.cite_url != '') caption += '</a>'
    }
    caption += '</p>'
    
    var captionTag = document.getElementById('feature_caption')
    captionTag.innerHTML = caption
    
    var imgTag = document.getElementById('feature_img')
    imgTag.src = 'features/'+randomImg.src
    
    // Comment out the line below to get one random image per page, with no swap-outs.
    //setTimeout('swapFeatureImage()', 30*1000) // repeat every 30 seconds
}

// This nifty function means we won't override other ONLOAD handlers
function windowOnload(f)
{
    var prev = window.onload;
    window.onload = function() { if(prev) prev(); f(); }
}

windowOnload(swapFeatureImage)

