﻿
var nf_Root;
var nf_ttlMsgs;
var nf_currAnimateMsg=0;
var nf_delay=15000;
var nf_step=5;
var nf_speed=10;
var nf_widthOffset=222;
var nf_imgHeightOffset=22;
var nf_CurrHeight= nf_imgHeightOffset;
var nf_MaxHeight;
var nf_subCurrHeight= 0;
var nf_subMaxHeight= 34;
var nf_cancel=false;
var bWidth = 0;
var bHeight = 0;
    function getBrowserSize() 
    {  
      if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        bWidth = window.innerWidth;
        bWidth=bWidth-20;
        bHeight = window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        bWidth = document.documentElement.clientWidth;
        bHeight = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        bWidth = document.body.clientWidth;
        bHeight = document.body.clientHeight;
      }
    }
    function nf_Start(count)
    {
        getBrowserSize();
        nf_ttlMsgs = count;
        nf_Root = document.getElementById('NewsFlash');
        nf_Root.style.visibility='hidden';
        if (nf_ttlMsgs>4)
        {
            nf_ttlMsgs=4;
        }
        if (nf_ttlMsgs>0)
            {
                for (var i=0; i<=(nf_ttlMsgs-1); i++)
                {
                    prepareChild('nf_Msg_' + i);
                }
                prepareChild('nf_MaxMsgs');
                nf_MaxHeight=(nf_subMaxHeight*nf_ttlMsgs)+nf_imgHeightOffset;
                var adminBarTest = document.getElementById('SlidingAdminDiv')
                if (adminBarTest==null){nf_Root.style.top="0px";}else{nf_Root.style.top="25px";}
                nf_Root.style.position="absolute";
                nf_Root.style.left=(bWidth - nf_widthOffset) ;
                nf_Root.style.width=nf_widthOffset + "px";
                nf_Root.style.height=nf_imgHeightOffset + "px";
                nf_Root.style.overflow='hidden';
                nf_Root.style.visibility='visible';
                setTimeout('animate_NFOut(true,\'nf_Msg_' + nf_currAnimateMsg + '\')',nf_speed);
            }
    }
    function hide_NF()
    {
        nf_Root.style.top="0px";
        nf_Root.style.position="absolute";
        nf_Root.style.left=(window.screen.Width - nf_widthOffset) + "px";
        nf_Root.style.width=nf_widthOffset + "px";
        nf_Root.style.height="0px";
        nf_Root.style.visibility='hidden';
        nf_Root.style.overflow='hidden';
        for (var i=0; i<=(nf_ttlMsgs-1); i++)
        {
            hideChild('nf_Msg_' + i);
        }
        nf_cancel=true;
    }
    
    function prepareChild(id)
    {
        var nf_Child = document.getElementById(id);
        nf_Child.style.visibility='hidden';
        nf_Child.style.overflow='hidden';
        nf_Child.style.height="0px";        
    }
    function hideChild(id)
    {
        var nf_Child = document.getElementById(id);
        nf_Child.style.position='absolute';
        nf_Child.style.visibility='hidden';
        nf_Child.style.overflow='hidden';
        nf_Child.style.height="0px";        
    }
    function animateNFChild(id)
    {
        var nf_Child = document.getElementById(id);
        nf_Child.style.visibility='visible';
        nf_Child.style.height=nf_subCurrHeight+"px";
    }
    function animate_NFOut(firstTime,currSubID)
    {
        if (nf_cancel==false)
        {
            if (firstTime==true)
                {
                    nf_subCurrHeight=0;
                    firstTime=false;
                }
            nf_subCurrHeight= nf_subCurrHeight+nf_step;
            if (nf_subCurrHeight>nf_subMaxHeight)
            {
                nf_subCurrHeight=nf_subMaxHeight;
            }
            nf_CurrHeight=nf_CurrHeight+nf_step;
            if (nf_CurrHeight>nf_MaxHeight)
            {
                nf_CurrHeight=nf_MaxHeight;
            }
            animateNFChild(currSubID)
            nf_Root.style.height=nf_CurrHeight + "px";     
            if (nf_subCurrHeight==nf_subMaxHeight&&nf_CurrHeight!=nf_MaxHeight)
            {
                nf_currAnimateMsg+=1;
                setTimeout('animate_NFOut(true,\'nf_Msg_' + nf_currAnimateMsg + '\')',nf_speed);
            }
            if (nf_subCurrHeight!=nf_subMaxHeight&&nf_CurrHeight!=nf_MaxHeight)
            {
                setTimeout('animate_NFOut(false,\''+currSubID+'\')',nf_speed);
            }
            if (nf_subCurrHeight==nf_subMaxHeight&&nf_CurrHeight==nf_MaxHeight&&currSubID!='nf_MaxMsgs')
            {
                nf_currAnimateMsg=0;
                setTimeout('animate_NFIn(true,\'nf_Msg_' + nf_currAnimateMsg + '\')',nf_delay); 
            }  
            if (nf_subCurrHeight==nf_subMaxHeight&&nf_CurrHeight==nf_MaxHeight&&currSubID=='nf_MaxMsgs')
            {
                nf_currAnimateMsg=0;
                setTimeout('animate_NFIn(true,\'nf_MaxMsgs\')',nf_delay); 
            } 
        }                
    }
    function animate_NFIn(firstTime,currSubID)
    {
        if (nf_cancel==false)
        {
            if (firstTime==true)
                {
                    nf_subCurrHeight=nf_subMaxHeight;
                    firstTime=false;
                }
            nf_subCurrHeight= nf_subCurrHeight-nf_step;
            if (nf_subCurrHeight<0)
            {
                nf_subCurrHeight=0;
            }
            nf_CurrHeight=nf_CurrHeight-nf_step;
            if (nf_CurrHeight<nf_imgHeightOffset)
            {
                nf_CurrHeight=nf_imgHeightOffset;
            }
            animateNFChild(currSubID)
            nf_Root.style.height=nf_CurrHeight + "px";     
            if (nf_subCurrHeight==0&&nf_CurrHeight!=nf_imgHeightOffset)
            {
                hideChild(currSubID);
                //prepareChild('nf_MsgLink_' + nf_currAnimateMsg);
                //prepareChild('nf_MsgSpan_' + nf_currAnimateMsg);    
                nf_currAnimateMsg+=1;                   
                setTimeout('animate_NFIn(true,\'nf_Msg_' + nf_currAnimateMsg + '\')',nf_speed) ;
            }
            if (nf_subCurrHeight!=0&&nf_CurrHeight!=nf_imgHeightOffset)
            {
                setTimeout('animate_NFIn(false,\''+currSubID+'\')',nf_speed) ;
            }
            if (nf_subCurrHeight==0&&nf_CurrHeight==nf_imgHeightOffset&&currSubID!='nf_MaxMsgs')
            {
                hideChild(currSubID);
               // prepareChild('nf_MsgLink_' + nf_currAnimateMsg);
                //prepareChild('nf_MsgSpan_' + nf_currAnimateMsg); 
                nf_currAnimateMsg=0;          
                nf_MaxHeight=nf_subMaxHeight+nf_imgHeightOffset;
                setTimeout('animate_NFOut(true,\'nf_MaxMsgs\')',nf_speed) ;
            }    
            if (nf_subCurrHeight==0&&nf_CurrHeight==nf_imgHeightOffset&&currSubID=='nf_MaxMsgs')
            {
                nf_currAnimateMsg=0;
                hideChild(currSubID);
            }  
        }      
    }
