var presentacionPlayer;

function showPresentation() {
    $("#presentacion-video-fade").fadeIn(750);
    $("#presentacion-activate").fadeOut(750,function(){
        $("#presentacion-video").removeClass("no-show");
        if(presentacionPlayer){
            presentacionPlayer.playVideo();
        }
        $("#presentacion-activate").remove();
        $("#presentacion-video-fade").fadeOut(750,function(){
            $("#presentacion-video-fade").remove();
        });
    });
}

function onYouTubePlayerReady(playerId) {
    presentacionPlayer = document.getElementById("presentacion-player");
}

function scrollNewsList(perc) {
    var lHeight=$("#news-history-list").height();
    var maxScrollY=lHeight-$("#news-history").height();
    var percNormalized=1.00-(perc/100);
    var scrollPosY=Math.round(0-(maxScrollY*percNormalized));
    $("#news-history-list").css({
        top:scrollPosY+'px'
    });
}
function scrollNewsPressList(perc) {
    var lHeight=$("#press-history-list").height();
    var maxScrollY=lHeight-$("#press-history").height();
    var percNormalized=1.00-(perc/100);
    var scrollPosY=Math.round(0-(maxScrollY*percNormalized));
    $("#press-history-list").css({
        top:scrollPosY+'px'
    });
}
function scrollFinoliBioList(perc) {
    var lHeight=$(".show-description").height();
    var maxScrollY=lHeight-$("#finolis-summary").height();
    var percNormalized=1.00-(perc/100);
    var scrollPosY=Math.round(0-(maxScrollY*percNormalized));
    $(".show-description").css({
        top: scrollPosY+'px'
    });
}

var months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];
function getFormattedTime(stamp) {
    var date = Date.parse(stamp.substr(0,19));
    var monthStr = months[date.getMonth()];
    return date.getDate() + ' ' + monthStr.substr(0,3);
}

function finolisShowOtherFinolis(targ) {
    var el=$(targ);
    $("#finolis-list h3").removeClass('active');
    el.addClass('active');
    $('div.finolis:visible').fadeOut(300,function(){
        $('div.finolis#finolis-'+el.attr('id')).fadeIn(300);
    });
}

function newsShow(targ) {
    var el=$(targ);
    var activeId = $("#news-menu-items span.active").attr('id')
    $("#news-menu-items span.active").removeClass('active');
    el.addClass('active');
    $('div#'+activeId+'-history').fadeOut(300,function(){
        $('div#'+el.attr('id')+'-history').fadeIn(300);
    });
}

function finolisShowSummary() {
    $("#finolis-list .active-bio").removeClass("active-bio");
    $("#finolis-summary .finoli-bio").fadeOut(300,function(){
        $("#finolis-summary .show-description").fadeIn(300);
        $("#finoli-bio-scroll").fadeIn(300);
    });
}
function finolisShowFinoliBio(targ) {
    var el=$(targ);
    var desc = false;
    //set currently active item if set
    var activeEl=$("#finolis-list .active-bio");
    //fade in
    if(activeEl.length>0){
        activeEl=$("#finolis-summary .finoli-bio");
    }else{
        activeEl=$("#finolis-summary .show-description");
        desc = true;
    }
    if(desc)$("#finoli-bio-scroll").fadeOut(300);
    activeEl.fadeOut(300,function(){
        //set new content
        $("#finolis-summary .finoli-bio h3 span").html(el.children('h4').html());
        $("#finolis-summary .finoli-bio p").html(el.children('p').html());
        //unset old active item
        $("#finolis-list .active-bio").removeClass("active-bio");
        //set new active item
        el.addClass('active-bio');
        //fade in
        $("#finolis-summary .finoli-bio").fadeIn(300);
    });
}

function scrollWorldTourList(perc) {
    var lHeight=$("#world-tour-scroll-content table").height();
    var maxScrollY=lHeight-$("#world-tour-scroll-content").height();
    var percNormalized=1.00-(perc/100);
    var scrollPosY=Math.round(0-(maxScrollY*percNormalized));
    $("#world-tour-scroll-content table").css({
        top:scrollPosY+'px'
    });
}
