/*This file created to add site js functions */

$(document).ready(function () {

    // get IE Version
    var IE_clientstring_match = (new RegExp('MSIE [0-9]{1,}[\.0-9]{0,}')).exec(navigator.userAgent);
    var VersionIE = parseInt(IE_clientstring_match ? IE_clientstring_match.toString().substring(5) : '-1');

    $("#btnSearch").attr("src", "../PublishingImages/btn-search-off.png");

    initializeRollovers();

    var randomNum = Math.ceil(Math.random() * 5);
    $("#door").attr("src", "../PublishingImages/door-" + randomNum + ".jpg");

    $("#askLilly").hover(
        function () {
            $("#lillyInfoBox").css('display', 'block');
        },
        function () {
            $("#lillyInfoBox").css('display', 'none');
        });

/***** Popup interstitials *****/

    var myClose = function () {
        $('.jqmWindow').hide();
        $('.jqmOverlay').hide();
        $('#homeVideoContainer').show();
    };
    $('#dialog').jqm({ onHide: myClose });

    //leaving site popup
    $('#leavingSiteProducts').jqm();

    $('.leavingSiteProducts').bind('click', function (event) {
        event.preventDefault();
        $('.btn_ok').attr("href", this.href);
        // $('#btn_ok').attr("target", "_blank");
        $('#leavingSiteProducts').jqmShow();
        $('body').prepend($('#leavingSiteProducts')); //fix IE layer problem
    });

    $('#leavingSiteThirdParty').jqm();

    $('.leavingSiteThirdParty').bind('click', function (event) {
        event.preventDefault();

        $('.btn_ok').attr("href", this.href);
        $('.btn_ok').attr("target", "_blank");
        var url = this.href.replace('http://', '');
        var href= this.href;
       
        $('.btn_ok').unbind("click").click(function() {
        	dcsMultiTrack('DCS.dcssip', url, 'DCS.dcsuri', '/', 'WT.ti', href);
        	parent.$("#leavingSiteProducts").jqmHide();
       		parent.$("#leavingSiteThirdParty").jqmHide();
        });

        $('#leavingSiteThirdParty').jqmShow();
        $('body').prepend($('#leavingSiteThirdParty')); //fix IE layer problem
    });

    $('#leavingSiteHCP').jqm({ modal: true });

    // Check cookie for landing page interstitial
    var visit = readCookie("visit");
    if (visit != null && visit != "") {
        //do nothing
    }
    else {

        $("#leavingSiteHCP").jqmShow();
        $('body').prepend($('#leavingSiteHCP')); //fix IE layer problem
        //createCookie("visit", "Oncology", 365);
    }

    $('.btn_ok_landing').bind('click', function () {
        createCookie("visit", "Oncology", 365);
        parent.$("#leavingSiteHCP").jqmHide();
    });

    $('.btn_cancel_landing').bind('click', function () {
        $("#leavingSiteHCP").jqmHide();
        //window.history.go(-1);

    });
  
    $('.btn_cancel').bind('click', function (event) {
        event.preventDefault();
        $("#leavingSiteProducts").jqmHide();
        $("#leavingSiteThirdParty").jqmHide();
        $("#leavingSiteHCP").jqmHide();
    })

    if (VersionIE > 0 && VersionIE < 7) {
        RefreshPopupTops();
        $(window).scroll(RefreshPopupTops);
    }

/***** common tracking *****/
    $('#tout-listening').click(function () { dcsMultiTrack('DCS.dcssip', 'www.lillyoncologylistens.com', 'DCS.dcsuri', '/', 'WT.ti', 'Tout - Listening'); });
    $('#tout-PatientOne').click(function () { dcsMultiTrack('DCS.dcssip', 'www.LillyOncology.com', 'DCS.dcsuri', '/customTracking/tout/reimbursementPatientOne_Lnav', 'WT.ti', 'Tout - Reimbursement Patient One - LNav'); });
    $('#tout-OncologyOnCanvas').click(function () { dcsMultiTrack('DCS.dcssip', 'www.LillyOncology.com', 'DCS.dcsuri', '/customTracking/tout/lillyOncologyOnCanvas_Lnav', 'WT.ti', 'Tout - Lilly Oncology on Canvas - LNav'); });
    $('#tout-PatientEducationSupport').click(function () { dcsMultiTrack('DCS.dcssip', 'www.LillyOncology.com', 'DCS.dcsuri', '/customTracking/tout/patientEducationSupport_homepage', 'WT.ti', 'Tout - Patient Education and Support - Home Page'); });
});

function initializeRollovers() {
    //preload
    $(window).load(function () {
        $(".rollover").each(function () { $("<img>").attr("src", $(this).attr("src").replace("-off.", "-on.")); });
    });

    $(".rollover").hover(
		function () { $(this).attr("src", $(this).attr("src").replace("-off.", "-on.")); },
		function () { $(this).attr("src", $(this).attr("src").replace("-on.", "-off.")); });
}

function RefreshPopupTops() {
    $('.LeavingSiteHCPPop, .LeavingSiteThirdPartyPop, .LeavingSiteProductsPop')
		.css('top', $(window).scrollTop() + 80 + ' px');
}

function flashPopUp(url) {
    $('.btn_ok').attr("href", url);
    $('.btn_ok').attr("target", "_blank");
    var shorturl = url.replace('http://', '');
    
    $('.btn_ok').unbind("click").click(function() {
    	dcsMultiTrack('DCS.dcssip', shorturl, 'DCS.dcsuri', '/', 'WT.ti', url);
    	parent.$("#leavingSiteProducts").jqmHide();
   		parent.$("#leavingSiteThirdParty").jqmHide();
    });

    $('#leavingSiteThirdParty').jqmShow();
    $('body').prepend($('#leavingSiteThirdParty')); //fix IE layer problem
}

function popPrivacy() {
    dcsMultiTrack('DCS.dcssip', 'www.lillyhub.com', 'DCS.dcsuri', '/legal/hcp/lillyusa/privacy.html', 'WT.ti', 'Privacy Statement');
    popupWin = window.open("http://www.lillyhub.com/legal/hcp/lillyusa/privacy.html", "ViewPop", "status=0,height=590,width=600,scrollbars=1,resizable=yes,toolbar=0")
    return false;
}
function popTerms() {
    dcsMultiTrack('DCS.dcssip', 'www.lillyhub.com', 'DCS.dcsuri', '/legal/hcp/lillyusa/termsofuse.html', 'WT.ti', 'Terms of Use');
    popupWin = window.open("http://www.lillyhub.com/legal/hcp/lillyusa/termsofuse.html", "ViewPop", "status=0,height=590,width=600,scrollbars=1,resizable=yes,toolbar=0")
    return false;
}
function popCopy() {
    dcsMultiTrack('DCS.dcssip', 'www.lillyhub.com', 'DCS.dcsuri', '/legal/hcp/lillyusa/copyright.html', 'WT.ti', 'Copyright');
    popupWin = window.open("http://www.lillyhub.com/legal/hcp/lillyusa/copyright.html", "ViewPop", "status=0,height=590,width=600,scrollbars=1,resizable=yes,toolbar=0")
    return false;
} 

