﻿$(function () {

    ie6 = $.browser.msie && ($.browser.version == "6.0") && !window.XMLHttpRequest;

    $(".dropdown dd").hover(function () {
        $(this).addClass("over");
        if (ie6) {
            $(".sec_maps select").hide();
        }

    },
    function () {
        $(this).removeClass("over");
        if (ie6) {
            $(".sec_maps select").show();
        }
    });

    $(".dropdown #mnAttractions, .dropdown #mnOutdoor").hover(function () {
        $(".sec_festivals_events_select").hide();
    },
    function () {
        $(".sec_festivals_events_select").show();
    });

    $('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);
    });

    $('.dropdown ul li a').hover(function () {
        $(this).animate({ marginLeft: "4" }, { duration: 200 });
    },
    function () {
        $(this).animate({ marginLeft: "0" }, { duration: 200 });
    });

    // 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");
        }
    });


});

jQuery.fn.counter = function () {

    $(this).each(function () {

        if ($(this))

            var max = $(this).attr('maxlength');
        var val = $(this).attr('value');
        var cur = 0;

        if (val)
            cur = val.length;

        var left = max - cur;

        $(this).after("<span class='charCounter'>" + left.toString() + "</span>");

        var c = $(this).next(".charCounter");

        $(this).keyup(function (i) {
            var max = $(this).attr('maxlength');
            var val = $(this).attr('value');
            var cur = 0;

            if (val)
                cur = val.length;

            var left = max - cur;

            $(this).next(".charCounter").text(left.toString());

            return this;
        });
    });
    return this;
}


jQuery.fn.countertextarea = function (set_max) {
    $(this).each(function () {

        var textarea = $(this).is('textarea');
        var max = set_max ? set_max : $(this).attr('maxlength');

        if (!max || max == 2147483647) { return; }

        var val = textarea ? $(this).val() : $(this).attr('value');
        var left = max - (val ? val.length : 0);

        $(this).after("<div class='counter'>" + left.toString() + "</div>");

        var c = $(this).next(".counter");
        c.width(40);
        c.css("position", "relative");
        c.css("top", -$(this).height() - 8);
        c.css("left", $(this).width() + 8);
        c.css("background", "yellow");
        $(this).keyup(function (e) {
            var val = textarea ? $(this).val() : $(this).attr('value');
            var left = max - (val ? val.length : 0);
            if (left < 0) {
                cutval = val.substr(0, max);
                textarea ? $(this).val(cutval) : $(this).attr('value', val);
                left = 0;
            }
            $(this).next(".counter").text(left.toString());
            return this;
        });
    });
    return this;
}