﻿var deviceIphone = "iphone";
var deviceIpod = "ipod";
var deviceIpad = "ipad";
var deviceAndroid = "android";
var deviceBB = "blackberry";
var devicePalm = "palm";
var deviceWinMob = "windows ce";
var deviceS60 = "series60";
var deviceSymbian = "symbian";
var engineWebKit = "webkit";

var fileToUse = "/css/mobile.css";
var idsaMobile = "/css/idsaMobile.css";
var hivmaMobile = "/css/hivmaMobile.css";
var uagent = navigator.userAgent.toLowerCase();



function DetectMobile() {
    if (uagent.search(deviceIphone) > -1 || uagent.search(deviceIpod) > -1 || uagent.search(deviceAndroid) > -1 || uagent.search(deviceBB) > -1 || uagent.search(devicePalm) > -1)
        return true;
    else {
        return false;
    }
}

//alert(uagent);


//All of the functions for pages are called at the bottom of this file within the "$(window).load" function

$(window).load(function () {

    if (uagent.search(deviceIpad) > -1) {
        //mobileNavFullSite();
    }

    $(".QuadsTabs li:last").addClass("last");

    var windowWidthOnLoad = $("body").width(); //this is used to with mobile functions.
    var desktopWidth = 760;
    Array.max = function (array) {
        return Math.max.apply(Math, array);
    };
    Array.min = function (array) {
        return Math.min.apply(Math, array);
    };

    function patientSlide() {
        //alert("slider");
        var i = 0;
        var total = $(".patientStorySlider .bannerLeft img").length - 1;
        var realTotal = $(".patientStorySlider .bannerLeft img").length;
        $(".slideTotalPatient").text(realTotal);

        //alert(total);

        $(".patientArrowLeftSlide").click(function () {
            //alert("left");
            i = --i;
            // i++;
            if (i < 0) {
                i = total;
            }
            currentSlideCount = parseInt(i) + 1;
            $(".patientStorySlider").find(".slideNumber").text(currentSlideCount);
            $(".patientStorySlider .bannerLeft img").hide();
            $(".patientStorySlider .bannerLeft img").eq(i).show();
        });

        $(".patientArrowRightSlide").click(function () {
            //alert("right");
            i = ++i;
            if (i > total) {
                i = 0;
            }
            currentSlideCount = parseInt(i) + 1;
            $(".patientStorySlider").find(".slideNumber").text(currentSlideCount);
            $(".patientStorySlider .bannerLeft img").hide();
            $(".patientStorySlider .bannerLeft img").eq(i).show();
        });

    }

    function bannerHome() {
        var guidelinesSpecial = $(".guidelinesSpecial").length;
        var patientBannerLength = $(".slideSet").parents(".patientInfo").length;
        var idsaNoRandom = $("#idsaNoRandom").length;
        var childElment = $(".bannerLeft img").parent().attr("class");
        //alert(childElment);
        var slideSetTotal = $(".slideSet li").length;
        var randomSlide = Math.random() * 4;
        var randomNum = Math.floor(Math.random() * 3);
        if (idsaNoRandom <= 0) {
            // right banner TEXT VERBIAGE
            $(".bannerRight .innerInfo").eq(randomNum).show();
            // thumbnail images SELECTED HIGHLIGHT IMAGE
            $(".slideSet a").eq(randomNum).addClass("selected");
            // left banner LARGE IMAGE
            $(".bannerLeft img").fadeOut();
            $(".bannerLeft img").eq(randomNum).fadeIn("fast");

            if (guidelinesSpecial > 0) {
                $(".guidelinesSlideShow:gt(0)").hide();
            }

            if (childElment == "bannerLeft") {
                $(".bannerLeft img:gt(0)").hide();
            }
            $(".slideSet a").eq(randomNum).addClass("selected");
        }
        else {
            $(".bannerRight .innerInfo").eq("0").show();
            $(".slideSet a").eq("0").addClass("selected");
        }
        $(".slideSet a").click(function () {
            var indexThis = $(".slideSet a").index(this);
            var indexBanner = $(".bannerLeft img").index(this);
            $(".slideSet a").removeClass("selected");
            if (childElment == "bannerLeft") {
                $(".bannerLeft img").fadeOut();
                $(".bannerLeft img").eq(indexThis).fadeIn("fast");
            }
            else if (guidelinesSpecial > 0) {

                $(".guidelinesSlideShow").fadeOut();
                $(".guidelinesSlideShow").eq(indexThis).fadeIn("fast");
            }
            else {
                $(".bannerLeft .hivmaGuidelinesResources").fadeOut();
                $(".bannerLeft .hivmaGuidelinesResources").eq(indexThis).fadeIn("fast");
            }
            $(".bannerRight .innerInfo").hide();

            $(".bannerRight .innerInfo").eq(indexThis).show();
            $(this).addClass("selected");
        });
        if (patientBannerLength > 0) {
            $(".slideSet a").eq(randomSlide).click();
        }
    }
    function sideBarSlider(className) {


        if (className.indexOf("slideShowGeneric") > -1) {
            var imageArray = new Array();
            $(className + " .entry img").each(function () {
                var imageWidth = $(this).width();
                // alert(imageWidth);
            });
            var newWidth = Array.max(imageArray);
            if (newWidth != 0) {
                $(className).width(newWidth);
            }
        }

        $(className).each(function () {
            $(this).children(".entry:gt(0)").hide();
        });

        var total = $(className).children(".entry").length - 1;
        var slideTotalCount = parseInt(total) + 1;

        if (total == 0) {
            //$(className).children(".navigateEntry").remove();
        }

        $(className).children(".navigateEntry").find(".slideTotal").text(slideTotalCount);

        var i = 0;
        $(className + " .arrowLeftSlide").click(function () {
            i = --i;
            // i++;
            if (i < 0) {
                i = total;
            }
            currentSlideCount = parseInt(i) + 1;
            $(className).find(".slideNumber").text(currentSlideCount);
            $(className).children(".entry").hide();
            $(className).children(".entry").eq(i).show();
        });
        $(className + " .arrowRightSlide").click(function () {
            i = ++i;
            if (i > total) {
                i = 0;
            }
            currentSlideCount = parseInt(i) + 1;
            $(className).find(".slideNumber").text(currentSlideCount);
            $(className).children(".entry").hide();
            $(className).children(".entry").eq(i).show();
        });
    }

    function showHideQuestions() {
        $(".question a").toggle(function () {
            $(this).parents(".question").next(".answer").fadeIn();
        }, function () {
            $(this).parents(".question").next(".answer").fadeOut();
        });
    }

    function journalsTabs() {

        var heightList = new Array();
        /*
        $(".journals .tabs li").each(function () {
        var height = $(this).height();
        heightList.push(height);
        var maxNumber = Array.max(heightList);
        $(this).height(maxNumber);
        });
        */

        $(".contentTab").hide();
        $(".contentTab").each(function () {
            $(this).children(".row:last").addClass("last");
        });

        var tabIndex = $('#ctl00_ContentPlaceHolder1_hdnCalendarSelected').val();
        $(".journals").children(".contentTabContainer").children(".contentTab").css({ position: "absolute", top: "-2500px", left: "0", visibility: "hidden" }).hide();
        if (tabIndex === "0" || tabIndex === "" || tabIndex === undefined) {
            $(".journals").children(".contentTabContainer").children(".contentTab").eq(0).css({ position: "static", top: "0px", left: "0", visibility: "visible" }).show();
            //$(".journals").children(".contentTabContainer").children(".contentTab:gt(0)").hide();
            $(".journals .tabs li:eq(0)").addClass("selected");
        }
        else if (tabIndex === "1") {
            $(".journals").children(".contentTabContainer").children(".contentTab").eq(tabIndex).css({ position: "static", top: "0px", left: "0", visibility: "visible" }).show();
            $(".journals .tabs li:eq(1)").addClass("selected");
        }
        $(".journals .tabs a").click(function () {

            $(".journals .tabs a").parent("li").removeClass("selected");
            $(this).parent("li").addClass("selected");
            var indexThis = $(".journals .tabs a").index(this);
            $('#ctl00_ContentPlaceHolder1_hdnCalendarSelected').val(indexThis);
            $(".journals").children(".contentTabContainer").children(".contentTab").css({ position: "absolute", top: "-2500px", left: "0", visibility: "hidden" }).hide();
            $(".journals").children(".contentTabContainer").children(".contentTab").eq(indexThis).css({ position: "static", top: "0px", left: "0", visibility: "visible" }).show();

        });

    }

    function blogPostLast() {
        $(".blogPost:last").removeClass().addClass("blogPostLast"); ;
        $(".listings:last").addClass("last");
    }

    function practiceAccordion() {
        $(".accordionIDSA dt").click(function () {
            var isVisible = $(this).next("dd").is(":visible");
            if (isVisible == false) {
                $(this).addClass("selected");
                $(this).next("dd").slideDown();
            }
            else {
                $(this).removeClass("selected");
                $(this).next("dd").slideUp();
            }
        });
    }
    function meetingArchivesColumnize() {
        try {
            $(".meetings .row ul").columnize({ columns: 2 });
        }
        catch (err) {
            //alert(err);
        }
    }
    function pageFunctionsContent() {
        /*begin print*/
        $(".icoPrint").click(function () {
            window.print();
        });
        /*end print*/

        /*begin favorites*/
        try {
            $(".icoFavorites").jFav();
        }
        catch (err) {
            //alert(err);
        }
        /*end favorites*/
    }

    function searchBoxFocusAndBlur() {

        var originalTextValue = $(".sideContainer input[type='text']").val();
        $(".sideContainer input[type='text']").focus(function () {
            var currentTextboxValue = $(this).val();
            if (currentTextboxValue == originalTextValue) {
                $(this).val("");
            }
        });
        $(".sideContainer input[type='text']").blur(function () {
            var textValue = $(this).val().length;
            //alert(textValue);
            if (textValue <= 0) {
                $(this).val(originalTextValue);
            }
        });
    }

    function fixSelectorIssuesIE7() {
        $(".IDSAUserName ul li:last").addClass("last");
    }

    function primaryNavDropDown() {
        $(".primaryNav li.parentMenuIDSA").hover(function () {
            var offSetParent = $(this).position();
            //alert("the offset of this item is " + offSetParent.left);
            if (offSetParent.left > 700) {
                $(this).addClass("parentAlignRight");
                //alert("too far");
            }
            $(this).children(".subMenuIDSA").show();


        }, function () {
            $(this).children(".subMenuIDSA").hide();
        });
    }

    function inputFocusAndBlur() {
        var defaultValue;
        $("#txtstatus").focus(function () {
            defaultValue = $(this).attr("title");
            if ($(this).val() == defaultValue) {
                $(this).val("");
            }
            //alert(defaultValue);

            $(this).addClass("editTextFieldIDSA");

        });

        $(".container input").blur(function () {
            defaultValue = $(this).attr("title");
            var defaultValueLength = $(this).val().length;

            if (defaultValueLength == 0) {
                $(this).val(defaultValue);
            }

            if ($(this).val() != defaultValue) {
                $(this).addClass("editTextFieldIDSA");
                //alert("different");
            }
            else {
                $(this).removeClass("editTextFieldIDSA");
            }
            //alert("the default value is " + defaultValue);
            //alert("the new value is " + $(this).val());
        });
    }

    function twoBySliderMyIDSA() {
        //alert("two by slider ready to go");
        var i = 0;
        var totalCount = parseInt(($(".containTwo ul").length) - 1);
        $(".prevTwo").addClass("disabledLink");
        //alert("the total count is " + totalCount);
        $(".containTwo ul:gt(0)").hide();

        $(".prevTwo").not("disabledLink").click(function () {
            $(".nextTwo").removeClass("disabledLink");
            if (i > 0) {
                i = --i;
            }
            //alert("prev value i is " + i);
            if (i == 0) {
                //i = 0;
                $(this).addClass("disabledLink");
            }
            $(this).parent(".navigationMyIDSASlideShow").next(".containTwo").children("ul").hide();
            $(this).parent(".navigationMyIDSASlideShow").next(".containTwo").children("ul").eq(i).show();
        });
        $(".nextTwo").not("disabledLink").click(function () {
            $(".prevTwo").removeClass("disabledLink");
            if (i < totalCount) {
                i = ++i;
            }
            //alert("next value i is " + i);
            if (i == totalCount) {
                //i = 0;
                $(this).addClass("disabledLink");
            }
            $(this).parent(".navigationMyIDSASlideShow").next(".containTwo").children("ul").hide();
            $(this).parent(".navigationMyIDSASlideShow").next(".containTwo").children("ul").eq(i).show();
        });

    }

    function textResize() {
        var i = 0;
        var fontSize;
        var thisContainer;

        function changeFontSize() {
            $(thisContainer).children().not(".journals .tabs, .questionsAndAnswers .paginateQuestions, h1, h2, h3, h4, .patientInfo, .accordionIDSA, .takeAction").css("font-size", fontSize);
        }

        if ($(".wideColumnRight").length > 0) {
            fontSize = $(".wideColumnRight").css("font-size").replace("px", "");
            thisContainer = ".wideColumnRight";
        }
        if ($(".middleContentContainer").length > 0) {
            fontSize = $(".middleContentContainer").css("font-size").replace("px", "");
            thisContainer = ".middleContentContainer";
        }
        if ($(".aToZResults").length > 0) {
            fontSize = $(".aToZResults").css("font-size").replace("px", "");
            thisContainer = ".aToZResults";
        }
        if ($(".blogIDSAList").length > 0) {
            fontSize = $(".blogIDSAList").css("font-size").replace("px", "");
            thisContainer = ".blogIDSAList";
        }
        if ($(".calendarIDSA").length > 0) {
            fontSize = $(".calendarIDSA").css("font-size").replace("px", "");
            thisContainer = ".calendarIDSA";
        }
        if ($(".whiteBackground").length > 0) {
            fontSize = $(".whiteBackground").css("font-size").replace("px", "");
            thisContainer = ".whiteBackground";
        }
        if ($(".searchResultsIDSA").length > 0) {
            fontSize = $(".searchResultsIDSA").css("font-size").replace("px", "");
            thisContainer = ".searchResultsIDSA";
        }
        if ($(".memberInformation").length > 0) {
            fontSize = $(".memberInformation, .contentTabContainer").css("font-size").replace("px", "");
            thisContainer = ".memberInformation, .contentTabContainer";
        }
        if ($(".CesSearch").length > 0) {
            fontSize = $(".CesSearch, .contentTabContainer").css("font-size").replace("px", "");
            thisContainer = ".CesSearch, .contentTabContainer";
        }
        $(".icoTextSize").click(function () {
            i = ++i;
            if (i == 1) {
                fontSize = parseInt(fontSize) + 2;
                //alert("the font size is " + fontSize);
                changeFontSize();
            }
            else if (i == 2) {
                fontSize = parseInt(fontSize) + 4;
                //alert("the font size is " + fontSize);
                changeFontSize();
            }
            else {
                i = 0;
                fontSize = parseInt(fontSize) - 6;
                //alert("the font size is " + fontSize);
                changeFontSize();
            }
        });
    }

    function myIDSAModal() {
        $(".interestGroupIDSAModal").click(function () {
            alert("Joining a special interest group adds you to a distribution list in order to receive the latest updates for that group.");
        });

        $(".gayGroupModal").click(function () {
            alert("The Gay and Lesbian Interest Group is committed to representing and supporting the needs of gay and lesbian IDSA members. IDSA wishes to foster a professional climate in which all of our diverse members can achieve their full potential and where our gay and lesbian members may serve openly without fear of discrimination or hostility. The IG will serve as a venue for networking as well as a forum to discuss  unique challenges our gay and lesbian colleagues face in today's society. The IG will explore how best to combat homophobia within the field of infectious diseases and how IDSA may support members challenged by discrimination on the basis of sexual orientation. The IG will recommend solutions/actions to IDSA's leadership as needed and appropriate.");
        });

        $(".infectionsCancerGroupModal").click(function () {
            alert("The Infections in Cancer Interest Group is a forum for infectious disease clinicians and investigators working in major cancer centers. Topics of discussion may include ways to enhance educational opportunities related to the prevention/management of infections in oncology patients; collaboration on clinical studies/trials; and ways to work with CDC to establish evidenced based surveillance programs. The IG will suggest ways for IDSA to help support educational activities, including possible symposia at the annual meeting.");
        });

        $(".minoritiesGroupModal").click(function () {
            alert("The Minorities in ID Interest Group is committed to representing and supporting minority members. Topics for discussion may include ways to further the goals of the IG, challenges that minorities face in medicine or the subspecialty of infectious diseases, and public policy aimed at supporting medical education for minorities. The interest group may suggest ways that the Society can better serve its diverse membership, ways to recruit minority infectious diseases physicians to IDSA, sessions or networking events to be held at the Annual Meetings, public policy positions that the Society should take, and ways to ensure that the IDSA leadership reflects the diversity of the membership. To join the Minorities in ID Interest Group and subscribe to the discussion list. (Log-in required)");
        });
    }

    function sideMenu() {
        $(".menu li").eq(0).addClass("noGradient");
        var urlCurrent = window.location;
        urlCurrent = urlCurrent.toString().toLowerCase().replace("http://", "").replace("www.", "");
        var indexFirstSlash = urlCurrent.indexOf("/");
        var urlBase = urlCurrent.substring(0, indexFirstSlash);
        urlCurrent = urlCurrent.replace(urlBase, "")
        var selectedHref = $(".menu ul li").find("a[href='" + urlCurrent + "']");

        $(".menu ul li").find("a[href='" + urlCurrent + "']").addClass("selected");
        var parentUlClass = $(selectedHref).parent("li").parent("ul").attr("class");

        if (parentUlClass == "subMenuSideIDSA") {
            $(selectedHref).parent("li").parent("ul.subMenuSideIDSA").show();
            $(selectedHref).parent("li").parent("ul.subMenuSideIDSA").parent("li").find("a").eq(0).addClass("selected");
        }
        else {
            $(".menu ul li").find("a[href='" + urlCurrent + "']").parent("li").children("ul.subMenuSideIDSA").show();
        }

        //alert(parentUlClass);

    }

    function rightSideBoxBeginAndEnd() {
        //alert("columnRight");
        $(".columnRight .info:first").removeClass().addClass("infoTop");
        $(".columnRight .info:last").removeClass().addClass("infoBottom");
    }

    function mobileNav() {


        var showNavOnHome = $("#homePageMobileShow").length; //we use this id to see if we are on the home page for mobile.

        if (showNavOnHome > 0 && windowWidthOnLoad < desktopWidth) {//this shows the navigation if we are on the homepage for mobile vs. and empty page.
            $(".mobileNav").slideDown();
        }


        $(".mobileNav li").each(function () {
            var hasChildren = $(this).find("ul").length;
            //console.log("the length is " + hasChildren);
            if (windowWidthOnLoad < 900) {
                if (hasChildren > 0) {
                    $(this).children("a:eq(0)").attr("href", "javascript\:void(0)\;").addClass("mobileParentMenu");
                    $(this).addClass("containsChildren");
                }
            }
        });

        $(".mobileNav .parentMenuIDSA a.mobileParentMenu").click(function () {
            $(".selectedMobileNavItem").removeClass("selectedMobileNavItem");
            var childrenVisible = $(this).parent("li").find(".subMenuIDSA").is(":visible");
            console.log(childrenVisible);
            $(".subMenuIDSA").slideUp();
            if (childrenVisible == false) {
                $(this).parent("li").addClass("selectedMobileNavItem").find(".subMenuIDSA").slideDown();
            }
            else {
                $(this).parent("li").removeClass("selectedMobileNavItem").find(".subMenuIDSA").slideUp();
            }

        });


        $(".mobileShowMenu").click(function () {
            var isVisible = $(".mobileNav").is(":visible");
            try {
                if (isVisible == false) {
                    $(".mobileNav").show(20, function () {
                        $(".container, .mobileAtoZ").css({ position: "absolute", top: -1300 }).hide();
                        $(".mobileNav").css({ position: "static", top: 0 });
                    });
                    $(this).text("View Content");
                }
                else {
                    $(".mobileNav, .mobileAtoZ").css({ position: "absolute", top: -1300 }).hide();
                    $(".container").css({ position: "static", top: 0 }).show();
                    $(this).text("View Menu");
                }
            }
            catch (err) {
                alert(err);
            }
        });


        $(".mobileShowAotZ").click(function () {
            var isVisible = $(".mobileAtoZ").is(":visible");
            if (isVisible == false) {
                $(".mobileAtoZ").show(20, function () {
                    $(".container, .mobileNav").css({ position: "absolute", top: -1300 }).hide(); //slide other navigation elements up
                    $(".mobileAtoZ").css({ position: "static", top: 0 });
                    $(".mobileShowMenu").text("View Menu"); //change menu text
                });
            }
            else {
                $(".container").css({ position: "static", top: 0 }).show();
                $(".mobileAtoZ, .mobileNav").css({ position: "absolute", top: -1300 }).hide();
            }
        });

        /*
        $(".mobileShowMenu").click(function () {
        var isVisible = $(".mobileNav").is(":visible");
        if (isVisible == false) {
        $(".mobileNav").slideDown();
        $(".container, .mobileAtoZ").slideUp();
        $(this).text("View Content");
        }
        else {
        $(".mobileNav, .mobileAtoZ").slideUp();
        $(".container").slideDown();
        $(this).text("View Menu");
        }
        });

        $(".mobileShowAotZ").click(function () {
        var isVisible = $(".mobileAtoZ").is(":visible");
        if (isVisible == false) {
        $(".mobileAtoZ").slideDown();
        $(".container, .mobileNav").slideUp();
        $(".mobileShowMenu").text("View Menu");
        }
        else {
        $(".mobileAtoZ, mobileNav").slideUp();
        $(".container").slideDown();
        }
        });
        */


        $(window).resize(function () {
            var windowWidth = $("body").width();

            //console.log("the window width is " + windowWidth);
            if (windowWidth > desktopWidth) {
                $(".mobileNav, .mobileAtoZ, .contentTabMobile").hide();
                $(".container").show();
                $(".contentTabMobile").remove();
                $(".contentTabContainer").show();
            }

            else if (windowWidth < desktopWidth && showNavOnHome > 0) {
                $(".mobileShowMenu").text("View Content");
                $(".mobileNav").show();
                mobileTabsToAccordion();
            }
            else {
                mobileTabsToAccordion();
            }
        });

        var topicsLinksMobile = $(".topics").html();
        $(".mobileAtoZ").html(topicsLinksMobile);

    }

    function mobileTabsToAccordion() {
        $(".contentTabContainer").hide();
        $(".journals .tabs li").each(function () {
            var indexThis = $(".journals .tabs li").index(this);
            var newAccordionContent = "<div class=\"contentTabMobile\"></div>";
            $(newAccordionContent).appendTo(".tabs li:eq(" + indexThis + ")");
            $(this).children("a").addClass("parentAccordion");
        });
        $(".contentTabMobile:eq(0)").show();
        $(".contentTabMobile").each(function () {
            var indexThis = $(".contentTabMobile").index(this);
            var newHtml = $(".contentTab").eq(indexThis).html();
            $(this).html(newHtml);
        });
        $(".parentAccordion").click(function () {
            $(".contentTabMobile").hide();
            var contentVisibile = $(this).parent().find(".contentTabMobile:eq(0)").is(":visible");
            if (contentVisibile == true) {
                $(this).parent().find(".contentTabMobile:eq(0)").hide();
            }
            else {
                $(this).parent().find(".contentTabMobile:eq(0)").show();
            }
        });
        //$(".contentTabMobile").eq(0).show();

    }




    function scrollToPractice() {

        var windowLocation = window.location.href;

        var indexOfHash = windowLocation.indexOf("#");

        var removeThis = windowLocation.substring(0, indexOfHash);

        var goToThisID = windowLocation.replace(removeThis + "#", "").replace("/", "");
        try {
            //alert(goToThisID);

            var trgt = $(".datascrollto" + goToThisID);

            var parentItemElement = trgt;

            if (trgt.length > 0) {
                if (($(trgt).parent().is("dt"))) {
                    $(".datascrollto" + goToThisID).parent("dt").addClass("selected").next("dd").slideDown();
                    var target_offset = $(trgt).offset();

                    var target_top = target_offset.top;
                    $('html, body').animate({ scrollTop: target_top }, { duration: "slow" }, 500);
                }
                else {
                    //alert("lets scroll");
                    $(".datascrollto" + goToThisID).parents("dd").eq(0).prev("dt").addClass("selected").next("dd").slideDown();
                    var target_offset = $(trgt).offset();

                    var target_top = target_offset.top;
                    $('html, body').animate({ scrollTop: target_top }, { duration: "slow" }, 500);
                }
            }
        }
        catch (err) {
            //alert(err);
        }
    }


    var isMobile = DetectMobile();



    if (isMobile == true) {



        $(".fullSiteLinkJavascript").show().appendTo(".replaceLink");

        var idsaScreen = $("#idsaScreen").length;


        var mobileValue = $(".checkMobile").val();

        function mobileNavFullSite() {
            $(".primaryNav li").each(function () {
                var hasChildren = $(this).find("ul").length;
                //alert(hasChildren);
                //console.log("the length is " + hasChildren);
                if (hasChildren > 0) {
                    $(this).children("a:eq(0)").attr("href", "javascript\:void(0)\;").addClass("mobileParentMenu");
                    $(this).addClass("containsChildren");
                }
            });
            $(".mobileParentMenu").click(function () {

                $(".subMenuIDSA").hide()
                var offSetParent = $(this).position();
                //alert("the offset of this item is " + offSetParent.left);
                if (offSetParent.left > 700) {
                    $(this).addClass("parentAlignRight");
                    //alert("too far");
                }
                $(this).children(".subMenuIDSA").show();
            });
        }

        if (mobileValue == 1) {
            //mobileNavFullSite();
            $(".mobileSiteLinkJavascript").show().appendTo(".swapLink");
        }
        else {
            mobileNav();
        }

        if (uagent.search(deviceIpad) > -1 || windowWidthOnLoad > 800) {
            //mobileNavFullSite();
        }


        if (windowWidthOnLoad < desktopWidth) {
            if (mobileValue != 1) {
                mobileTabsToAccordion();
            }
        }

        var headerVisible = $(".mobileHeader").is(":visible");
        var footerVisible = $(".footer").is(":visible");

        //alert("header is " + headerVisible + "and footer is " + footerVisible + ".");
        if (headerVisible == true && footerVisible == false) {
            $(".header, .footer").remove();
        }
    }

    else if (isMobile == false) {

        $(".mobileSiteLinkJavascript").show().appendTo(".replaceLink");
    }

    function removeNBSPFromBlog() {
        try {
            var NBSP = $(".blogIDSAList .entry").html().replace("&nbsp;", "");
            $(".blogIDSAList .entry").html(NBSP);
        }
        catch (err) {
            //alert(err);
        }
    }


    function inputFocusAndBlurNew() {
        $(".myIDSAProfile input[type='text']").each(function () {
            var value = $(this).val();
            var dataTitle = $(this).attr("data-title");
            $(this).wrap("<div class='fieldWrap'></div>");
            if (dataTitle != undefined) {
                $(this).parent(".fieldWrap").append("<label class='idsaForm'>" + dataTitle + "</label>");
            }
            if (value == '') {
                $(this).addClass("editTextFieldIDSA").parent(".fieldWrap").children(".idsaForm").show();
            }
            else {
                $(this).addClass("editTextFieldIDSA").parent(".fieldWrap").children(".idsaForm").hide();
            }
        });

        $(".idsaForm").click(function () {
            $(this).parent(".fieldWrap").children(".idsaForm").hide();
            $(this).parent(".fieldWrap").children("input").focus();
        });

        $(".container input[type='text']").focus(function () {
            $(this).addClass("editTextFieldIDSA").parent(".fieldWrap").children(".idsaForm").hide();
        });

        $(".container input[type='text']").blur(function () {
            var thisVal = $(this).val().length;
            if (thisVal < 1) {
                $(this).parent(".fieldWrap").children(".idsaForm").show();
            }
        });
    }
    function selectTabsquerySt(ji) {
        hu = window.location.search.substring(1);
        gy = hu.split("&");
        for (i = 0; i < gy.length; i++) {
            ft = gy[i].split("=");
            if (ft[0] == ji) {
                return ft[1];
            }
        }
    }
    modalHelpMyIDSA();
    patientSlide();
    scrollToPractice();
    removeNBSPFromBlog();
    bannerHome();
    sideBarSlider(".policyNewsSlider"); //operates policy slideshow container for home page
    sideBarSlider(".breakingNewsSlider"); //operates news slideshow container
    sideBarSlider(".idsaSlider"); //operates IDSA announcements slideshow container for home page
    sideBarSlider(".slideShowGeneric"); //generic slideshow used for articles
    sideBarSlider(".blogSlider"); //operates for the blogs
    showHideQuestions(); //shows and hides questions
    journalsTabs(); //operates tab layouts globally based off index of item clicked and dom structure.    
    blogPostLast(); //does some css class updates for last blog post
    practiceAccordion(); //accordion functions for showing and hiding information used globally on templates
    meetingArchivesColumnize(); //columnizes list on the fly
    pageFunctionsContent(); //this contains the functions needed for each page at the top (print, favorite, etc)
    searchBoxFocusAndBlur(); //this performs default focus and blur on most forms on the site.
    fixSelectorIssuesIE7();
    primaryNavDropDown(); //drop down navigation function used in global header
    inputFocusAndBlur();
    inputFocusAndBlurNew();
    twoBySliderMyIDSA(); //slider used in myidsa pages
    textResize(); //text resize function used within page functions container.
    myIDSAModal(); //opens modal window for information
    sideMenu(); //this does some css changes and opens menus based off url
    rightSideBoxBeginAndEnd(); //this function replaces first and last element class names in columns within the home page and blog
    var tabSelection = selectTabsquerySt('tab');
    if (tabSelection != undefined) {
        $('.tabs li:eq(' + (tabSelection - 1) + ') a').click();
        if (tabSelection == 2) {
            getPeers();
        }
        else if (tabSelection == 3) {
            getTopics();
        }
        else if (tabSelection == 4) {
            getAlertTopics();
        }
        else if (tabSelection == 5) {
            getFavorites();
        }
    }
    goToGuidelinesPage();
    mobileTabs();//operates show hide function for policy topis on mobile pages.
});

