(function ($)
{ 
    /***********************************************************************
    Tab Callout Rollover :: Function
    ***********************************************************************/
    $(".callout").hover(function () {

        if ($.browser.mozilla) {
            $(this).animate({ backgroundPosition: "+=5" }, { duration: 100 });
        } else {
            $(this).animate({ backgroundPositionX: "+=5" }, { duration: 100 });
        }

    }, function () {

        if ($.browser.mozilla) {
            $(this).animate({ backgroundPosition: "-=5" }, { duration: 100 });
        } else {
            $(this).animate({ backgroundPositionX: "-=5" }, { duration: 100 });
        }

    });

    var x = 0;

    $("#callOutContainer div").each(function () {
        x++;
        switch (x) {

            case 1:
                $(this).addClass("first");
                break;
            case 2:
                $(this).addClass("second");
                break;
            case 3:
                $(this).addClass("third");
                break;
        }
    });

    /***********************************************************************
    Flash HP Journal Removal :: Function
    ***********************************************************************/
    $.fn.exists = function () { return $(this).length > 0; }

    if ($("#introflash").exists()) {
        $("#introflash").hide();
    }

    if ($("#homepageflash").exists()) {
        setTimeout(removeFlashIntro, 6000);
        setTimeout(function () { $("#mainContainer").removeClass("hideElement"); }, 2000);
    }

    /***********************************************************************
    No Flash Post onclick :: Function
    ***********************************************************************/

    // Close Post on
    $("#postClose").click(function (e) {
        e.preventDefault();
        $("#postOn").fadeOut(1000, function () {
            $(this).attr({ "class": "" });
        });
    });

    $("#postHaveYou, #postDoTheChanges, #postHaveYourFam, #postDoYou").click(function (e) {
        e.preventDefault();
        var that = $(this);
        var newBG = $(this).attr("id") + "_On";

        $("#postOn").css({
            "top": $(this).parent().position().top,
            "left": $(this).parent().position().left + 22
        });
        $("#postOn").fadeIn(1000).addClass(newBG);
        $("#postNav").attr("href", that.attr("href"));
    });

    /***********************************************************************
    Isi Toggle :: Function
    ***********************************************************************/

    var windowHeight = $(window).height();
    var visibleHeight = Math.floor(windowHeight / 4) - $("#isiHeaderBar").outerHeight();

    // Expanded Height - 3/4 document
    expandHeight = Math.floor(visibleHeight * 4);

    adjustWindowHeightForISI();

    $(window).resize(function () {
        adjustWindowHeightForISI();
    });

    $('#isiContentContainer').height(visibleHeight);

    /********* Footer ISI Toggle *********/

    $('a#isiToggle, a.isiTrigger').click(function () {

        var windowHeight = $(window).height();
        var visibleHeight = Math.floor(windowHeight / 4) - $("#isiHeaderBar").outerHeight();

        // Expanded Height - 3/4 document
        expandHeight = Math.floor(visibleHeight * 4);

        if ($('#isiContentContainer').height() == visibleHeight) {

            $('#isiContentContainer').stop().animate(
            {
                height: expandHeight
            }, {
                easing: 'easeOutCubic',
                duration: 1000
            });

            $('a#isiToggle img').attr('src', '/Images/Common/btnCollapse.gif');
        }
        else {

            $('#isiContentContainer').stop().animate(
            {
                height: visibleHeight
            }, {
                easing: 'easeOutCubic',
                duration: 800
            });

            $('a#isiToggle img').attr('src', '/Images/Common/btnExpand.gif');
        }

        return false;
    });

    $('.openISI').click(function () {
        $('#isiToggle').click();
    });

    /********* Scroll to location *********/
    $('.scrollToLocation, .scrollToLocationBackToTop').click(function (e) {
        var getHref = $(this).attr('href');
        var correctAnchor = getHref.replace(/#/, '');

        processScrollTo(correctAnchor);

        return false;
    });

    /***********************************************************************
    Nav Hover YELLOW :: Function
    ***********************************************************************/

    $(".subNav ul li a").each(function () {

        // Check li's to see if this page is active
        if (checkNavHighlight($(this).attr("href"))) {
            $(this).parent().parent().show();
            $(this).parent().addClass("bulletOn");
            $(this).parent().parent().parent().removeClass("navOnBull").addClass("navOn");
        }
    });


    /* Check subNav */

    $("#topNav a").hover(function () {

        if (checkNavHighlight($(this).attr("href"))) {
            // Do not toggle
        } else {
            $(this).parent().toggleClass("navOn");
        }

    }, function () {
        if (checkNavHighlight($(this).attr("href"))) {
            // Do not toggle
        } else {
            $(this).parent().toggleClass("navOn");
        }
    });

    $(".topNav").each(function () {

        // Check li's to see if this page is active
        if (checkNavHighlight($(this).attr("href"))) {
            $(this).parent().addClass("navOnBull");

            if ($(this).parent().children().size() != 0) {
                $(this).parent().children("ul").slideDown();
            }
        }

        if ($(this).parent().hasClass("navOnBull") == true || $(this).parent().hasClass("navOn") == true) {

        } else {

            if ($.browser.mozilla) {
                $(this).parent().hover(function () {
                    $(this).css(
            {
                background: "url(/Images/common/navOnSwash.png) no-repeat scroll -195px -3px transparent",
                backgroundPosition: "-195px"
            }
            ).stop(false, false).animate({ backgroundPosition: "0px" }, { duration: 150 });
                }, function () {
                    $(this).stop().animate({ backgroundPosition: "-195px" }, { duration: 150 });
                });
            } else {
                $(this).parent().hover(function () {
                    $(this).css(
            {
                background: "url(/Images/common/navOnSwash.png) no-repeat scroll -195px -3px transparent",
                backgroundPositionX: "-195px",
                backgroundPositionY: "-3px"
            }
            ).animate({ backgroundPositionX: "0px" }, { duration: 150 });
                }, function () {
                    $(this).animate({ backgroundPositionX: "-195px" }, { duration: 150 });
                });
            }

        }

    });

    $("#navContainer ul ul li").hover(function () {

        if (checkNavHighlight($("a", this).attr("href"))) {
            // Do not toggle
        } else {
            $(this).toggleClass("bulletOn");
        }
    },
    function () {
        if (checkNavHighlight($("a", this).attr("href"))) {
            // Do not toggle
        } else {
            $(this).toggleClass("bulletOn");
        }
    });


    /***********************************************************************
    Nav Hover GREEN:: Function
    ***********************************************************************/

    $(".subNavGreen ul li a").each(function () {

        // Check li's to see if this page is active
        if (checkNavHighlight($(this).attr("href"))) {
            $(this).parent().parent().show();
            $(this).parent().addClass("bulletOnGreen");
            $(this).parent().parent().parent().removeClass("navOnBullGreen").addClass("navOnGreen");
        }
    });


    /* Check subNav */

    $("#topNav li.subNavGreen a").hover(function () {

        if (checkNavHighlight($(this).attr("href"))) {
            // Do not toggle
        } else {
            $(this).parent().toggleClass("navOnGreen");
        }

    }, function () {
        if (checkNavHighlight($(this).attr("href"))) {
            // Do not toggle
        } else {
            $(this).parent().toggleClass("navOnGreen");
        }
    });

    $(".topNavGreen").each(function () {

        // Check li's to see if this page is active
        if (checkNavHighlight($(this).attr("href"))) {
            $(this).parent().addClass("navOnBullGreen");

            if ($(this).parent().children().size() != 0) {
                $(this).parent().children("ul").slideDown();
            }
        }

        if ($(this).parent().hasClass("navOnBullGreen") == true || $(this).parent().hasClass("navOnGreen") == true) {

        } else {

            if ($.browser.mozilla) {
                $(this).parent().hover(function () {
                    $(this).css(
            {
                background: "url(/Images/common/navOnSwashGreen.png) no-repeat scroll -195px -3px transparent",
                backgroundPosition: "-195px"
            }
            ).stop(false, false).animate({ backgroundPosition: "0px" }, { duration: 150 });
                }, function () {
                    $(this).stop().animate({ backgroundPosition: "-195px" }, { duration: 150 });
                });
            } else {
                $(this).parent().hover(function () {
                    $(this).css(
            {
                background: "url(/Images/common/navOnSwashGreen.png) no-repeat scroll -195px -3px transparent",
                backgroundPositionX: "-195px",
                backgroundPositionY: "-3px"
            }
            ).animate({ backgroundPositionX: "0px" }, { duration: 150 });
                }, function () {
                    $(this).animate({ backgroundPositionX: "-195px" }, { duration: 150 });
                });
            }

        }

    });

    $("#navContainer ul li.subNavGreen ul li").hover(function () {

        if (checkNavHighlight($("a", this).attr("href"))) {
            // Do not toggle
        } else {
            $(this).toggleClass("bulletOnGreen");
        }
    },
    function () {
        if (checkNavHighlight($("a", this).attr("href"))) {
            // Do not toggle
        } else {
            $(this).toggleClass("bulletOnGreen");
        }
    });


    /***********************************************************************
    Glossary Term :: Function
    ***********************************************************************/

    /* Create a namespace */
    var glossaryTipz = {};

    glossaryTipz.enableGlossary = function () {

        $("a.glossaryTrigger").each(function () {

            var triggers = $(this).text().replace(/ /g, '-');

            if ($.browser.mozilla) {

                $(this).css(
                {
                    backgroundImage: "url(/Images/GlossaryUnderlines/" + triggers + ".png)",
                    backgroundPosition: "0px 17px",
                    backgroundRepeat: "no-repeat"
                });
            } else {

                $(this).css(
                {
                    backgroundImage: "url(/Images/GlossaryUnderlines/" + triggers + ".png)",
                    backgroundPositionX: "0px",
                    backgroundPositionY: "17px",
                    backgroundRepeat: "no-repeat"
                });
            }
        });


        var hoverDelay;

        $("a.glossaryTrigger").hover(function () {

            var triggers = $(this).text().replace(/ /g, '-');
            var pos = $(this).offset();
            var linkWidth = $(this).width();
            var left = pos.left + linkWidth - 127;
            var posLeft = pos.left - 30;
            var top = pos.top + 14;

            if (left < 0) {
                top = top + 12; //explorer needs 15 added to top.
            }

            $(".jqmAlert").css({
                position: "absolute",
                marginLeft: 0,
                marginTop: 0,
                left: left,
                top: top
            });

            var jqmAlertContent = ("/glossary/" + triggers + ".htm");

            hoverDelay = setTimeout(function () {

                $("#glossaryModal").jqm({
                    trigger: triggers,
                    ajax: jqmAlertContent,
                    target: 'div.jqmAlertContent div.contentbox',
                    overlay: 0
                }).jqmShow().hide().slideDown();

            }, 800);

            return false;

        }, function () {

            clearTimeout(hoverDelay);

            var triggers = "";
            var ele = "";
            var pos = "";
            var linkWidth = "";
            var left = "";
            var posLeft = "";
            var top = "";

            var jqmAlertContent = ("");

            $("#glossaryModal").jqm({
                trigger: triggers,
                ajax: jqmAlertContent,
                target: 'div.jqmAlertContent div.contentbox',
                overlay: 0
            });

            return false;
        });

        $("#glossaryModal").mouseleave(function () {
            $(this).slideUp(function () { $(this).jqmHide(); });
        });

        // Close Button Highlighting. 
        // IE doesn't support :hover

        if ($.browser.msie) {

            $('div.jqmAlert .jqmClose').hover(
	        function () {
	            $(this).addClass('jqmCloseHover');
	        }, function () {
	            $(this).removeClass('jqmCloseHover');
	        });

        }
    };

    /* Initialize Glossary Terms */

    glossaryTipz.enableGlossary();

    /***********************************************************************
    Panel Exp/Col box :: Function
    ***********************************************************************/

    $(".panelTitle").toggle(function () {

        $(this).toggleClass("panelExpanded");
        $(this).next().next().show();
        $(this).next().slideDown();

        $(".glossaryTrigger", $(this).next()).css({ display: "inline-block" });

    }, function () {

        $(this).toggleClass("panelExpanded");
        $(this).next().next().hide();
        $(this).next().slideUp();
    });

    /***********************************************************************
    ShareThis :: Function
    ***********************************************************************/

    $('.shareThisTrigger, .shareThisContainerCloseBtn').click(function () {
        $('div#shareThisContainer').fadeToggle("slow");

        return false;
    });

    $('.facebook_large_custom').click(function () {
        window.open('http://www.facebook.com/sharer/sharer.php?u=http://www.serostim.com', 'ShareThis');
        return false;
    });

    /***********************************************************************
    Site Map fix :: Function
    ***********************************************************************/
    /*
    $(".sitemap a").each(function () {
    var newstuff = $(this).html().replace(/®/gi, '<sup>&reg;</sup>');
    $(this).html(newstuff);
    });
    */

    /***********************************************************************
    Meet Panel Exp/Col box :: Function
    ***********************************************************************/

    $("#meetPJ").click(function () {

        if ($(this).hasClass("meetOff")) {
            $("#jrStory").hide();
            $("#pjStory").show();
            $("#realStoriesContent").toggleClass("realStoriesContentJR");
            $(this).removeClass("meetOff").addClass("meetOn");
            $("#meetJR").removeClass("meetOn").addClass("meetOff");
        }

    });

    $("#meetJR").click(function () {
        if ($(this).hasClass("meetOff")) {
            $("#jrStory").show();
            $("#pjStory").hide();
            $("#realStoriesContent").toggleClass("realStoriesContentJR");
            $(this).removeClass("meetOff").addClass("meetOn");
            $("#meetPJ").removeClass("meetOn").addClass("meetOff");
        }
    });

    /***********************************************************************
    Custom Scroll Area :: Function
    ***********************************************************************/

    /*
    args: scrollType,animSpeed,easeType,bottomSpace,draggerDimType,mouseWheelSupport,scrollBtnsSupport,scrollBtnsSpeed
    */

    $("#contentContainer").mCustomScrollbar("vertical", 1000, "easeOutCirc", 1.25, "auto", "no", "yes", 5);

    //Fix Dragger height
    var dgheight = $(".dragger").height() - 40;
    $(".scrollerBkgdBar").height(dgheight);

    /***********************************************************************
    FusionBot Search :: Function
    ***********************************************************************/

    var fusionBotURL = 'http://ss810.fusionbot.com/b/q?sn=161232186&amp;k=&related=0&rgn=serostimv3&e=se2&keys=';
    var HCPfusionBotURL = 'http://ss810.fusionbot.com/b/q?sn=161232186&k=&related=0&rgn=serostimhcpv3&e=hc2&keys=';

    $(".searchbox").focusin(function () {
        if ($(this).val() == "Search") {
            $(this).val("");
        }
    });

    $(".searchbox").focusout(function () {
        if (!$(this).val()) {
            $(this).val("Search");
        }

    });

    $(".searchbox").keypress(function (event) {
        if (event.keyCode == 13) {
            window.location = fusionBotURL + $(this).val();
            return false;
        }
    });

    $("#btnSubmit").click(function () {
        window.location = fusionBotURL + $(".searchbox").val();
        return false;
    });

    /**HCP SEARCH **/
    $(".searchboxHCP").focusin(function () {
        if ($(this).val() == "Search") {
            $(this).val("");
        }
    });

    $(".searchboxHCP").focusout(function () {
        if (!$(this).val()) {
            $(this).val("Search");
        }
    });

    $(".searchboxHCP").keypress(function (event) {
        if (event.keyCode == 13) {
            window.location = HCPfusionBotURL + $(this).val();
            return false;
        }
    });

    $("#btnSubmitHCP").click(function () {
        window.location = HCPfusionBotURL + $(".searchboxHCP").val();
        return false;
    });


    /***********************************************************************
    Modal Boxen :: Function
    ***********************************************************************/

    // Videos
    $('a.injectionInstructions, a.coolClick2').boxen(
	{
	    showTitleBar: false,
	    showCloseButton: true,
	    width: 650,
	    height: 500,
	    overlayOpacity: 0.8,
	    modal: false,
	    postOpen: function () {
	        var iframeHREF = $('div#boxen_content_area iframe').attr('src');
	        iframeHREFVariableIndex = iframeHREF.indexOf("?");
	        iframeHREF = iframeHREF.substr(0, iframeHREFVariableIndex);
	        $('div#boxen_content_area iframe').attr('src', iframeHREF);
	    }
	});

    $('a.hcpGrowthHormone, a.hcpDaisyWheel, a.hcpScienceBehindSerostim, a.hcpProperNutrition').boxen(
	{
	    showTitleBar: false,
	    showCloseButton: true,
	    width: 785,
	    height: 645,
	    overlayOpacity: 0.8,
	    useTheme: true,
	    themeName: 'hcpvideo',
	    modal: false,
	    postOpen: function () {
	        $('div#boxen_content_area_interstitial iframe').attr('src', '/includes/' + $(this).attr("class") + '.htm');
	    }
	});

    $('a.hcpInjectionInstruction, a.hcpcoolClick2').boxen(
	{
	    showTitleBar: false,
	    showCloseButton: true,
	    width: 580,
	    height: 500,
	    overlayOpacity: 0.8,
	    useTheme: true,
	    themeName: 'hcpvideo',
	    modal: false,
	    postOpen: function () {
	        $('div#boxen_content_area_interstitial iframe').attr('src', '/includes/' + $(this).attr("class") + '.htm');
	    }
	});

    $('div#boxen_content iframe').attr('scrolling', 'no');

    // Interstitial Modal
    $('a.interstitial').boxen(
	{
	    showTitleBar: false,
	    showCloseButton: true,
	    showRedirectButton: true,
	    closeButtonText: "Cancel",
	    redirectButtonText: "OK",
	    redirectBlank: true,
	    useTheme: true,
	    themeName: 'interstitial',
	    width: 575,
	    height: 325,
	    overlayOpacity: 0.8,
	    modal: true,
	    postOpen: function () {
	        $('div#boxen_content_area_interstitial iframe').attr('src', '/includes/interstitial.htm');
	    }
	});

    // LEGAL HCP - Interstitial Modal
    $('a.legalHCP').boxen(
	    {
	        showTitleBar: false,
	        showCloseButton: true,
	        showRedirectButton: true,
	        closeButtonText: "RETURN",
	        redirectButtonText: "OK",
	        redirectBlank: false,
	        useTheme: true,
	        themeName: 'hcplegal',
	        width: 575,
	        height: 325,
	        overlayOpacity: 0.8,
	        modal: true,
	        postOpen: function () {
	            $('div#boxen_content_area_hcplegal iframe').attr('src', '/includes/hcplegal.htm');
	        }
	    });

    // Charts Modal
    $('a.pjcharts').boxen(
	{
	    showTitleBar: false,
	    showCloseButton: true,
	    showNavControls: true,
	    navLeftURL: '/includes/pj-weight-tracker.htm',
	    navRightURL: '/includes/pj-goals.htm',
	    width: 650,
	    height: 500,
	    overlayOpacity: 0.8,
	    modal: true,
	    useTheme: true,
	    themeName: 'charts',
	    postOpen: function () {
	        var iframeHREF = $('div#boxen_content_area_charts iframe').attr('src');
	        iframeHREFVariableIndex = iframeHREF.indexOf("?");
	        iframeHREF = iframeHREF.substr(0, iframeHREFVariableIndex);
	        $('div#boxen_content_area_charts iframe').attr('src', iframeHREF);
	    }
	});

    $('a.jrcharts').boxen(
	{
	    showTitleBar: false,
	    showCloseButton: true,
	    showNavControls: true,
	    navLeftURL: '/includes/jr-weight-tracker.htm',
	    navRightURL: '/includes/jr-goals.htm',
	    width: 650,
	    height: 500,
	    overlayOpacity: 0.8,
	    modal: true,
	    useTheme: true,
	    themeName: 'charts',
	    postOpen: function () {
	        var iframeHREF = $('div#boxen_content_area_charts iframe').attr('src');
	        iframeHREFVariableIndex = iframeHREF.indexOf("?");
	        iframeHREF = iframeHREF.substr(0, iframeHREFVariableIndex);
	        $('div#boxen_content_area_charts iframe').attr('src', iframeHREF);
	    }
	});


    $('div#boxen_content_charts iframe').attr('scrolling', 'no');

    // Close button :: on Click event to close Modal
    $('p.closeModal, div.btnCloseModal').click(function () {
        window.parent.closeIFRAME();
    });

    /***********************************************************************
    Pharma Search :: Function
    ***********************************************************************/

    if ($(".customScrollBox").innerHeight() < $(".customScrollBox .container .content").innerHeight()) {
        $(".scrollable").removeClass("hideElement");
    }

    if ($(".dragger").innerHeight() < 50) {
        $(".dragger").css({ height: "45px" });
        $(".scrollerTopCap, .scrollerBtmCap").css({ height: "20px" });
        $(".scrollerBkgdBar").css({ height: "5px" });
    }

    /***********************************************************************
    Nav fix to make the size of the registration mark the same cross browser 
    ***********************************************************************/
    if (!$.browser.msie) { $("#navContainer sup, #isiFooterContainer sup").addClass("regFix"); }

})(jQuery);

    /***********************************************************************
    Nav fix for 1200 x 800 or less resolution
    ***********************************************************************/

    if (screen.width <= 1280 || screen.height <= 800) {
        $("#navDivider").addClass("screenResFix");
    }

/***********************************************************************
Scrollto for Isi :: Function
***********************************************************************/

function processScrollTo(id) {
    var targetOffset = $('#' + id).offset().top;
    $('html, body').animate({ scrollTop: targetOffset }, 500);
}

function adjustWindowHeightForISI() {

        windowHeight=$(window).height();
        visibleHeight = Math.floor(windowHeight / 4) - $("#isiHeaderBar").outerHeight();

        // Expanded Height - 3/4 document
        expandHeight = Math.floor(visibleHeight * 4);

        $('#isiContentContainer').height(visibleHeight);
}

/***********************************************************************
CheckNav :: Function
***********************************************************************/

function checkNavHighlight(url) {

    var pathname = window.location.pathname;
    pathname.replace(".aspx", "");

    result = (pathname == url) ? true : false;

    return result;
}

/***********************************************************************
Boxen Close :: Function
***********************************************************************/

function closeIFRAME() {
    $.Boxen.close();
}

/*
function scrollBarResize() {

    var totalContent = $(".content").outerHeight(true);
    console.log(totalContent);

    var minDraggerHeight = 5;
    var draggerContainerHeight = $(".dragger-container").height();
    var visibleHeight = $(".customScrollBox").height();
    var adjDraggerHeight = Math.round(totalContent - ((totalContent - visibleHeight) * 1.3));

    if (adjDraggerHeight <= minDraggerHeight) { //minimum dragger height
        $(".dragger").css({
            "height": minDraggerHeight + "px",
            "line-height": minDraggerHeight + "px"
        });
    } else if (adjDraggerHeight >= draggerContainerHeight) {
        $(".dragger").css({
            "height": draggerContainerHeight - 10 + "px",
            "line-height": draggerContainerHeight - 10 + "px"
        });
    } else {
        $(".dragger").css({
            "height": adjDraggerHeight + "px",
            "line-height": adjDraggerHeight + "px"
        });
    }

}
*/
