﻿// Menu JS ---------------------
var timeout = 500;
var closetimer = 0;
var zoomenuitem = 0;
function zoo_open() {
    zoo_canceltimer();
    zoo_close();
    zoomenuitem = $(this).find('ul').eq(0).css('display', 'block');
}
function zoo_close()
{ if (zoomenuitem) zoomenuitem.css('display', 'none'); }
function zoo_timer()
{ closetimer = window.setTimeout(zoo_close, timeout); }
function zoo_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}
document.onclick = zoo_close;
// ------------------------------

// Change the fonts
function changeFont(size) {
    $(".content-main #content h2:not(.nochange, .subheader)").css("font-size", (15 + parseInt(size)) + "px");
    $(".content-main #content h2:not(.nochange, .subheader)").css("line-height", (18 + parseInt(size)) + "px");

    $(".content-main #content h3:not(.nochange, .subheader, .subeyebrow)").css("font-size", (14 + parseInt(size)) + "px");
    $(".content-main #content h3:not(.nochange, .subheader, .subeyebrow)").css("line-height", (16 + parseInt(size)) + "px");

    $(".content-main #content p:not(.nochange, .intro)").css("font-size", (13 + parseInt(size)) + "px");
    $(".content-main #content p:not(.nochange, .intro)").css("line-height", (18 + parseInt(size)) + "px");
    $(".content-main #content .references p:not(.nochange, .intro)").css("font-size", (12 + parseInt(size)) + "px");

    $(".content-main #content a:not(.nochange)").css("font-size", (13 + parseInt(size)) + "px");
    $(".content-main #content a:not(.nochange)").css("line-height", (18 + parseInt(size)) + "px");
    $(".content-main #content a.lg-link:not(.nochange)").css("font-size", (14 + parseInt(size)) + "px");
    $(".content-main #content .references a:not(.nochange)").css("font-size", (13 + parseInt(size)) + "px");

    $(".content-main #content li:not(.nochange)").css("font-size", (13 + parseInt(size)) + "px");
    $(".content-main #content li:not(.nochange)").css("line-height", (18 + parseInt(size)) + "px");
    $(".content-main #content .references li:not(.nochange)").css("font-size", (13 + parseInt(size)) + "px");

    $(".content-main #content span:not(.nochange)").css("font-size", (13 + parseInt(size)) + "px");
    $(".content-main #content span:not(.nochange)").css("line-height", (18 + parseInt(size)) + "px");
    $(".content-main #content .references span:not(.nochange)").css("font-size", (13 + parseInt(size)) + "px");

    $(".content-main #content sup:not(.nochange)").css("font-size", (9 + parseInt(size)) + "px");
    $(".content-main #content .references sup:not(.nochange)").css("font-size", (9 + parseInt(size)) + "px");
    
    $.cookie('txtSize', size);
}

// Document JS ------------------
$(document).ready(function() {

    // Nav and various dropdowns
    $('#nav-main ul.menu > li.selectedMenuItem').bind('mouseover', zoo_open);
    $('#nav-main ul.menu > li.selectedMenuItem').bind('mouseout', zoo_timer);
    $('#spec-menu > li').bind('mouseover', zoo_open);
    $('#spec-menu > li').bind('mouseout', zoo_timer);

    // Dropdown nav
    $('#quint_dropdown').change(function() {
        if ($('#quint_dropdown option:selected[value]').attr('value') != "-- Select a Page --") {
            document.location = $('#quint_dropdown option:selected').attr('value');
        }
    });

    // HP-Accordian
    if ($("#HP-Accordian a.first").hasClass("selected")) {
        $("#HP-Accordian_top").css("background-image", "url(/Content/images/default/accordion/top_cap_on.gif)");
    }
    $("#HP-Accordian a.first").hover(function() {
        $("#HP-Accordian_top").css("background-image", "url(/Content/images/default/accordion/top_cap_on.gif)");
    });
    $("#HP-Accordian a.head:not(.first)").hover(function() {
        $("#HP-Accordian_top").css("background-image", "url(/Content/images/default/accordion/top_cap_off.gif)");
    });
    $("#HP-Accordian").accordion({
        active: '.selected',
        header: '.head',
        navigation: false,
        event: 'mouseover',
        autoheight: false,
        animated: 'easeslide'
    });

    // ORC-Drawers
    if ($("#ORC-Drawers a.first").hasClass("selected")) {
        $("#ORC-Drawers_top").addClass("top_cap_on");
    } else {
        $("#ORC-Drawers_top").addClass("top_cap_off");
    }
    $("#ORC-Drawers a.first").hover(function() {
        $("#ORC-Drawers a.head").removeClass("prev");
        $("#ORC-Drawers_top").addClass("top_cap_on");
    });
    $("#ORC-Drawers a.head:not(.first)").hover(function() {
        $("#ORC-Drawers_top").removeClass("top_cap_on");
        $("#ORC-Drawers_top").addClass("top_cap_off");
    });
    $("#ORC-Drawers a.head:not(.selected)").hover(function(e) {
        $("#ORC-Drawers a.head").removeClass("prev");
        var $liabove = $(this).parent().prev();
        $liabove.find("a.head").addClass("prev");
    });
    $("#ORC-Drawers").accordion({
        active: '.selected',
        header: '.head',
        navigation: false,
        event: 'mouseover',
        autoheight: false,
        animated: 'slide'
    });

    // Font changer
    if ($.cookie('txtSize')) {
        changeFont($.cookie('txtSize'));
    }
    $("#lg-txt").click(function() {
        changeFont(2);
    });
    $("#md-txt").click(function() {
        changeFont(1);
    });
    $("#sm-txt").click(function() {
        changeFont(0);
    });

    // Tabs
    $('#prod_tabs').tabs();


    // Helpful Links
    $('#helpful-links a.help-link').click(function() {
        $(this).siblings('ul').toggle();
        $(this).toggleClass("clicked");
        return false;
    });

    // Get return url for links
    $('a.getURL').each(function() {
        $(this).attr('href', $(this).attr('href') + window.location);
    });

    // Do Search
    $('#site-search-form').submit(function(e) {
        e.preventDefault();
        var term = $('#search-term').attr('value');
        document.location = "http://www.novomedlink.com/search/?output=xml_no_dtd&client=FrontEnd_NovoMedLink&site=NovoMedLink&q=" + term;
    });
    $('#site-search-submit').click(function(e) {
        e.preventDefault();
        var term = $('#search-term').attr('value');
        document.location = "http://www.novomedlink.com/search/?output=xml_no_dtd&client=FrontEnd_NovoMedLink&site=NovoMedLink&q=" + term;
    });

    // Turn error text red if it contains error:
    $("div.messages:contains('error')").css("color", "#F00");

});

