$('document').ready(function() {
    jQuery.fn.exists = function() { return jQuery(this).length > 0; }

    if ($(".share").exists()) {
        $(".share").click(function() {
            s.linkTrackVars = "events"
            s.linkTrackEvents = "event17"
            s.events = "event17"
            s.tl()
        });
    }
    if ($(".subscribe").exists()) {
        $(".subscribe").click(function() {
            s.linkTrackVars = "events"
            s.linkTrackEvents = "event19"
            s.events = "event19"
            s.tl()
        });
    }
    if ($(".print").exists()) {
        $(".print").click(function() {
            s.linkTrackVars = "events"
            s.linkTrackEvents = "event18"
            s.events = "event18"
            s.tl()
        });
    }


    // FIX FOR IMAGE CAPTIONS WIDTHS - Thank you Kenny Meyers!
$(".graphic img").each(function(i) {
var self = $(this);
$(this).parents(".graphic")
.css("width", self.attr("width") + "px")
.end()
.next(".caption")
.css("width", self.attr("width") + "px");
});

    // FIX FOR DROP DOWN MENU'S IN IE6 OVERLAYING THE MODAL
    if ($(".TB_overlayBG").exists()) {
        $('.TB_overlayBG').bgiframe();
    }

    // HEADER TITLE SHRINKING CLASS - 45 CHARS
    if ($("H1").text().length >= 45) {
        $("#pageTitle").addClass("longTitle");
    }

    // GLOSSARY TERMS
    $("span.glossaryTerm").after("<div style=\"display: none;\" class=\"tooltip relative\"><div class=\"top\"></div><div class=\"toolTipContent\"><h5></h5><p></p></div></div>");

    var x = "";
    var y = "";

    $().mousemove(function(e) {
        x = e.pageX;
        y = e.pageY;
    });

    $("span.glossaryTerm").mouseover(function(ev) {
        var innerText = $(this).html();

        $(this).next('div').fadeIn('fast');


        var p = $(this);
        var offset = p.position();
        $(this).next('div').css({ top: offset.top + 22 + 'px', left: offset.left - 110 + 'px' });

        $.ajax({
            type: "GET",
            url: "/webservices/get-term.aspx",
            data: "t=" + escape(innerText),
            success: function(desc) {
                $(".toolTipContent").html(desc);
            }
        });
    });
    $(".glossaryTerm").mouseout(function() {
        $('.tooltip').fadeOut('fast');
    });
    // ------------------------------ END GLOSSARY TERM -----------------------------------------

    //run tooltips on 'updated' labels
    $('.share a').click(function() {
        $('.shareTip').fadeIn('fast');
    })
    $('.submitButton').click(function() {
        $('.form').fadeOut('fast');
    })

    $('.addthis_toolbox ul li a, #closeBtn').click(function() {
        $('.shareTip').fadeOut('fast');
    })


    //run tooltips on 'updated' labels
    $('.updated').mouseover(function() {
        $('.tooltip', $(this).parent()).fadeIn('fast');
    })
    $('.updated, .tooltip').mouseout(function() {
        $('.tooltip', $(this).parent()).fadeOut('fast');
    })


    //Activate input text hinting
    //Find all the input elements with title attributes
    $('input[title!=""]').hint();

    //Hide skip to content link
    $('#skip').hide();

    //Text resize

    // Reset Font Size
    $('#utilityNav .textSizer .normal').click(function() {
        $('body').css('font-size', '62.5%');
        $('#utilityNav .textSizer li').children('a').removeClass('active');
        $(this).children('a').addClass('active');

        $('a.button').removeClass("noBackground");
        $('#utilityNav').css('font-size', '100%');
        return false;
    });

    // Set Large Font Size
    $('#utilityNav .textSizer .large').click(function() {
        $('body').css('font-size', '95%');
        $('#utilityNav .textSizer li').children('a').removeClass('active');
        $(this).children('a').addClass('active');

        $('a.button').addClass("noBackground");
        $('#utilityNav').css('font-size', '65%');
        return false;
    });

    // Set Small Font Size
    $('#utilityNav .textSizer .small').click(function() {
        $('body').css('font-size', '50%');
        $('#utilityNav .textSizer li').children('a').removeClass('active');
        $(this).children('a').addClass('active');

        $('a.button').removeClass("noBackground");
        $('#utilityNav').css('font-size', '90%');
        return false;
    });

    //Feature panel contrlls
    $('#panelLinks li').click(function() {
        $(this).toggleClass('active');
        return false;
    });

    //Add dividers to breadcrumbs
    $('#breadCrumbs li a').each(function() {
        $(this).after("<span class=\"divider\">&nbsp;&gt;</span>");
    });


    //For Patients and Famlies funcitonality
    $('#knowAbout div.child div').hover(
			function() {
			    $(this).css('background-image', 'url("/img/bg_for_pf_hover.jpg")');
			    $(this).children('p').show();
			},
			function() {
			    if ($(this).hasClass('childsVisit')) {
			        $(this).css('background-image', 'url("/img/bg_for_pf_childs_visit.jpg")');
			    }
			    else if ($(this).hasClass('childsStay')) {
			        $(this).css('background-image', 'url("/img/bg_for_pf_childs_stay.jpg")');
			    }
			    else if ($(this).hasClass('childsSurgery')) {
			        $(this).css('background-image', 'url("/img/bg_for_pf_childs_surgery.jpg")');
			    }
			    $(this).children('p').hide();
			}
		);
    //UWPeds funcitonality
    $('#knowAbout div.child div').hover(
			function() {
			    $(this).css('background-image', 'url("/img/bg_for_pf_hover.jpg")');
			    $(this).children('p').show();
			},
			function() {
			    if ($(this).hasClass('uwPedsResidentLife')) {
			        $(this).css('background-image', 'url("/img/uwpeds-resident-life-up.jpg")');
			    }
			    else if ($(this).hasClass('uwPedsTraining')) {
			        $(this).css('background-image', 'url("/img/uwpeds-training-btn-up.jpg")');
			    }
			    else if ($(this).hasClass('uwPedsAboutUs')) {
			        $(this).css('background-image', 'url("/img/uwpeds-about-btn-up.jpg")');
			    }
			    $(this).children('p').hide();
			}
		);

    //Print button!
    $('#pageTools ul li.print a').click(function() {
        window.print();
        return false;
    });

    $('#flashNavReplace').hover(
			function() {

			},
			function() {
			    if (getFlashMovie("flashNavReplace") != null) {
			        getFlashMovie("flashNavReplace").jsCloseNavigation()
			    }
			});
    //Alert close box!

    $('#alert a.close').click(function() {
        $('#alert').hide();
        $('#home #utilityBar h2').show();
    });
});


