var prt = true;

function background() {
    bgs = new Array("waveform.gif", "drips.gif", "noise.gif", "feather.gif", "feet.jpg");
    n = Math.floor(Math.random()*bgs.length);
    document.body.style.backgroundImage = "url('backgrounds/" + bgs[n] + "')";
}

function portrait(val) {
    obj = document.getElementById("portrait");
    hdg = document.getElementsByTagName("h1")[0];
    mup = document.getElementById("menu-person");
    if (val) {
        var picm = {type: 'top', to: 0, step: 10, delay: 15};
        var head = {type: 'top', to: 335, step: 10, delay: 15};
        var menu = {type: 'top', to: 380, step: 10, delay: 15};
        sitepart(false);
    } else {
        var picm = {type: 'top', to: -320, step: -10, delay: 15};
        var head = {type: 'top', to: 15, step: -10, delay: 15};
        var menu = {type: 'top', to: 60, step: -10, delay: 15};
    }
    $fx(obj).fxAdd(picm).fxRun();
    $fx(hdg).fxAdd(head).fxRun();
    $fx(mup).fxAdd(menu).fxRun();
    prt = val;
}

var visible = false;
var killthis = "";

var animationfinish = function() {
    kll = document.getElementById(killthis);
    kll.style.display = "none";
}

function sitepart(tgt) {
    if (visible && (visible != tgt)) {
        vsb = document.getElementById(visible);
        killthis = visible;
        var disappear = {type: 'opacity', from:100, to:0, step: -10, delay:60}
        $fx(vsb).fxAdd(disappear).fxRun(animationfinish);
    }
    if (tgt && (visible != tgt)) {
        portrait(false);
        tgo = document.getElementById(tgt);
        tgo.style.opacity = "0";
        tgo.style.display = "block";
        var appear = {type: 'opacity', from:0, to:100, step: 10, delay:60}
        $fx(tgo).fxAdd(appear).fxRun();
    }
    visible = tgt;
}

var lcn = "";
var count = 0;

function checklocation() {
    current = window.location.hash;
    if ("#" + lcn != current) {
        part = window.location.hash.split("#")[1];
        if (part != "portrait") {
            if (part == 'person-weblog' && !showiframe) {
                iframe();
            }
            sitepart(part);
            lcn = part;
        } else {
            portrait(true);
            lcn = "portrait";
        }
    }
}

function init() {
    background();
    window.setInterval('checklocation()',150);
}

window.onload = init;
