var dummy = new Array();

function preload_img() {
    var names = new Array('3b', '3c', '4b', '5b');
    for (var i = 0; i < names.length; i++) {
        dummy[i] = new Image();
        dummy[i].src = 'images/slice' + names[i] + '.gif';
    }
}

function toggle_heart(state) {
    if ('undefined' != typeof(document.images)) {
        document.images['msg'].src   = state ? 'images/slice3b.gif' : 'images/slice3a.gif';
        document.images['heart'].src = state ? 'images/slice4b.gif' : 'images/slice4a.gif';
    }
}

function toggle_envelope(state) {
    if ('undefined' != typeof(document.images)) {
        document.images['msg'].src      = state ? 'images/slice3c.gif' : 'images/slice3a.gif';
        document.images['envelope'].src = state ? 'images/slice5b.gif' : 'images/slice5a.gif';
    }
}

function pop_and_center(url, w, h) {
    var opt = "menubar=no,toolbar=no,location=no,directories=no,fullscreen=no"
            + ",titlebar=no,hotkeys=no,status=no,scrollbars=no,resizable=yes";

    var fudge = 24;

    var has_body = ('undefined' != typeof(document) && 'undefined' != typeof(document.body));
    var has_win  = ('undefined' != typeof(window));
    var has_de   = ('undefined' != typeof(document) && 'undefined' != typeof(document.documentElement));

    var parent_w = 800;
    if (has_win && 'undefined' != typeof(window.outerWidth) && window.outerWidth)
        parent_w = window.outerWidth;
    else if (has_de && 'undefined' != typeof(document.documentElement.clientWidth) && document.documentElement.clientWidth)
        parent_w = document.documentElement.clientWidth;
    else if (has_body && 'undefined' != typeof(document.body.clientWidth) && document.body.clientWidth)
        parent_w = document.body.clientWidth;
    else if (has_body && 'undefined' != typeof(document.body.offsetWidth) && document.body.offsetWidth)
        parent_w = document.body.offsetWidth;

    var parent_h = 600;
    if (has_win && 'undefined' != typeof(window.outerHeight) && window.outerHeight)
        parent_h = window.outerHeight;
    else if (has_de && 'undefined' != typeof(document.documentElement.clientHeight) && document.documentElement.clientHeight)
        parent_h = document.documentElement.clientHeight;
    else if (has_body && 'undefined' != typeof(document.body.clientHeight) && document.body.clientHeight)
        parent_h = document.body.clientHeight;
    else if (has_body && 'undefined' != typeof(document.body.offsetHeight) && document.body.offsetHeight)
        parent_h = document.body.offsetHeight;

    var left = 0;
    if (has_win && 'undefined' != typeof(window.screenLeft))
        left = window.screenLeft;
    else if (has_win && 'undefined' != typeof(window.screenX))
        left = window.screenX;

    var top  = 0;
    if (has_win && 'undefined' != typeof(window.screenTop))
        top = window.screenTop;
    else if (has_win && 'undefined' != typeof(window.screenY))
        top = window.screenY;

    var pos_x = Math.floor(left + (parent_w - w) / 2);
    var pos_y = Math.floor(top  + (parent_h - h) / 2) - fudge;
    if (0 > pos_x)
        pos_x = 0;
    if (0 > pos_y)
        pos_y = 0;

    window.open(url, '_blank', 'width='    + w       + ',height='  + h     +
                               ',left='    + pos_x   + ',top='     + pos_y +
                               ',screenX=' + pos_x   + ',screenY=' + pos_y + ',' + opt);
}
