
// looping config vars
var _totalLoops     = 0;
var _endFrameDelay  = 4;

// content
var container       = getById("container");
var loadingContent  = getById("loading_content");

// copy
var copy01          = getById("copy_01");
var copy02          = getById("copy_02");
var cta             = getById("cta");

// images
var img01           = getById("img_01");

// exit
var exitBtn         = getById("exit_btn");
var _exitURL        = "https://www.hogarth.com";



// Create and provide timeline to Hoxton
var Creative = {

    tl: gsap.timeline({defaults: {ease:"none"}}),


    setExitURL: function( strURL )
    {
        _exitURL = strURL;
    },

    onExit: function( e ) 
    {
        hoxton.exit( "Exit" , _exitURL );
    },

    onBannerStart: function() 
    {
        console.log("Creative.onBannerStart()");
    },

    onBannerComplete: function() 
    {
        console.log("Creative.onBannerComplete()");
    },

    jumpToEndFrame: function() 
    {
        Creative.tl.pause();
        Creative.tl.seek( "end", false);
    },

    checkIsBackup: function() 
    {
        return ( window.location.href.indexOf( 'hoxtonBackup' ) >= 0 ) ? true : false;
    },

    startAd: function() 
    {
        Creative.createButtons();
        Creative.displayBanner();
        Creative.setUpTimeline();

        Creative.init();
        Creative.checkIsBackup() ? Creative.jumpToEndFrame() : null;
    },

    createButtons: function()
    {
        exitBtn.addEventListener("click", Creative.onExit, false);
    },

    setUpTimeline: function()
    {
        Creative.tl.repeat(_totalLoops);
        Creative.tl.repeatDelay(_endFrameDelay);
        Creative.tl.eventCallback("onStart", Creative.onBannerStart);
        Creative.tl.eventCallback("onComplete", Creative.onBannerComplete);
    },

    displayBanner: function()
    {
        loadingContent.style.display = "none";
        container.style.display = "block";
    },

    init: function() 
    {
        Creative.tl.to([copy01], {duration:1, alpha:1}, "0")

                .to([copy01], {duration:0.5, alpha:0}, ">2")
                .to([copy02], {duration:1, alpha:1}, ">")
                .to([cta], {duration:1, alpha:1}, ">")
                .addLabel("end", ">");
    }
};


function getById(eleID) 
{
    return document.getElementById(eleID);
}
