/*This file created to add site js functions */

/*===================================
-- Start site jQuery
=====================================*/

$(document).ready(function () {

    $(".ms-sbgo img").attr("id", "btnSearch");
    $("#btnSearch").addClass("rollover");
    $("#btnSearch").addClass("ms-sbgo-bpv3");
    $("#btnSearch").removeAttr("onmouseover");
    $("#btnSearch").removeAttr("onmouseout");
    $("#btnSearch").attr("src", "/PublishingImages/btn_search_off.jpg");
    $("#printer_friendly").hide();

    /*if($("img[src*='btn-next']").length > 0)
    {
    var nextBtn = $("img[src*='btn-next']").parent().parent();
    $("img[src*='btn-next']").parent().parent().remove();
    $("<div id='nextButton'>"+ nextBtn.html() +"</div>").prependTo($("#byetta-isi"));
			

    }
    var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
    if(isIE6)
    {
    $("#bpv3_toolbar").prependTo($("#header"));
    $("#SRSB").appendTo($("#header"));
    $(".ms-sbscopes select").attr("visibility", "hidden");
    $("#searchContainer").css("display","none");
    $("#printHeader td:eq(1)").css("display","none");
    correctPNG();
    }
    */


    var imgID = "#" + getActiveStyleSheet().replace(" ", "-");
    if ($(imgID).attr("src")) {
        $(imgID).attr("src", $(imgID).attr("src").replace("_off", "_on"));
        $(imgID).unbind("mouseenter").unbind("mouseleave");
    }


    /*===================================
    -- Start Nav functionality
    =====================================*/

    var navID = "#nav" + $(".navName").attr("id");
    Navigation(navID);

    function Navigation(navID) {
        var navImg = $(navID + " a img:first");
        var navDiv = $(navID + " a span:first");
        if ($(navImg).length > 0 || $(navDiv).length > 0) {
            var activeNav = $(navID);
            var topNav = $(navID);
            while (!topNav.hasClass("topNav")) {
                if (!topNav.hasClass("sideNav")) {
                    if (topNav.hasClass("subSideNav")) {
                        if (topNav.find("img:first").length > 0) {
                            topNav.find("img:first").attr("src", topNav.find("img:first").attr("src").replace("_off", "_on"));
                            topNav.find("img:first").addClass("imgOn");
                            topNav = topNav.parent();
                            topNav.css("display", "block");
                        }
                        else {
                            topNav.find("div").addClass("divOn");
                            topNav = topNav.parent();
                            topNav.css("display", "block");
                        }
                    }
                    else {
                        if (topNav.find("img:first").length > 0) {
                            topNav.find("img:first").attr("src", topNav.find("img:first").attr("src").replace("_off", "_on"));
                            topNav.find("img:first").addClass("imgOn");
                        }
                        else {
                            topNav.find("div").addClass("divOn");
                        }
                    }
                }
                topNav.addClass("active");
                activeNav.find("a:first").addClass("active");
                topNav = topNav.parent();
            }

            var navHtml = $("#.active:first").parent().html();
            $("#sideNav").append(navHtml);
            $("#sideNav .subNav").css("display", "block");
            $("#sideNav .active").children().css("display", "block");
            if ($("#sideNav img:first").length > 0) {
                $("#sideNav img:first").attr("src", $("#sideNav img:first").attr("src").replace("topNav", "sideNav"));
                $("#sideNav img:first").attr("src", $("#sideNav img:first").attr("src").replace("png", "jpg"));
                $("#sideNav img:first").attr("src", $("#sideNav img:first").attr("src").replace("_off", "_on"));
                //code to switch to pulling alts for text sidenav
                //var sideNavText = $("#sideNav img:first").attr("alt");
                //$("#sideNav img:first").parents("a:first").html("<span class='sideNavTopReplace'>"+sideNavText+"</span>");
            }
            $("#sideNav .subNav div img").each(
            function () {
                $(this).attr("src", $(this).attr("src").replace("dropDown", "subNav"));
            });
        }
        else {
            //alert("div does not exist");
        }
    }



    $("#topNav div.topNav > div").each(function () { $(this).hover(function () { $(this).find('.sideNav').show(); }, function () { $(this).find('.sideNav').hide(); }); });
    $("#sideNav div").css("display", "block");
    $("#topNav div.topNav > div").css("display", "block");

    $(".rollover").each(function () {
        $(this).hover(
                function () { imgSwap($(this).get(0)); },
                function () { imgSwap($(this).get(0)); }
        );
    });
    $(".imgOn").unbind('mouseenter').unbind('mouseleave');


});

/*===================================
-- End site jQuery
=====================================*/



function imgSwap(oImg) {
    var strOver = "_on";
    var strOff = "_off";
    var strImg = oImg.src;
    if (strImg.indexOf(strOver) != -1)
        oImg.src = strImg.replace(strOver, strOff)
    else
        oImg.src = strImg.replace(strOff, strOver)
}

