﻿
var toolTipContainerOffsetLeft = 77; /* Adjust this to move it left/right :: the higher the number more to the left the tool tip container will move */
var toolTipContainerOffsetTop = 10; /* Adjust this to move it up/down :: the higher the number more upward the tool tip container will move */

var pathname = window.location.pathname;
//This checks for either the Default.aspx page, or a root folder "/" by checking for
//The absence of ".aspx".  This will set a flag to hide/show the footer link titled "Millennium.com"
var homeFlag = ((pathname.indexOf("Default.aspx") > 0) || (pathname.indexOf(".aspx") == -1)) ? true : false;


//ready function
$(document).ready(function () {

    /*********************************************************************
    HCP Interstitial Validation - Global
    *********************************************************************/
    // For testing remove comment from below.
    //$.cookie('CymbaltaHCPPopup', null);

    if (!$.cookie('CymbaltaHCPPopup')) {

        $("<div>").attr({ 'id': 'HCPmodalBackground' })
        .css({ 'opacity': '0.7', 'display': 'block' })
        .insertAfter("#container").hide().fadeIn(1000);

        //load interstitial popup
        var HCPinterstitialModal = new ModalPopup(
            {
                dynamic: false,
                popupSelector: "#HCPinterstitialModal",
                triggerSelector: "#HCPmodalTrigger",
                opacity: ".7",
                closeSelector: ".HCPcloseModal"
            });

        $('#HCPinterstitialModal').remove().insertBefore("#container");

        $(".HCPmodalContinueBtn").click(function (event) {
            event.preventDefault();
            // If user accepts set the cookie and continue 
            $.cookie("CymbaltaHCPPopup", 'true', { expires: 365 });
            $(".HCPmodalBox, #HCPmodalBackground").fadeOut(1000, function () {
                $(this).remove();
            });

        });

        $(".HCPmodalCancelBtn").click(function (event) {
            window.location = "http://www.cymbalta.com";
        });

        $("#HCPmodalTrigger").click();

    }

    /*********************************************************************
    Image Rotator - Home Page
    *********************************************************************/


    //Get size of the image, how many images there are, then determin the size of the image reel.
    var imageWidth = $(".calloutWindow").width();
    var imageSum = $(".calloutImages img").length;
    var imageReelWidth = imageWidth * imageSum;
    var totalWidth = 0;
    $(".calloutImages img").each(function () {
        totalWidth += $(this).width();
    });


    //Adjust the image reel to its new size
    $(".calloutImages").css({ 'width': '1044px' });

    //calloutNav  and Slider Function
    rotate = function () {
        var triggerID = $active.attr("rel") - 1; //Get number of times to slide
        if(isNaN(triggerID)){
        	triggerID = 0;
        }
        var calloutImagesPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

        $(".calloutNav a").removeClass('active'); //Remove all active class
        $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

        var currentUrl = $('.active').attr('href');
        $('.calloutArrow a').attr('href', currentUrl);

        if (triggerID == 0) {
            $('.calloutArrow a').addClass('leavingSitePreg');

            //load Preg interstitial popup
            var interstitialModalPreg = new ModalPopup(
            {
                dynamic: false,
                popupSelector: "#interstitialModalPreg",
                triggerSelector: ".leavingSitePreg",
                opacity: ".7",
                closeSelector: ".closeModal, #modalBackground, .modalCancelBtn"
            });

        } else {
			delete interstitialModalPreg;        
		    $('.calloutArrow a').removeClass('leavingSitePreg').unbind();        
        }
        
        //Slider Animation
        $(".calloutImages").stop(true, false).animate({
            left: -calloutImagesPosition,
            queue: false
        }, 5000);

    };

    //Rotation  and Timing Event
    rotateSwitch = function () {
        play = setInterval(function () { //Set timer - this will repeat itself every 7 seconds
            $active = $('.calloutNav a.active').next(); //Move to the next calloutNav
            if ($active.length === 0) { //If calloutNav reaches the end...
                $active = $('.calloutNav a:first'); //go back to first
            }
            rotate(); //Trigger the calloutNav and slider function
        }, 5000); //Timer speed in milliseconds (7 seconds)
    };

    rotateSwitch(); //Run function on launch

    //On Hover
    $(".calloutImages a").hover(function () {
        clearInterval(play); //Stop the rotation
    }, function () {
        rotateSwitch(); //Resume rotation timer
    });

    //On Click
    $(".calloutNav a").click(function () {
        $active = $(this); //Activate the clicked calloutNav
        //Reset Timer
        clearInterval(play); //Stop the rotation
        rotate(); //Trigger rotation immediately
        rotateSwitch(); // Resume rotation timer
        return false; //Prevent browser jump to link anchor
    });


    $(".calloutNav a").removeClass('active');
    //Show the calloutNav and activate its first link    
    $(".calloutNav a:first").addClass("active");
    $(".calloutNav").show();
    $(".calloutNav a:first").click();
    //Load Plugins	

    //load interstitial popup
    var interstitialModal = new ModalPopup(
            {
                dynamic: false,
                popupSelector: "#interstitialModal",
                triggerSelector: ".leavingSite",
                opacity: ".7",
                closeSelector: ".closeModal, #modalBackground, .modalCancelBtn"
            });

    //load Preg interstitial popup
    var interstitialModalPreg = new ModalPopup(
            {
                dynamic: false,
                popupSelector: "#interstitialModalPreg",
                triggerSelector: ".leavingSitePreg",
                opacity: ".7",
                closeSelector: ".closeModal, #modalBackground, .modalCancelBtn"
            });

    $('.modalBox').hide();
    $('#modalBackground').remove();
    $('#interstitialModal, #interstitialModalPreg').remove().appendTo('body');


    /*********************************************************************
    Mechanism of Action Modal
    ***********************************************************************/
    var mechanismModal = new ModalPopup(
            {
                dynamic: false,
                popupSelector: "#mechanismAction",
                triggerSelector: ".mechanismOfAction",
                opacity: ".7",
                closeSelector: ".closeModal, #modalBackground, .modalCancelBtn"
            });

    $('.modalBox').hide();
    $('#modalBackground').remove();
    $('#mechanismAction').remove().appendTo('body');

   

    $('.closeBtnFlash, .modalContinueBtn, .internPregLink').live('click', function () {
        closePopupModal();
    });

    //On click of link, pull interstitial information
    $('.leavingSite').click(function () {
        var exitURL = $(this).attr('href');
        $('#modalAction span').html('<a href="' + exitURL + '" target="_blank" class="modalContinueBtn">Continue</a>');
    });

    //On click of link, pull interstitial information
    $('.leavingSitePreg').click(function () {
        var exitURL = $(this).attr('href');
        $('#modalActionPreg span').html('<a href="' + exitURL + '" target="_blank" class="modalContinueBtn">Continue</a>');
    });

    /******************/
    /* Set Navigation */
    /******************/

    selectNavPrimaryActive('topNav');

    var options = {};
    options.navSecondaryContainer = "subNavigation"; 		//Default ID, if not set = "Left"
    options.navSecondary = "subNav"; 					//Default ID, if not set = "leftNav"
    options.navSecondaryOnClass = ""; 			//Default Class, if not set = "active"
    options.navSecondaryLevelClassPrefix = ""; //Default Class, if not set = "level"
    options.isMasterMenu; 						//Default is true

    selectNavSecondaryActive(options);

    /******************/
    /* askLilly Rollover Navigation */
    /******************/

    /* $(".askLilly").hover(function () {
        $("#askLillyRollover").css({
            top: $(this).position().top + $(this).height(),
            left: $(this).position().left - 100
        }).show();
    }, function () {
        $("#askLillyRollover").hide();
    });
    */
});


function closePopupModal() {
    $('.modalBox').hide();
    $('#modalBackground').remove();
    $('#presentationVideos1').remove();


   
}


/*****************************************************
Ask Lilly Utility Nav
*****************************************************/

function askLillyClick() {
    window.open("http://www.asklilly.com/?www.insidecymbalta.com", "ask_lilly_medical", "location=0,menubar=0,status=0,toolbar=0,width=700,scrollbars=1,resizeable=0");
}
