
var PC_SPACER_MOVE_HEIGHT_TIME = 500;
var g_oPcSpacerCheckHeightTimeout = null;
function pcSpacerCheckHeightClearTimeout() {
    try {
        clearTimeout(g_oPcSpacerCheckHeightTimeout);
        g_oPcSpacerCheckHeightTimeout = null;
    } catch(oException) {
        // do nothing
    }
}
function pcSpacerCheckHeight() {
    pcSpacerCheckHeightClearTimeout();

    if ($('#pc-spacer').height() != $('#pc').height())
    {
        pcSpacerMoveHeight(PC_SPACER_MOVE_HEIGHT_TIME);
    }
    else
    {
        g_oPcSpacerCheckHeightTimeout = setTimeout('pcSpacerCheckHeight()', 1000);
    }
}
function pcSpacerMoveHeight(p_nTransitionTime) {
    pcSpacerCheckHeightClearTimeout();

    if (p_nTransitionTime == 0)
    {
        $('#pc-spacer').height($('#pc').height());
    }
    else
    {
        if ($('#pc-spacer').height() != $('#pc').height())
        {
            $('#pc-spacer').animate({height: $('#pc').height()},
                                    p_nTransitionTime,
                                    'easeInOutExpo',
                                    function() {
                                        fasciaCentraleMoveTop();
                                        //pcSpacerCheckHeight();
                                    });
        }
        else
        {
            fasciaCentraleMoveTop();
            //pcSpacerCheckHeight();
        }
    }
}

var g_nLastPositionRequested = 0;
var g_nLastPositionSet = 0;
var FASCIA_CENTALE_TOP_OFFSET = 150;
function fasciaCentraleRequestNewTop(p_nPosition) {
    g_nLastPositionRequested = p_nPosition;
}
function fasciaCentraleMoveTop() {
    var nPrevTop = $('#fascia-centrale').position().top;
    var nNewTop = 375;
    switch(g_nLastPositionRequested)
    {
        case 0:
        nNewTop = 100;
        break;

        default:
        nNewTop = $('#footer-menu').position().top - FASCIA_CENTALE_TOP_OFFSET;
        break;
    }
    g_nLastPositionSet = g_nLastPositionRequested;

    var sEasing = 'easeInOutExpo';
    if (nPrevTop < nNewTop)
        sEasing = 'easeOutBounce';

    if (nNewTop != nPrevTop)
    {
        $('#fascia-centrale').stop(true).animate({top: nNewTop + 'px'},
                                                 1000,
                                                 sEasing,
                                                 function() {
                                                    pcSpacerCheckHeight();
                                                 });

        return;
    }

    pcSpacerCheckHeight();
}
addListener(window, 'load', function() {
    fasciaCentraleMoveTop();
});

function removeSifr(p_sSelector) {
    $(p_sSelector).each(function() {
        if (this.className.indexOf('sIFR-replaced') >= 0)
        {
            var oChildToGetText;
            for (var iCount = 0; iCount < this.childNodes.length; iCount++)
            {
                if (this.childNodes[iCount])
                {
                    if (this.childNodes[iCount].tagName && this.childNodes[iCount].id)
                    {
                        if (this.childNodes[iCount].tagName.toLowerCase() == 'span' && this.childNodes[iCount].id.indexOf('_alternate') >= 0)
                        {
                            oChildToGetText = this.childNodes[iCount];
                            break;
                        }
                    }
                }
            }
            
            if (oChildToGetText != null)
                $this.html(oChildToGetText.innerHTML);

            this.className = this.className.replace('sIFR-replaced', '');
        }
    });
}

