// util.js...

function Browser() {
    this.av             = navigator.appVersion.toLowerCase();
    this.browserName    = navigator.appName.toLowerCase();
    this.browserVersion = parseInt(this.av);
    this.dom            = (document.getElementById) ? true : false;
} 
var browser = new Browser();

var timer = null;

function init() {
    if (next()) {
        schedule();
    }
}

function schedule() {
    if (timer != null) {
        clearTimeout(timer);
    }
    timer = window.setInterval(next, 30000);
}

function next() {
    if (browser.dom) {
        var image = document.getElementById("image");
        var text  = document.getElementById("image-text");
        if (image != null && text != null && text.innerHTML != undefined) {
            var t = teasers[index++ % teasers.length];
            image.src = t.image;
            image.alt = t.altText + " (click for next...)";
            text.innerHTML = t.text;
            return true;
        }
    }
    return false;
}

function clickNext() {
    if (browser.dom) {
        next();
        schedule();
    }
}

function Teaser(image, altText, text) {
    this.image = image;
    this.altText = altText;
    this.text = text;    
}

var teasers = [
    new Teaser('images/defence.jpg', 'Gunni at the oral defence of the thesis on November 2nd, 2007', 'The picture to the right is me at the oral defence of the thesis given on November 2nd, 2007, at the <a class="location" href="http://www.diku.dk/english/" title="DIKU">Department of Computer Science, University of Copenhagen</a>. Fabulous facilities, as you can see... :)'),
    new Teaser('images/lurifax.jpg', 'Lurifax is exhausted from reading the "Design Patterns" book by Gamma et al.', 'The picture to the right shows one of my great supporters during the writing of the thesis, namely my cat, Lurifax. As you can see, regardless of how interesting it is, reading the <a class="location" href="Bibliography.htm#Gamma95" title="Gamma95" target="thesis-bioliography">"Design Patterns"</a> book by Gamma et al. <i>can</i> be a tiresome job indeed... :)'),
    new Teaser('images/filur.jpg',   'Filur drinking *my* coffee to stay awake!', 'The picture to the right shows one of my great supporters during the writing of the thesis, namely my cat, Filur. However, having dedicated supporters is not always a good thing, as the darn cat kept stealing my coffee and literally kept clawing his way through various books... :)')
];
var index = new Date().getSeconds() % teasers.length;

window.onload = init;
window.onerror = 
    function() {
       return true;
    };
