﻿
var flag = 0;
function animatedvideo() {

    var backgroundheight = 410;

    var offset;

    offset = 409;
    function scrollbackground() {

        if (offset < 753) {

            offset = (offset < 1) ? offset + (backgroundheight + 1) : offset + 1;

            $('#bedroom-scene-img').css("background-position", "50% " + offset + "px");

            setTimeout(function() {
                scrollbackground();
              
            }, 3
		);
        }

        else {
            flag = 1;
            if (isPopupOpen == false) {
                document.getElementById('baloon-ani').style.display = 'block';
            }
        }
       
    }

    // Start the animation
    scrollbackground();
  
}


var rotatorSlides = "ul#left-callout > li"
var rotatorTabs = "ul#homepage-rotator-tabs > li"

//variables for animated rotation

var intervalID;
var intervalLength = 8000; // 8 seconds
var slideIndex = 0;
var maxSlideIndex = 2;
var newsCount = 1;
var previousRadioButton = "#tab-button-1>img";


$(window).load(function() {
    var t = window.setTimeout("animatedvideo()",1500);
    InitializeRotator();

});


function showTab() {
    showPopup();

}

function InitializeRotator() {
    InitializeRotatorTabs();
    intervalID = setInterval("RotateTab()", intervalLength);
}

function InitializeRotatorTabs() {
    $(rotatorTabs).hover(
        function() {
            $(this).toggleClass("hover");
        }
    );
    $(rotatorTabs).click(function() {
        clearInterval(intervalID);
        SwitchTab(this);
    });
}

$("img#right-arrow").click(function() {

if (newsCount == 9)
{ newsCount = 0; }
newsCount++;
    document.getElementById('news-rotator').innerHTML = document.getElementById('news-rotator-' + newsCount).innerHTML;
    var divNewsShow = "#news-rotator";
    $(divNewsShow).show();
});

$("img#left-arrow").click(function() {
    if (newsCount == 1)
    { newsCount = 10; }
    newsCount--;
    document.getElementById('news-rotator').innerHTML = document.getElementById('news-rotator-' + newsCount).innerHTML;
    var divNewsShow = "#news-rotator";
    $(divNewsShow).show();
});

$("#find-store").click(function() {
    
    showPopup();

});



$("img#animation-baloon").click(function() {
showPopup();
});



function RotateTab() {
    var tab = $(rotatorTabs).eq(slideIndex);
    SwitchTab(tab);

    if (slideIndex < maxSlideIndex) {
        slideIndex++;
    }
    else {
        slideIndex = 0;
    }
}


function SwitchTab(tab) {
    $(previousRadioButton).attr("src", "/static/img/flu-homepage/unselected-radio.png");
    var id = $(tab).attr("id");
    var currRadioButton = "#" + id + ">img";
    previousRadioButton = currRadioButton;
    id = "#" + id.replace(/tab/gi, 'slide');
    $(rotatorTabs).removeClass("active");
    $(tab).addClass("active");
    var nextActiveButton = "ul#homepage-rotator-tabs > li img.active";
    $(currRadioButton).attr("src", "/static/img/flu-homepage/selected-radio.png");
    SwitchRotatorSlide(id);
}

function SwitchRotatorSlide(id) {
    $(rotatorSlides).removeClass("active");
    $(id).addClass("active");
}

var isPopupOpen = false;
/* Show Hide Popup*/
function showPopup() {

    isPopupOpen = true;

    $("#find-store-tab1").hide();
    $("#find-a-store1").hide();
    $("#LocatorDiv").show();
    document.getElementById('baloon-ani').style.display = 'none';
   
}
function HidePopup() {


//refresh locater popup drop down
    document.getElementById('locator-age-select').getElementsByTagName('option').item(1).selected = "selected"; ;
    document.getElementById('locator-flavor-select').getElementsByTagName('option').item(0).selected = "selected"; ;
    var txtBoxPin = document.getElementById('locator-zip-field');
    txtBoxPin.value = "";

//hide popup show tab
    $("#find-store-tab1").show();
    $("#find-a-store1").show();
    $("#LocatorDiv").hide();

    if (flag == 1) {

        document.getElementById('baloon-ani').style.display = 'block';
       
    }
}
