Cufon.set('selector', jQuery);
Cufon.replace('h1');
Cufon.replace('h3');

var isPlaying = false;

function callToActionscript(flash) {
    getFlashMovie(flash).sendToActionscript();
}

function callToActionscript2(flash) {
    getFlashMovie(flash).sendToActionscript2();
}

function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? document.forms["aspnetForm"][movieName] : document[movieName];
}

function playerStatus(tOrF) {
    isPlaying = tOrF;
}

$(document).ready(function () {
    $("#tooglePat").mouseenter(function () {
        if (isPlaying) {
            callToActionscript("moa2");
        }

        $("#hcp-wrapper").stop(true, true);
        $("#patients-wrapper").stop(true, true);

        if ($("#hcp-wrapper").css("top") == "0px") {
            $("#hcp-wrapper").stop(true, true).animate({ top: '323px' }, "slow", function () {
                $("#toggleHcp").css("display", "inline");
                $("#hcp-wrapper").css("top", "424px");
                $("#tooglePat").css("display", "none");
                $("#patients-wrapper").stop(true, true).css("top", "323px").animate({ top: '0px' }, "slow");
            });
        }
        else {
            $("#tooglePat").css("display", "none");
            $("#patients-wrapper").stop(true, true).css("top", "323px").animate({ top: '0px' }, "slow");
        }
    });

    $("#toggleHcp").mouseenter(function () {
        if (isPlaying) {
            callToActionscript("moa");
        }

        $("#hcp-wrapper").stop(true, true);
        $("#patients-wrapper").stop(true, true);

        if ($("#patients-wrapper").css("top") == "0px") {
            $("#patients-wrapper").stop(true, true).animate({ top: '323px' }, "slow", function () {
                $("#tooglePat").css("display", "inline");
                $("#patients-wrapper").css("top", "424px");
                $("#toggleHcp").css("display", "none");
                $("#hcp-wrapper").stop(true, true).css("top", "323px").animate({ top: '0px' }, "slow");
            });
        }
        else {
            $("#toggleHcp").css("display", "none");
            $("#hcp-wrapper").stop(true, true).css("top", "323px").animate({ top: '0px' }, "slow");
        }
    });

    $("#patients-wrapper").mouseleave(function () {
        if (!isPlaying) {
            $("#patients-wrapper").stop(true, true).animate({ top: '323px' }, "slow", function () {
                $("#tooglePat").css("display", "inline");
                $("#patients-wrapper").css("top", "424px");
            });
        }
    });

    $("#hcp-wrapper").mouseleave(function () {
        if (!isPlaying) {
            $("#hcp-wrapper").stop(true, true).animate({ top: '323px' }, "slow", function () {
                $("#toggleHcp").css("display", "inline");
                $("#hcp-wrapper").css("top", "424px");
            });
        }
    });
});

$(document).ready(function () { $('a[rel*=facebox]').facebox(); })

function checkSubmit(e)
{
    if (e && e.keyCode == 13) {
        submitZipSearch();
        return false;
    }
}

function checkSubmitHCP(e) {
    if (e && e.keyCode == 13) {
        submitZipSearchHCP();
        return false;
    }
}

function submitZipSearch() {
    window.location.href = "provider-locator-results.aspx?zip=" + $("#zipCode").val();
}

function submitZipSearchHCP() {
    window.location.href = "find-a-provenge-provider-results.aspx?zip=" + $("#zipCode").val();
}

function submitZipSearchTriageCons() {
    window.location.href = "provider-locator-results.aspx?zip=" + $("#conzip").val();
}

function submitZipSearchTriageHCP() {
    window.location.href = "/hcp/find-a-provenge-provider-results.aspx?zip=" + $("#hcpzip").val();
}

function showToolTip(e, id) {
    if (document.all) e = event;

    var obj = document.getElementById(id);
    var st = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
    if (navigator.userAgent.toLowerCase().indexOf('safari') >= 0) st = 0;
    var leftPos = e.clientX - 700;
    if (leftPos < 0) leftPos = 0;
    obj.style.left = 5 + 'px';
    obj.style.top = 20 + 'px';
    document.getElementById(id).style.display = 'block';
}

function hideToolTip(id) {
    document.getElementById(id).style.display = 'none';
}

/*Text Resize function added here*/


function changeTextSize(size) {
    switch (size) {
        case 2:
            $("#content").css("font-size", "14px");
            $("#content-hcp").css("font-size", "14px");
            $(".big-bold").css("font-size", "16px");
            $("h2").css("font-size", "18px");
            createCookie("textSize", "2", 1);
            $("#larger-text").css("color", "#d6ccbe");
            $("#normal-text").css("color", "");
            $("#smaller-text").css("color", "");
            break;

        case 1:
            $("#content").css("font-size", "13px");
            $("#content-hcp").css("font-size", "13px");
            $(".big-bold").css("font-size", "15px");
            $("h2").css("font-size", "16px");
            createCookie("textSize", "1", 1);
            $("#larger-text").css("color", "");
            $("#normal-text").css("color", "#d6ccbe");
            $("#smaller-text").css("color", "");
            break;

        case 0:
            $("#content").css("font-size", "11px");
            $("#content-hcp").css("font-size", "11px");
            $(".big-bold").css("font-size", "12px");
            $("h2").css("font-size", "14px");
            createCookie("textSize", "0", 1);
            $("#larger-text").css("color", "");
            $("#normal-text").css("color", "");
            $("#smaller-text").css("color", "#d6ccbe");
            break;
    }
}

