﻿$(document).ready(function () {

    // This is the simplified img hover script
    $('img[hvr]').hover(function () {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hvr'));
        $(this).attr('hvr', currentImg);
    }, function () {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hvr'));
        $(this).attr('hvr', currentImg);
    });

    // This adds a watermark to the textbox using the ToolTip attribute for <asp:TextBox or the Title attribute on input.
    $("input[title]").each(function () {
        if ($(this).attr('title') != '') {
            $(this).val($(this).attr('title'));
            $(this).addClass("water");
        }
    }).focus(function () {
        if ($(this).val() == $(this).attr('title')) {
            $(this).val("");
            $(this).removeClass("water");
        }
    }).blur(function () {
        if ($.trim($(this).val()) == "") {
            $(this).val($(this).attr('title'));
            $(this).addClass("water");
        }
    });

    // Autocreate captions for images.
    $("img[longdesc]").each(function () {

        $(this).wrap('<div class="autoImage" />');
        $(this).after('<div class="autoImageCaption">' + $(this).attr('longdesc') + '</div>');
        $(this).parent().attr('style', $(this).attr('style')).attr('class', $(this).attr('class'));
        $(this).removeAttr("style").removeAttr("class");

    });

    $("a[href^=http://]").each(function () {
        var rexcludedomains = new RegExp(window.location.hostname, "i");
        if (this.hostname.search(rexcludedomains) == -1)
            $(this).attr("target", "_blank");
    });

    $("a[rel*=external], a[href$=.pdf]").each(function () {
        $(this).attr("target", "_blank");
    });
});