function getH1SifrProps(p_sSelector, p_sAddCss, p_nBorderAlpha, p_nShadowAlpha, p_nColor) {
    if (!p_nColor)
        p_nColor = '#ffffff';
    return {
        selector: p_sSelector,
        css: '.sIFR-root { color: #ffffff; ' + p_sAddCss + ' }',
        filters: {
            BevelFilter: {
                distance: -.7,
                angle: 90,
                shadowColor: '#777777',
                shadowAlpha: p_nShadowAlpha,
                blurX: 5,
                blurY: 5,
                strength: 5,
                quality: 3,
                type: 'inner',
                knockout: false
            },
            DropShadow: {
                distance: 0,
                color: '#444444',
                strength: 400,
                alpha: p_nBorderAlpha,
                blurX: 0,
                blurY: 0,
                angle: 0
            }
        },
        transparent: true
    }
}


$(document).ready(function() {
    runSifrPageLoad();
    runSifrAjaxLoad();
    runSifrPanelChanged();
    runSifrVideoPanelChanged();
});

function runSifrAjaxLoad() {
    sIFR.replace(frutigerRoman,
        {
            selector: '.descr-title',
            css: '.sIFR-root { color: #6a6a68; margin: 0px; }',
            filters: {
                BevelFilter: {
                    distance: -.7,
                    angle: 90,
                    shadowColor: '#777777',
                    shadowAlpha: .8,
                    blurX: 5,
                    blurY: 5,
                    strength: 5,
                    quality: 3,
                    type: 'inner',
                    knockout: false
                },
                DropShadow: {
                    distance: 0,
                    color: '#EEEEEE',
                    strength: 200,
                    alpha: 1,
                    blurX: 0,
                    blurY: 0,
                    angle: 0
                }
            },
            transparent: true
        }
    );
    
    sIFR.replace(frutigerRoman,
        {
            selector: '.descr-subtitle',
            css: '.sIFR-root { color: #AAAAAA; }',
            filters: {
                BevelFilter: {
                    distance: -.7,
                    angle: 90,
                    shadowColor: '#777777',
                    shadowAlpha: .8,
                    blurX: 5,
                    blurY: 5,
                    strength: 5,
                    quality: 3,
                    type: 'inner',
                    knockout: false
                },
                DropShadow: {
                    distance: 0,
                    color: '#EEEEEE',
                    strength: 200,
                    alpha: 1,
                    blurX: 0,
                    blurY: 0,
                    angle: 0
                }
            },
            transparent: true
        }
    );
    
    //$('.descr-title').each(function() {
    //    if (this.className.indexOf('sIFR-replaced') >= 0)
    //    {
    //        var nHeight = $(this).height();
    //        $(this).height(nHeight);
    //        var oCurrNode = null;
    //        var oNodeToSetHeight = null;
    //        for (var iCount = 0; iCount < this.parentNode.childNodes.length; iCount++)
    //        {
    //            oCurrNode = this.parentNode.childNodes[iCount];
    //            
    //            if (hasClassName(oCurrNode, 'descr-title-spacer'))
    //            {
    //                oNodeToSetHeight = oCurrNode;
    //            }
    //            else if (hasClassName(oCurrNode, 'descr-subtitle'))
    //            {
    //                nHeight += $(oCurrNode).height();
    //            }
    //        }
    //        if (oNodeToSetHeight != null)
    //            $(oNodeToSetHeight).css('height', (nHeight+10) + 'px');
    //    }
    //});
}
function runSifrPageLoad() {
    sIFR.replace(frutigerRoman, getH1SifrProps('#fascia-centrale-testo-title', 'letter-spacing: 1.2;', .2, .6));
}
function runSifrPanelChanged() {
    removeSifr('#pannello-visual-title');
    sIFR.replace(frutigerRoman, getH1SifrProps('#pannello-visual-title', '', .1, .4));
}
function runSifrVideoPanelChanged() {
    removeSifr('#pannello-video-title');
    sIFR.replace(frutigerRoman, getH1SifrProps('#pannello-video-title', '', .1, .4));
}



// -----------------------------------------------------------
// ALTRE FUNZIONI RICHIESTE DAL CLIENTE
// -----------------------------------------------------------
function clientNavigateTo(p_sPage) {
            location.href = '/client/fe/browser.php?pc=/client/fe/' + p_sPage;
    }

