/**
 * CHANGE HEADS OF THE THREE PERSONS ON THE SITE
 * @author: Steffen Muecke, quellkunst multimedia, 2008
 * @email: mail@quellkunst.de
 *
 * feel free to use this code in any way you like.
 * this code is given "as is". the author takes no responsibilities
 * for any effects related to the usage of this code.
 *
 */

/** SETTINGS - imagepath relative to html **/
var imagepath = "stcimg/";
/** SETTINGS - filenames for each of the heads' images **/
var heads = new Array();
    heads[1] = new Array(0,"mv_p1h1.jpg","mv_p1h2.jpg","mv_p1h3.jpg","mv_p1h4.jpg","mv_p1h5.jpg"); // person on the left
    heads[2] = new Array(0,"mv_p2h1.jpg","mv_p2h2.jpg","mv_p2h3.jpg"); // person in the middle
    heads[3] = new Array(0,"mv_p3h1.jpg","mv_p3h2.jpg","mv_p3h3.jpg"); // person on the right
/** SETTINGS - minimum and maximum interval [in milliseconds] for changing heads **/
var mintimeout = 8000;
var maxtimeout = 16000;
/** END OF SETTINGS ---------------------------- **/

function changeheads(who,of) {
    if(!who || !of || isNaN(of)) return;
    of = parseInt(of); var nextnum = false;
    while(!nextnum) {
        var headsimg = Math.floor((heads[of].length - 1) * Math.random()) + 1;
        if(headsimg != heads[of][0]) nextnum = true;
    }
    heads[of][0] = headsimg;
    who.style.backgroundImage = "url("+imagepath+heads[of][headsimg]+")";
    
    var newtimeout = Math.round(Math.round(Math.random() * 1000 + 1) / 1000 * maxtimeout);
    if(newtimeout < mintimeout) newtimeout = mintimeout;
    window.setTimeout(function(){changeheads(who,of)},newtimeout);
}