/**
* Resize too large images
* (c) Tale 2008
* http://www.taletn.com/
*/
var reimg_version = 0.000003;
document.writeln('<style type="text/css" media="screen, projection"><!--');
document.writeln('.reimg { width: 1px; height: 1px; visibility: hidden; }');

if (window.reimg_swapPortrait && window.reimg_maxWidth && window.reimg_maxHeight && reimg_maxHeight > reimg_maxWidth)
    {
    reimg_maxWidth += reimg_maxHeight;
    reimg_maxHeight = reimg_maxWidth - reimg_maxHeight;
    reimg_maxWidth -= reimg_maxHeight;
    }

if (window.reimg_maxWidth)
    {
    document.writeln('.reimg-width { width: ' + reimg_maxWidth + 'px; height: auto; }');

    if (window.reimg_swapPortrait)
        document.writeln('.reimg-width-portrait { width: auto; height: ' + reimg_maxWidth + 'px; }');
    }

if (window.reimg_maxHeight)
    {
    document.writeln('.reimg-height { width: auto; height: ' + reimg_maxHeight + 'px; }');

    if (window.reimg_swapPortrait)
        document.writeln('.reimg-height-portrait { width: ' + reimg_maxHeight + 'px; height: auto; }');
    }

if (window.reimg_zoomImg)
    {
    document.writeln('span.reimg-zoom { position: absolute; text-align: '
        + (window.reimg_zoomAlign
            ? reimg_zoomAlign
            : 'left') + '; }');
    document.writeln('img.reimg-zoom { margin: 1px; border: none; cursor: pointer;'
        + (window.reimg_zoomStyle
            ? ' ' + reimg_zoomStyle
            : '') + ' }');

    if (window.reimg_zoomHover)
        document.writeln('img.reimg-zoom:hover { ' + reimg_zoomHover + ' }');
    }
document.write('--></style>');

function reimg_unhide(img)
    {
    if (img.className)
        img.className = img.className.replace(/(^|.*\s)reimg(\s+(.*)|$)/, '$1$3');
    }
var reimg_zoomLink = null;
var reimg_orgSize = new Array();

function reimg_zoomIn(e)
    {
    if (! e)
        e = window.event;
    target = this;

    if (e)
        {
        if (target == window)
            target = e.target ? e.target : e.srcElement;

        if (typeof (e.stopPropagation) != "undefined")
            e.stopPropagation();

        else
            e.cancelBubble = true;
        }

    if (! target)
        return false;

    if (! reimg_zoomLink)
        {
        reimg_zoomLink = document.createElement("a");
        reimg_zoomLink.style.display = "none";

        if (window.reimg_zoomTarget == "_blank")
            {
            try
                {
                reimg_zoomLink.target = "_blank";
                }
            catch (err)
                {
                }
            }
        document.body.appendChild(reimg_zoomLink);
        }
    reimg_zoomLink.href = target.parentNode.nextSibling.src;

    if (window.reimg_zoomTarget == "_blank")
        {
        if (reimg_zoomLink.target && typeof (reimg_zoomLink.click) != "undefined")
            reimg_zoomLink.click();

        else
            window.open(reimg_zoomLink.href);
        }

    else if (window.reimg_zoomTarget == "_litebox" && window.litebox_version)
        {
        var width, height;

        if (reimg_orgSize[reimg_zoomLink.href])
            {
            width = reimg_orgSize[reimg_zoomLink.href][0];
            height = reimg_orgSize[reimg_zoomLink.href][1];
            }

        else
            {
            width = target.nextSibling.width;
            height = target.nextSibling.height;
            }
        litebox_show(reimg_zoomLink.href, width, height);
        }

    else
        {
        if (! window.exturl_version || exturl(reimg_zoomLink))
            window.location.href = reimg_zoomLink.href;
        }
    return false;
    }

function reimg_resize(img, orgWidth, orgHeight, safetyNet)
    {
    if (! img)
        return;

    if (img.readyState == "complete" && img.complete && ! safetyNet)
        return;
    reimg_unhide(img);
    var width = img.width, height = img.height;

    if (!(width && height))
        {
        if (! safetyNet)
            img.className = (img.className ? img.className + " " : "") + "reimg";
        return;
        }

    if (window.reimg_zoomTarget == "_litebox" && ! reimg_orgSize[img.src])
        {
        if (width && height)
            if (orgWidth && ! orgHeight)
                orgHeight = Math.round(orgWidth / (width / height));

            else if (orgHeight && ! orgWidth)
                orgWidth = Math.round(orgHeight / (height / width));

        if (orgWidth && orgHeight)
            reimg_orgSize[img.src] =
                [
                orgWidth,
                orgHeight
                ];

        else
            reimg_orgSize[img.src] =
                [
                width,
                height
                ];
        }

    var swap = false;

    if (window.reimg_swapPortrait && height > width)
        {
        swap = true;
        width = img.height;
        height = img.width;
        }
    var className = "";

    if (width && window.reimg_maxWidth && width > reimg_maxWidth)
        {
        height = Math.round(height / (width / reimg_maxWidth));
        width = reimg_maxWidth;

        if (height && window.reimg_maxHeight && height > reimg_maxHeight)
            {
            width = Math.round(width / (height / reimg_maxHeight));
            height = reimg_maxHeight;
            className = "reimg-both";
            }

        else
            className = "reimg-width" + (swap ? "-portrait" : "");
        }

    else if (height && window.reimg_maxHeight && height > reimg_maxHeight)
        {
        width = Math.round(width / (height / reimg_maxHeight));
        height = reimg_maxHeight;

        if (width && window.reimg_maxWidth && width > reimg_maxWidth)
            {
            height = Math.round(height / (width / reimg_maxWidth));
            width = reimg_maxWidth;
            className = "reimg-both";
            }

        else
            className = "reimg-height" + (swap ? "-portrait" : "");
        }

    if (swap)
        {
        width += height;
        height = width - height;
        width -= height;
        }

    if (! className && (! orgWidth || width >= orgWidth) && (! orgHeight || height >= orgHeight))
        return;

    if (window.reimg_zoomImg)
        {
        var span = document.createElement("span");
        span.style.width = width + "px";
        var zoom = document.createElement("img");
        zoom.src = reimg_zoomImg;

        if (window.reimg_zoomAlt)
            zoom.alt = zoom.title = reimg_zoomAlt.replace(/%1\$d/, orgWidth
                ? orgWidth
                : img.width).replace(/%2\$d/,
                orgHeight
                    ? orgHeight
                    : img.height);
        zoom.className = span.className = "reimg-zoom";
        zoom.onclick = reimg_zoomIn;
        span.appendChild(zoom);
        img.parentNode.insertBefore(span, img);
        }
    img.className = (img.className ? img.className + " " : "") + className;
    img.width = width;
    img.height = height;

    if (window.litebox_version && litebox_background && litebox_background.style.display != "none")
        litebox_calc();
    }

function reimg_onLoad(e)
    {
    var images = document.getElementsByTagName("img");

    if (! images)
        return true;

    for (var n = 0; n < images.length; n++)
        {
        if (! images[n].className.match(/(^|\s)reimg(\s|$)/))
            continue;

        reimg_resize(images[n], null, null, true);
        }
    return true;
    }

if (window.onload_functions)
    onload_functions[onload_functions.length] = "reimg_onLoad();";

else if (typeof (window.addEventListener) != "undefined")
    window.addEventListener("load", reimg_onLoad, false);

else if (typeof (window.attachEvent) != "undefined")
    window.attachEvent("onload", reimg_onLoad);