function setFlashNavHeight(heightIn) {
    $('#flashNavReplace').height(heightIn);
}

function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
    
}

$(document).ready(function() {
    // hides the slickbox as soon as the DOM is ready
    // (a little sooner than page load)
    $('#prSearchFilter').hide();
    $('#prOuterExpand').hide();
    // toggles the slickbox on clicking the noted link
    $('a#selectMonth').click(function() {
        $(this).toggleClass('active');
        $('#prSearchFilter').slideToggle(400);
        $('#prOuterExpand').slideToggle(400);
        return false;
    });
});

// prepare the form when the DOM is ready 
$(document).ready(function() {
    var options = {
        target: '#ajaxResponse',   // target element(s) to be updated with server response 
        beforeSubmit: showRequest,  // pre-submit callback 
        success: showResponse  // post-submit callback 
    };

    // bind to the form's submit event 
    $('.submit').click(function() {
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options);

        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false;
    });
});

// pre-submit callback 
function showRequest(formData, jqForm, options) {
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData);
    return true;
}

// post-submit callback 
function showResponse(responseText, statusText) {

    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
			        '\n\nThe output div should have already been updated with the responseText.');
}

$(document).ready(function() {
    $('.pulldown').change(function() {
        $('#filterSelectAMonth option:checked').val();
    });
});

$(document).ready(function() {
    // hides the slickbox as soon as the DOM is ready
    // (a little sooner than page load)
    $('#searchFilter').hide();
    $('#outerExpand').hide();
    // toggles the slickbox on clicking the noted link
    $('a#reviseResults').click(function() {
        $(this).toggleClass('active');
        $('#searchFilter').slideToggle(400);
        $('#outerExpand').slideToggle(400);
        return false;
    });
});
// prepare the form when the DOM is ready 
$(document).ready(function() {
    var options = {
        target: '#ajaxResponse',   // target element(s) to be updated with server response 
        beforeSubmit: showRequest,  // pre-submit callback 
        success: showResponse  // post-submit callback 

    };

    // bind to the form's submit event 
    $('#formSearchFilter').submit(function() {
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options);

        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false;
    });
});

// pre-submit callback 
function showRequest(formData, jqForm, options) {
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData);

    return true;
}

// post-submit callback 
function showResponse(responseText, statusText) {

    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
			        '\n\nThe output div should have already been updated with the responseText.');
}

// LIGHTBOX
$(document).ready(function(){ $(".ceebox").ceebox();});