// js for HPPA Banner //

var LastHoveredItemNumber = 0;
var LastHoveredItem = 'nothing';
var oldBg;
var newBg;

function ReportButtonClicked()
{
    if ($$('#report-button-link a') != null)
    {
        if ($$('#report-button-link a')[0].href != null)
        {
            window.location = $$('#report-button-link a')[0].href;
            return false;
        }
    }
}


function SetNewBg()
{
$('hppa-behind-bg-container').style.backgroundImage = newBg;

}


function ReallyDoFade()
{
    new Effect.Opacity('hppa-front-bg-container', {duration:1.6, from:1, to:0});
    new Effect.Opacity('hppa-behind-bg-container', {duration:0.7, from:0, to:1});
    setTimeout(SetNewBg, 100);


}


function Fade()
{
    $('hppa-front-bg-container').style.backgroundImage = oldBg;
    
    setTimeout(ReallyDoFade, 100);
  
    FadeText();
}
function DoCopyFade()
{
    $('hppa-copy0').appear({ duration: 1.5, from: 0, to: 1 });
}

function DoSubFade()
{
    $('hppa-subhead0').appear({ duration: 0.5, from: 0, to: 1 });
}   

function FadeText()
{
 

    $('hppa-copy0').style.display = 'none';
    $('hppa-subhead0').style.display = 'none';
    
    
    setTimeout(DoSubFade, 300);
    setTimeout(DoCopyFade, 500);
    
}


function resetAll()
{

    $('hppa-label1').className = "hppa-wrapperoff";
    $('hppa-subhead1').className = "hppa-subheadoff";
    $('hppa-copy1').className = "hppa-copyoff";

    $('hppa-label2').className = "hppa-wrapperoff";
    $('hppa-subhead2').className = "hppa-subheadoff";
    $('hppa-copy2').className = "hppa-copyoff";

    $('hppa-label3').className = "hppa-wrapperoff";
    $('hppa-subhead3').className = "hppa-subheadoff";
    $('hppa-copy3').className = "hppa-copyoff";

    $('hppa-arrow1').src = "/ext/special_report/img/hppa-arrow1.gif";
    $('hppa-arrow2').src = "/ext/special_report/img/hppa-arrow1.gif";
    $('hppa-arrow3').src = "/ext/special_report/img/hppa-arrow1.gif";

}




function TurnWrapperOn(WrapperNumber)
{
    if (LastHoveredItemNumber != WrapperNumber)
    {
		resetAll();
        $('hppa-label' + WrapperNumber).className = "hppa-wrapperon";
        $('hppa-subhead' + WrapperNumber).className = "hppa-subheadon";  
        $('hppa-copy' + WrapperNumber).className = "hppa-copyon"; 

        $('hppa-arrow' + WrapperNumber).src = "/ext/special_report/img/hppa-arrow2.gif";
        
        LastHoveredItemNumber = WrapperNumber;
        
       	Fade(); 
    }
}




function TransferContent(parentElementId)
{

if (parentElementId != LastHoveredItem)
{

LastHoveredItem = parentElementId;

    var contentPathString = 'div#' + parentElementId + ' div.hppa-itemContent';

    // pulls the HTML out of the H2 of the "content div" and puts it in the LARGE content display
    var contentTitle = $$(contentPathString + ' h2');
    if (contentTitle != null && contentTitle[0] != null && contentTitle[0].innerHTML != null)
    {
        $('hppa-subhead0').innerHTML = contentTitle[0].innerHTML; 
    } 
    
    
    // pulls the HTML out of the P tag of the "content div" and puts it in the LARGE content display
    var contentCopy = $$(contentPathString + ' p');
    if (contentCopy != null && contentCopy[0] != null && contentCopy[0].innerHTML != null)
    {
        $('hppa-copy0').innerHTML = contentCopy[0].innerHTML; 
    }     
    


    // pulls the HTML out of the A tag, along with the a tag's HREF attribute value of the "content div" and puts it in the LARGE content display
    var contentButton = $$(contentPathString + ' a');
    if (contentButton != null && contentButton[0] != null && contentButton[0].innerHTML != null)
    {
        $$('#report-button-link a')[0].innerHTML = contentButton[0].innerHTML; 
        $$('#report-button-link a')[0].href = contentButton[0].href; 
    } 
    
    
    // pulls the SRC attribute value from the IMG tag in the content div and puts it in the LARGE content display
    var contentBackground = $$(contentPathString + ' img.hppa-banner-bg-image-source');
    if (contentBackground != null && contentBackground[0] != null && contentBackground[0].src != null)
    {
        try
        {
            oldBg = "url('" + $$('img#currentBgImg')[0].src + "')";
            newBg = "url('" + contentBackground[0].src + "')";
            
            $$('img#currentBgImg')[0].src = contentBackground[0].src;

        }
        catch(ex)
        {
            alert('failed : ' + ex);

        }
    }   
    
    }  
}

function mouseOver1(e)
{

    TransferContent($(this).id);
    TurnWrapperOn(1);

    
	if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}
function mouseOver2(e)
{
    TransferContent($(this).id);
    TurnWrapperOn(2);   

    
	if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}
function mouseOver3(e)
{
    TransferContent($(this).id);
    TurnWrapperOn(3);

    
	if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}




function InitializeHoverBoxes()
{
    $('hppa-label1').onmouseover = mouseOver1;  
    $('hppa-label2').onmouseover = mouseOver2; 
    $('hppa-label3').onmouseover = mouseOver3;
    
    $('report-button-link').onclick = ReportButtonClicked;
}


window.onload = InitializeHoverBoxes; 
