/*
 * Functions to loop through rolling media values
 * Slightly complicated solution to allow for caching
 */
function randOrd(a, b){
  return (Math.round(Math.random())-0.5);
}

function rotateVal(arr, idx, f, timeout) {
    if (idx == arr.length) {
        idx = 0;
    }
    f(arr[idx++]);
    setTimeout(function() {rotateVal(arr, idx, f, timeout);}, timeout);
}

function rotate() {
    quoteArray.sort(randOrd);

    var timeout = 10000;
    var fadeout = 1000;

    setTimeout(function() { 
        rotateVal(quoteArray, 0, function(val) {
            $("#quotes").fadeOut(fadeout, function() {
                $(this).html("'" + val + "'");
                $(this).fadeIn(fadeout);
            });
        }, timeout);
    }, timeout);
}

$(document).ready(rotate);