/*===================================
-- End Nav functionality
=====================================*/

/*===================================
-- Start FAQ accordion
=====================================*/
$(document).ready(function () {
    $('div#faqSlider div> div').hide();
    $('div#faqSlider div> h4').toggle(
              function () {
                  $("span", this).removeClass('accordionArrowOff');
                  $("span", this).addClass('accordionArrowOn');
                  $(this).next('div').slideToggle('fast');
              },
              function () {
                  $("span", this).removeClass('accordionArrowOn');
                  $("span", this).addClass('accordionArrowOff');
                  $(this).next('div').slideToggle('fast');
              }
        );

    $('div#faqSlider2 div> div').hide();
    $('div#faqSlider2 div> h4').toggle(
              function () {
                  $("span", this).removeClass('accordionArrowOff');
                  $("span", this).addClass('accordionArrowOn');
                  $(this).next('div').slideToggle('fast');
              },
              function () {
                  $("span", this).removeClass('accordionArrowOn');
                  $("span", this).addClass('accordionArrowOff');
                  $(this).next('div').slideToggle('fast');
              }
        );

});

/*===================================
-- End FAQ accordion
=====================================*/

/*===================================
-- Begin IE 6 issues
====================================*/

$(document).ready(function () {

    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
        //$('#printHeader table tbody tr td:last-child').css('position','absolute');
        //$('#bpv3_toolbar').css({'position' : 'absolute', 'top' : '65px', 'left' : '900px', 'width' : '125px'});
        //$('#searchContainer').css({'position' : 'absolute', 'top' : '65px', 'left' : '900px', 'margin-left' : '75px', 'margin-top' : '25px'});

    }

});
/*===================================
-- End IE 6 issues
====================================*/

/*===================================
-- Begin Popup Window
====================================*/

//Video Popup
var modalWindow;

function popPage(source, width, height) {
    if (width == null)
        width = 600;
    if (height == null)
        height = 400;
    modalWindow.windowId = "Modal";
    modalWindow.width = width;
    modalWindow.height = height;
    modalWindow.content = "<iframe allowTransparency='true' width='" + width + "' height='" + height + "' frameborder='0' scrolling='no' src='" + source + "'></iframe>";
    modalWindow.open();
};

modalWindow = {
    parent: "body",
    windowId: null,
    content: null,
    width: null,
    height: null,
    close: function () {
        $(".modal-window").remove();
        $(".modal-overlay").remove();
    },
    open: function () {
        //margin-top:-" + (this.height / 2) + "px;
        var modal = "";
        modal += "<div id=\"modalBack\" class=\"modal-overlay\" onmousewheel=\"return false;\"></div>";
        modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"position:absolute;width:" + this.width + "px; height:" + this.height + "px; margin-top:0px;  margin-left:-" + (this.width / 2) + "px;\">";
        modal += this.content;
        modal += "</div>";

        $(this.parent).append(modal);

        /* adds a button to the html, button is now in flash, so HTML button is unnecessary */
        var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
        if (isIE6) {
            $(".modal-window").append("<div style=\"position:absolute;bottom:357px;left:437px;\"><a class=\"close-window\" href=\"#\">CLOSE</a></div>");
        }


        $(".close-window").click(function () { modalWindow.close(); });
        $(".modal-overlay").click(function () { modalWindow.close(); });
    }
};

function closePopup() {
    //modal exists in an iframe, for flash to call this, it must 
    //refere to the parent to close the modal. Otherwise closing can
    //be done by applying the above style .close-window
    parent.modalWindow.close();
}
/*===================================
-- End Popup Window
====================================*/

/*===================================
-- WhatExperts Experts Have to Say
====================================*/

function videoWindow(urlVid) {
    popupVideo = window.open(urlVid, "Video", "location=no,status=no,scrollbars=no,width=430,height=390");
    popupVideo.moveTo(0, 0);
}

function videoMOA() {
    popupVideo = window.open("/Pages/video_moa.aspx", "Video", "location=no,status=no,scrollbars=no,width=884,height=546");
}

function videoHolt() {
    popupVideo = window.open("/Pages/video_holt.aspx", "Video", "location=no,status=no,scrollbars=no,width=640,height=522");
}


/*===================================
-- End WhatExperts Experts Have to Say
====================================*/

/*===================================
-- Pen Tutorial
====================================*/

function popupTutorial() {
    window.open("/Pages/selectTutorial.aspx", "Video", "location=no,status=no,scrollbars=no,width=600,height=420");
}

function popupPenNeedles() {
    window.open("/Documents/info/pop_needle_info.html", "PenNeedles", "location=no,status=no,scrollbars=no,width=370,height=400");
}
