// This section of javscript is for a floating image

var floatimagediv;

function floatimageinit(e)
{
    floatimagediv = document.getElementById("floatimagediv");

    // floatimageinit() and floatimageadjust() are only for IE 5.x and IE 6
    if  ( window.navigator.userAgent.match( /msie +(5|6)/i ) )
    {
        // Call floatimageadjust() if the User scrolls or adjusts the window size
        window.onresize = floatimageadjust;
        window.onscroll = floatimageadjust;

        // Call floatimageadjust() to initialize the image position
        floatimageadjust();
    }
    else if ( window.navigator.userAgent.match( /msie +7|firefox/i ) )
    {
        // The Thomson logo in IE 7 and Firefox is handled automatically by browser : "position: fixed"

        // For Chart Builder's Main and Grid View page, as well as the main Summary page and the Home page,
        // get the Thomson logo coordinates after the User scrolls
        // or adjusts the window size
        if ( document.URL.match( /subsectionModeRadio=grid|chart_builder_instructions|oden_parse|t_inside/i ) )
        {
            // setthomsonlogocoordinates() checks if the mouse is near the logo and conditionally modifies the logo's properties
            window.onresize = setthomsonlogocoordinates;
            window.onscroll = setthomsonlogocoordinates;

            // Initialize Thomson logo coordinates
            if ( window.navigator.userAgent.match( /firefox/i ) )
            {
                setthomsonlogocoordinates(e);
            }
            else if ( window.navigator.userAgent.match( /msie/i ) )
            {
                setthomsonlogocoordinates(event);
            }
        }
    }
}

function floatimageadjust( recursivecall )
{
    // setthomsonlogocoordinates() records the logo's position and modifies the logo properties if needed
    if ( !recursivecall )
    {
        setthomsonlogocoordinates( event );
    }

    // IE 7 and Firefox automatically reposition a { position: fixed; right: 0px; bottom: 0px; } div element

    // IE 6 and IE 5.5 do not automatically reposition a { position: fixed; right: 0px; bottom: 0px; } div element
    // but they do automatically reposition a { position: absolute; right: 0px; bottom: 0px; } div element
    // when you modify an adjacent div's innerHTML
    // You can also get the same result by setting the Thomson logo div's innerHTML,
    // but the browser takes too long to reload the image
    // Use this work around for Chart Builder, Oden parse and Welcome pages
    if  ( this.name.match( /chartbuilder|f_inside_body/i ) )
    {
        if ( document.getElementById( "positioningdiv" ) )
        {
            document.getElementById( "positioningdiv" ).innerHTML = "";
        }
        else { return; }
    }
    else
    {
        // Place image on right hand side of viewport
        floatimagediv.style.left = document.body.scrollLeft + document.body.clientWidth - floatimagediv.offsetWidth;

        // Place image at bottom of viewport
        floatimagediv.style.top = document.body.scrollTop + document.body.clientHeight - floatimagediv.offsetHeight;
    }

    // Call this function again because the document.body.clientHeight is calculated before the horizontal scrollbar
    // is added or removed
    if ( !recursivecall )
    {
        setTimeout("floatimageadjust(1)", 100);
    }
}

var thomsonlogoperimeter = 35;
if ( window.navigator.userAgent.match( /msie +5/i ) ) { thomsonlogoperimeter = 45 }

function testmouseproximitytologo()
{
    var floatimage = document.getElementById('floatimage');
    var floatimagediv = document.getElementById('floatimagediv');

    // Only respond to the mousemove event part of the time
    if ( ( totalmousemoveevents % mouseeventgovernor ) ) { return } // These globals are in coordinates.js

    // Is the the mouse near the logo?
    if  (
            mousecoordinates.viewportx >= ( thomsonlogocoordinates.viewportleftx - thomsonlogoperimeter )
            &&
            mousecoordinates.viewportx <= ( thomsonlogocoordinates.viewportrightx + thomsonlogoperimeter )
            &&
            mousecoordinates.viewporty >= ( thomsonlogocoordinates.viewporttopy - thomsonlogoperimeter )
            &&
            mousecoordinates.viewporty <= ( thomsonlogocoordinates.viewportbottomy + thomsonlogoperimeter )
        )
    {
        if  (
                (
                    floatimage.style.opacity
                    &&
                    ( floatimage.style.opacity == 1 )
                )
                ||
                (
                    floatimage.style.filter
                    &&
                    floatimage.style.filter.match( /opacity=100/i )
                )
            )
        {
            if  ( window.navigator.userAgent.match( /firefox/i ) )
            {
                floatimage.style.opacity = "0.35";
            }
            else if ( window.navigator.userAgent.match( /msie/i ) )
            {
                floatimage.style.filter = "alpha(opacity=35)";
            }

            floatimagediv.style.zIndex = -1;
        }
    }
    else
    {
        if  (
                (
                    floatimage.style.opacity
                    &&
                    ( floatimage.style.opacity == 0.35 )
                )
                ||
                (
                    floatimage.style.filter
                    &&
                    floatimage.style.filter.match( /opacity=35/i )
                )
            )
        {
            if  ( window.navigator.userAgent.match( /firefox/i ) )
            {
                floatimage.style.opacity = "1.0";
            }
            else if ( window.navigator.userAgent.match( /msie/i ) )
            {
                floatimage.style.filter = "alpha(opacity=100)";
            }

            floatimagediv.style.zIndex = 0;
        }
    }
}

function setthomsonlogocoordinates( e )
{
    var eventtype;

    if ( window.navigator.userAgent.match( /firefox/i ) )
    {
        eventtype = e.type;
    }
    else if ( window.navigator.userAgent.match( /msie/i ) )
    {
        eventtype = event.type;
    }

    // For position fixed, only process if this is called from the onload or resize events
    if  (
            document.getElementById( 'floatimagediv' ).style.position.match( /fixed/i )
            &&
            !eventtype.match( /load|resize/i )
        )
    {
        return;
    }

    thomsonlogocoordinates.setelementcoordinates( thomsonlogocoordinates.element, 0 );

    //alert( 'VPmouse: ' + mousecoordinates.viewportx + ', ' + mousecoordinates.viewporty + '\nVPx: ' + thomsonlogocoordinates.viewportleftx + ', ' + thomsonlogocoordinates.viewportrightx + '\nVPy: ' + thomsonlogocoordinates.viewporttopy + ', ' + thomsonlogocoordinates.viewportbottomy );
    //alert( 'Actualmouse: ' + mousecoordinates.actualx + ', ' + mousecoordinates.actualy + '\nAx: ' + thomsonlogocoordinates.actualleftx + ', ' + thomsonlogocoordinates.actualrightx + '\nAy: ' + thomsonlogocoordinates.actualtopy + ', ' + thomsonlogocoordinates.actualbottomy );
}
