$(document).ready(function(){

    $('#sidebar .body').mouseover(function(){
        $(this).addClass('hover');
    }).mouseout(function(){
        $(this).removeClass('hover');
    });

    $('.reset').focus(function(){
        if (this.value === this.defaultValue) {
            this.value = '';
        }
    }).blur(function(){
        if (this.value === '') {
            this.value = this.defaultValue;
        }
    });
    
    $('a[rel="external"]').click(function (e) {
        e.preventDefault();
        window.open($(this).attr('href'));
    });

    $('#slideshow').backgroundSlider();

    $('#news-ticker').dbSlideshow({
        'target'        : 'div.item',
        'pauseButton'   : false,
        'autoResume'    : true,
        'debug'         : false
    });

    $('#newsletter a').click(function(e){
        e.preventDefault();
        $( "#newsletter-dialog" ).dialog("open");
    });
    
    $('#home-button').mouseover(function () {
        var img = $('img', this), src = img.attr('src'), re = new RegExp("(.+)\\.(gif|png|jpg)", "g");
        img.attr('src', src.replace(re, "$1_hover.$2"));
    }).mouseout(function () {
        var img = $('img', this), src = img.attr('src'), re = new RegExp("(.+)_hover\\.(gif|png|jpg)", "g");
        img.attr('src', src.replace(re, "$1.$2"));
    });
    function HoverImgOf(filename)
{
}

    $('#newsletter-dialog').dialog({
        autoOpen: false,
        height: 371,
        width: 470,
        modal: true,
        dialogClass: 'newsletter',
        title: 'Aanmelden voor de nieuwsbrief van Stad & Natuur Almere',
        resizable: false,
        draggable: false,
        open: function () {
            Cufon.replace('.ui-dialog-title');
            Cufon.replace('#newsletter-dialog h5');

            $('form', this).submit(function (e) {
                e.preventDefault();

                var $this = $(this), url = $this.attr('action'), post, error;

                $.each($this.find('input'), function () {
                    if (this.value === this.defaultValue) {
                        this.value = '';
                        error = true;
                    }
                });

                if (error === true) {
                    return false;
                }

                post = $this.serialize();

                $.post(url, post, function (html) {
                    
                    $('.ui-dialog-content').html(html);
                    Cufon.replace('#newsletter-dialog h5');

                    setTimeout(function(){
                        $('#newsletter-dialog').dialog('close');
                    }, 3000)

                    return true;
                });
                
                return true;
            });
        }
    });
});

Cufon.replace('h1');
Cufon.replace('h3');
Cufon.replace('#map ul li a span');
Cufon.replace('#topmenu a', {
    hover: true
});

Cufon.now();