function goToGuidelinesPage() {
    $("#idsaGotoPageButton").click(function () {
        var url = $(".goToGuidelineIDSA").children("option:selected").attr("data-url");
        if (url.length > 0) {
            document.location = url;
        }
    });
}

function addSubscription(subsId, elementName) {
    $.ajax({
        url: '/Handlers/CommunityAlerts.ashx?action=addalerts&subs_Id=' + subsId,
        cache: false,
        success: function (data) {
            $('#' + elementName).hide();
        },
        error: function (data) {
            $('#' + elementName).hide();
        }
    });
}

function modalHelpMyIDSA() {
//    $(".myIdsaHelpLink").click(function () {
//        $(this).colorbox({ width: "50%", inline: true, href: "#inline_example1" });
//    });
}

function mobileTabs() {
    //$(".IDSAJournalsMobileContent:eq(0)").show();
    $(".journals .tabs li.IDSAMobileTabOpen:eq(0)").removeClass("selected");
    $(".IDSAMobileTabOpen").click(function () {

        var subIsVisible = $(this).find(".IDSAJournalsMobileContent").is(":visible");


        if (subIsVisible == false) {
            $(".IDSAMobileTabOpen.selected").removeClass("selected");
            $(this).addClass("selected");
            $(this).find("a:eq(0)").addClass("selectedTabMobile");
            $(".IDSAJournalsMobileContent").hide();
            $(this).find(".IDSAJournalsMobileContent").show();
        }
        else {
            $(".IDSAMobileTabOpen.selected").removeClass("selected");
            //$(this).addClass("selected");
            $(this).find("a:eq(0)").removeClass("selectedTabMobile");
            $(".IDSAJournalsMobileContent").hide();
            //$(this).find(".IDSAJournalsMobileContent").show();
        }
    });
}
