﻿/* enlargementimage.js - mouseover image enlargement */
/* depends on a div with id "floatingdivid" containing an image with id "floatingimageid" */
/* images to be enlarged should contain 'onload="cacheBigImage(this);" onmouseover="showfloater(this);" onmouseout="startFTime();"' */
/* floating image with id "floatingimageid" should contain 'onmouseover="stopFTime();" onmouseout="startFTime();"' */
var timerFID = null; 
var timerFOn = false; 
var timeFcount = 4;
var imageEnlargementFactor = 1.25;
var enlargementArray = new Array();
var altname = new Array();
var cached = new Array();

function stopFTime() { 
    if (timerFOn) { 
        clearTimeout(timerFID); 
        timerFID = null; 
        timerFOn = false; 
    } 
}

function getfloaterst() {
    if (document.getElementById)
        return document.getElementById("floatingdivid").style;
    else if (document.all)
        return document.all.floatingdivid.style;
}

function getfloatingimage() {
    if (document.getElementById)
        return document.getElementById("floatingimageid");
    else if (document.all)
        return document.all.floatingimageid;
}

function getfloatinglink() {
    if (document.getElementById)
        return document.getElementById("enlargedlink");
    else if (document.all)
        return document.all.enlargedlink;
}

function getfloatingtopictitle() {
    if(document.getElementById)
        return document.getElementById("labeltopictitle");
    else if (document.all)
        return document.all.labeltopictitle;
}

function findaPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
            curleft += obj.offsetLeft;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findaPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
            curtop += obj.offsetTop;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function hidefloater() {
    stopFTime();
    getfloaterst().visibility = "hidden"
}

function showfloater(obj, linkdest, cachedimagename) {
    hidefloater();
    if(cached[cachedimagename] == 0)
    {
        cacheBigImage(obj, cachedimagename);
    }
    var fimage = getfloatingimage();
    var fsty = getfloaterst();
    var fposx = findaPosX(obj);
    var fposy = findaPosY(obj);
    var fsx = parseInt(imageEnlargementFactor * obj.width);
    var fsy = parseInt(imageEnlargementFactor * obj.height);
    var fpx = fposx + parseInt((obj.width / 2) - (fsx / 2));
    var fpy = fposy + parseInt((obj.height / 2) - (fsy / 2));
    var limiter = fsx;
    var flink = getfloatinglink();
    flink.target = "_blank";
    flink.href = "" + linkdest + "";
    fimage.src = enlargementArray[cachedimagename].src;
    fimage.width = fsx;
    fimage.height = fsy;
    fsty.top = fpy + "px";
    fsty.left = fpx + "px";
    fsty.width = fsx + "px";
    fsty.height = fsy + "px";
    fsty.visibility = "visible";
}

function showtopicfloater(obj, linkdest, cachedimagename, topictitle) {
    showfloater(obj, linkdest, cachedimagename);
    var fimage = getfloatingimage();
    var fsty = getfloaterst();
    var ftitle = getfloatingtopictitle();
    var fdivx = parseInt(imageEnlargementFactor * obj.width) + 2;
    var fdivy = parseInt(imageEnlargementFactor * obj.height);
    var flink = getfloatinglink();
    fsty.width = fdivx + "px";
    ftitle.innerHTML = topictitle;
    fimage.title = ""; /* topictitle; */
    fimage.alt = ""; /* topictitle; */
    flink.target = "_top";

    var fpx = findaPosX(obj) + parseInt( (obj.width - (imageEnlargementFactor * obj.width)) / 2 );
    var fpy = findaPosY(obj) + parseInt( (obj.height - (imageEnlargementFactor * obj.height)) / 2 );
    if(document.documentElement && typeof document.documentElement.style.maxHeight!="undefined")
    { // ie7 finding hack to deal with carousel style offset fix
        fpx = fpx - 20;
        if(window.Iterator)
        { // turns out the ie7 hack works in ff3, so this hacks back out of it (ff3 hack)
            fpx = fpx + 19;
        }
    }
    fsty.top = fpy - 10 + "px";
    fsty.left = fpx + "px";

}


function startFTime() { 
    if (timerFOn == false) 
    { 
        timerFID=setTimeout( "hidefloater()" , timeFcount); 
        timerFOn = true; 
    } 
} 

function cacheBigImage(obj, cachedimagename) {
    var bsx = 0;
    var bsy = 0;
    bsx = parseInt(imageEnlargementFactor * obj.width);
    bsy = parseInt(imageEnlargementFactor * obj.height);
    var blimiter = bsx;
    if(bsy > bsx)
        blimiter = bsy;
    var tsrc = "" + obj.src + "";
    tsrc = tsrc.replace("height=","ohig=");
    tsrc = tsrc.replace("width=","owid=");
    tsrc = tsrc + "&height=" + blimiter + "&width=" + blimiter + "";
    enlargementArray[cachedimagename] = new Image();
    enlargementArray[cachedimagename].src = tsrc;
    altname[cachedimagename] = cachedimagename;
    if(bsx == 0 || bsy == 0)
    {
        cached[cachedimagename] = 0;
    }
    else
    {
        cached[cachedimagename] = 1;
    }
}