﻿
var cycle1;
var cycle2;
var cycle3;

$(document).ready(function () {

    // Set the fade for the FAQ
    //if (location.href.indexOf("default.aspx") > -1) {
    //$('.faqPanel').css({ opacity: 0.8 });
    //$('.faqPanel').fadeTo("fast", 0.82);
    //$('.faqPanel .assistance.sub img').fadeTo("fast", 1);
    //}

    // Set the dropdown menu
    $('ul#main-menu li').hover(
        function () {
            $('ul', this).slideDown(100);
            $(this).parent().css('margin-bottom', '-30px');
        },
        function () {
            $('ul', this).slideUp(100);
        }
    );

    // Store the cycle slideshow html
    cycle1 = $('.banner-cycle .cycle1').html();
    cycle2 = $('.banner-cycle .cycle2').html();
    cycle3 = $('.banner-cycle .cycle3').html();

    // Set buttons on slideshow
    //    $('.cycle-map area').click(function () {
    //        //$('.banner-cycle').cycle('stop');
    //        alert('in button event');
    //        var newHtml = "";
    //        switch ($(this).attr('data-cycle')) {
    //            case 'cycle1':
    //                newHtml = cycle1;
    //                break;
    //            case 'cycle2':
    //                newHtml = cycle2;
    //                break;
    //            case 'cycle3':
    //                newHtml = cycle3;
    //                break;
    //        }
    //        alert(newHtml);
    //        $('.banner-cycle').html(newHtml);
    //    });

    // Set cycle
    $(".banner-cycle").cycle({
        fx: 'fade',
        pause: 10,
        timeout: 3000,
        speed: 3000
    });

    $(".toggle-audience").click(toggleSite);


    // Set search box
    $(".dob-textbox").focus(function () {
        if ($(this).attr("value") == "MM/DD/YYYY") {
            $(this).attr("value", "");
        }
    });
    $(".dob-textbox").blur(function () {
        if ($(this).attr("value") == "") {
            $(this).attr("value", "MM/DD/YYYY");
        }
    });


    // Set search box
    $(".search-textbox").focus(function () {
        if ($(this).attr("value") == "Search") {
            $(this).attr("value", "");
        }
    });
    $(".search-textbox").blur(function () {
        if ($(this).attr("value") == "") {
            $(this).attr("value", "Search");
        }
    });

    // Print page
    $("#header .right .search-bar a.text.print-page").click(function () {
        window.print();
        return false;
    });

    $(".text-size").click(function () {
        changeTextSize($(this).attr("data-bodycss"));
    });

    // Text size hover
    $(".search-bar a img").hover(
        function () {
            $(this).attr("src", "/images/a_hover.gif");
        },
        function () {
            if (!$(this).hasClass("selected"))
                $(this).attr("src", "/images/a.gif");
        }
    );

    // Search
    $(".search-textbox").bind("keypress", function (e) {
        if (e.keyCode == "13") {
            location.href = "610-search-results.aspx?q=" + $(this).val();
            return false;
        }
    });
    $(".search-button").click(function () {
        location.href = "610-search-results.aspx?q=" + $(".search-textbox").val();
    });

    // update text size based on users previous choice
    var tSize = readCookie('textSize');
    if (tSize)
        changeTextSize(tSize);
    else
        changeTextSize('medium');

    // set FENTORA to italic/bold (test)
    //$('body').each(function () {
    //    var newHtml = $(this).html().replace("<em>FENTORA</em>", "FENTORA");
    //    $(this).html(newHtml);
    //});

});


function toggleSite() {

    if (document.URL.indexOf("/patient/") >= 0) {
        $.colorbox({ width: "560px", height: "380px", href: "/hcp_confirm.aspx", iframe: true, open: true });
    }
    else {
        location.href = "/patient/000-default.aspx";
    }

}

function selectSlide(cycle) {
    $('.banner-cycle').cycle('stop');
    var newHtml = "";
    switch (cycle) {
        case 'cycle1':
            newHtml = cycle1;
            break;
        case 'cycle2':
            newHtml = cycle2;
            break;
        case 'cycle3':
            newHtml = cycle3;
            break;
    }
    $('.banner-cycle').html(newHtml);
}



function openNewWin(url) {
    var x = window.open(url, 'mynewwin', 'width=600,height=600,toolbar=1');
};


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;
};



function changeTextSize(tSize) {

    $("#bodyCopy").removeClass("small");
    $("#bodyCopy").removeClass("medium");
    $("#bodyCopy").removeClass("large");

    $("#isiWrapper").removeClass("small");
    $("#isiWrapper").removeClass("medium");
    $("#isiWrapper").removeClass("large");

    $("#bodyCopy").addClass(tSize);
    $("#isiWrapper").addClass(tSize);

    createCookie("textSize", tSize, 0);

    $(".text-size img").attr("src", "/images/a.gif");
    $(".text-size img").removeClass("selected");

    $(".text-size." + tSize + " img").attr("src", "/images/a_hover.gif");
    $(".text-size." + tSize + " img").addClass("selected");

};


function slideshowHover(area) {
    var imageElement = $(area).parent().prev();
    var imageSource = imageElement.attr('src');
    if (imageSource.indexOf('_hover') > -1)
        imageSource = imageSource.replace('_hover', '');
    else
        imageSource = imageSource.replace('.jpg', '_hover.jpg');
    imageElement.attr('src', imageSource);
}

//function slideshowHover(selector) {
//    alert('in slideshow hover');
//    var imageElement = $(selector);
//    alert(imageElement);
//    var imageSource = imageElement.attr('src');
//    alert(imageElement.parent().html());
//    if (imageSource.indexOf('_hover') > -1) {
//        // Revert to non-hover state
//        imageSource = imageSource.replace('_hover', '');
//    }
//    else {
//        // Set to hover state
//        imageSource = imageSource.replace('.jpg', '_hover.jpg');
//    }
//    alert(imageSource);
//    imageElement.attr('src', imageSource);
//}



