﻿$(function () {
    $('.dropdown li').each(function () {
        var minWidth = 12;
        var maxWidth = 25;

        $(this).children('ul').each(function () {
            var $$ = $(this);

            $$.prev('a').addClass('haschildren');
        });
    });

    $('.dropdown > li').hover(function () {
        $('.dropdown > li').find('ul').stop(true, true).parent().removeClass('over').css("z-index", "");
        $(this).children('a').addClass('over');
        if ($(this).children('ul').length > 0) {
            $(this).children('ul')
            .animate({ "height": "hide" }, 2000)
            .animate({
                "height": "show",
                "opacity": "show"
            }, "slow", "swing", function () {
                $(this).parent().addClass('over');

                $(this).css({ "height": "", "opacity": "", "display": "" });
            });
        } else {
            $(this).addClass('over');
        }

    }, function () {
        $(this).children('ul').stop(true, false);
        $(this).children('a').removeClass('over');
        if ($(this).children('ul').length > 0) {
            $(this).children('ul')
                .animate({ "height": "show" }, 5000)
                .animate({
                    "height": "hide",
                    "opacity": "hide"
                }, "slow", "swing", function () {
                    $(this).parent().removeClass('over');
                    $(this).css({ "height": "", "opacity": "", "display": "" });
                });
        } else {
            $(this).removeClass('over');
        }
    });

    // 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");

    });
    $(document).ready(function () {
        // Reset Font Size
        var originalFontSize = $('.clr p').css('font-size');
        $(".resetFont").click(function () {
            $('.clr p').css('font-size', originalFontSize);
        });
        // Increase Font Size
        $(".increaseFont").click(function () {
            var currentFontSize = $('.clr p').css('font-size');
            var currentFontSizeNum = parseFloat(currentFontSize, 10);
            var newFontSize = currentFontSizeNum * 1.2;
            $('.clr p').css('font-size', newFontSize);
            return false;
        });
        // Decrease Font Size
        $(".decreaseFont").click(function () {
            var currentFontSize = $('.clr p').css('font-size');
            var currentFontSizeNum = parseFloat(currentFontSize, 10);
            var newFontSize = currentFontSizeNum * 0.8;
            $('.clr p').css('font-size', newFontSize);
            return false;
        });
    });
});
