$(document).ready(function() {
Cufon.replace('.gothic,.whiteBtn,#mainnav li a,h1,h2,.orange-box h3,.gray-box h3,h5,h6', { fontFamily: 'Century Gothic' });
    $('.blue-textbox').watermark('blue-textbox-white', 'Skriv i din E-postadress...');
    $(".three-columns-list li").each(function() {
        var index = $(".three-columns-list li").index($(this)) + 1;
        if (index % 3 == 0) {
            $(this).css('margin', '0');
        }
    });

    $("a").each(function(intIndex) {
        var newurl = $(this).attr("href").replace("(at)", "@");
        $(this).attr("href", newurl);
    });

    $('a').click(function() {
        if ($(this).attr('href') == '#') {
            $(this).parent().next('ul').toggle();
            return false
        }

    });

    $('#searchForm').submit(function() {
        var email = $(this).find('input[type=text]').val();
        $('#subscribe-confirm').hide();
        if (!(checkEmail(email))) {
            $('#subscribe-confirm').html('Du m&aring;ste ange en korrekt e-postadress');
            $('#subscribe-confirm').show();
            return false
        }
        $('#ok').attr('disabled', 'true');
        $('#ok').css('moz-opacity:', '.50');
        $('#ok').css('filter', 'alpha(opacity=50)');
        $('#ok').css('opacity', '.50');
        $('#subscribe-confirm').show();
        $.ajax({
            type: 'POST',
            url: '/subscribe.ashx',
            data: 'email=' + email,
            success: function(msg) {
                $('#subscribe-confirm').html(msg);
                $('#subscribe-confirm').show();
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                $('#subscribe-confirm').html(textStatus);
                $('#subscribe-confirm').show();
            }
        });

        return false
    });

});
function checkEmail(email) {
    var pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if (pattern.test(email)) {
        return true
    }
    return false
}
(function($) {
    $.fn.watermark = function(css, text) {
        
        $(this).focus(function() {
            $(this).filter(function() {
                return $(this).val() == "" || $(this).val() == text
            }).removeClass(css).val("");
        });

        $(this).blur(function() {
            $(this).filter(function() {
                return $(this).val() == ""
            }).addClass(css).val(text);
        });

        var input = $(this);
        $(this).closest("form").submit(function() {
            input.filter(function() {
                return $(this).val() == text
            }).val("");
        });

        $(this).addClass(css).val(text);
    };
})(jQuery);