window.onload = function () {
    switch (readCookie("textSize")) {
        case "2":
            $("#content").css("font-size", "14px");
            $("#content-hcp").css("font-size", "14px");
            $(".big-bold").css("font-size", "16px");
            $("h2").css("font-size", "18px");
            $("#larger-text").css("color", "#d6ccbe");
            $("#normal-text").css("color", "");
            $("#smaller-text").css("color", "");
            break;

        case "1":
            $("#content").css("font-size", "13px");
            $("#content-hcp").css("font-size", "13px");
            $(".big-bold").css("font-size", "15px");
            $("h2").css("font-size", "16px");
            $("#larger-text").css("color", "");
            $("#normal-text").css("color", "#d6ccbe");
            $("#smaller-text").css("color", "");
            break;

        case "0":
            $("#content").css("font-size", "11px");
            $("#content-hcp").css("font-size", "11px");
            $(".big-bold").css("font-size", "12px");
            $("h2").css("font-size", "14px");
            $("#larger-text").css("color", "");
            $("#normal-text").css("color", "");
            $("#smaller-text").css("color", "#d6ccbe");
            break;

        default:
            $("#larger-text").css("color", "");
            $("#normal-text").css("color", "#d6ccbe");
            $("#smaller-text").css("color", "");
            break;
    }
};
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
/*Toggle Function for utility navigation*/
$(document).ready(function () {
    $("#hide_utlity_links").hide();
    $(".explore-btn").click(function () {
        $("#hide_utlity_links").slideToggle("fast");
        $(this).toggleClass("explore-btn_expand");
    });

    if (readCookie("hasSeenCallouts")) {
    }
    else if (window.location.href.indexOf('default.aspx') < 0 && window.location.href != 'http://www.provenge.com/') {
        if (window.location.href != 'http://www.provenge.com/hcp/') {
            $(".explore-btn").click();
            createCookie("hasSeenCallouts", 1, 1);
            setTimeout(function () {
                if ($("#hide_utlity_links").css('display') == "block") {
                    $(".explore-btn").click();
                }
            }, 5000);
        }
    }

    rankingsPush();
});


/*Clearing the Text of the text box*/
function clearText(field) {
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}

function download(filePath, fileName) {
    fileName = fileName.replace(".jpg", "");
    fileName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length);

    window.open("/download.aspx?url=" + filePath + "&fn=" + fileName + ".jpg");
}

function swapTab(tab) {
    switch (tab) {
        case "#tab1":
            $('#tab1').show();
            $('#tab1-link').addClass("selected");
            $('#tab2').hide();
            $('#tab2-link').removeClass("selected");
            $('#tab3').hide();
            $('#tab3-link').removeClass("selected");
            $('#tabs').css("background", "url(/images/tabs_selected_top.gif) no-repeat");

            break;

        case "#tab2":
            $('#tab1').hide();
            $('#tab1-link').removeClass("selected");
            $('#tab2').show();
            $('#tab2-link').addClass("selected");
            $('#tab3').hide();
            $('#tab3-link').removeClass("selected");
            $('#tabs').css("background", "url(/images/tabs_selected_top2.gif) no-repeat");
            break;

        case "#tab3":
            $('#tab1').hide();
            $('#tab1-link').removeClass("selected");
            $('#tab2').hide();
            $('#tab2-link').removeClass("selected");
            $('#tab3').show();
            $('#tab3-link').addClass("selected");
            $('#tabs').css("background", "url(/images/tabs_selected_top3.gif) no-repeat");
            break;
    }
}

function editFacebox() {
    $("td.body").css("background", "#ffffff url(images/reimbursementTop.jpg) no-repeat");
    $("td.body").css("background-position", "left top");
    $("img.close_image").attr("src","images/closeX.gif");
}

function showHideAnswer(answer) {
    if ($('#' + answer).css("display")) {
        if ($('#' + answer).css("display") == "block") {
            $('#' + answer).hide();
            $('#' + answer + "-plusMinus").html("+");
        }
        else {
            $('#' + answer).show();
            $('#' + answer + "-plusMinus").html("-");
            _gaq.push(['_trackEvent', 'Links', 'FAQ Expand', answer]);
        }
    }
    else {
        $('#' + answer).show();
        $('#' + answer + "-plusMinus").html("-");
        _gaq.push(['_trackEvent', 'Links', 'FAQ Expand', answer]);
    }
}

function rankingsPush() {
    var url = String(document.referrer);

    // confirm they came from G
    if (url.indexOf("google.com") != -1) {

        var urlVars = {};
        var parts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
            urlVars[key] = value;
        });

        // Push to GA Custom Variables
        _gaq.push(['_setCustomVar', '1', 'Rankings', urlVars["cd"], 1]);

    }

}
