$(document).ready(function(){
    $('div.class-img').bind({
        mouseenter: function(){
            $(this).children('a').animate({'opacity': 0});
            $(this).children('.info').animate({'opacity': 0});
            // $(this).find('.class-blurb p').animate({'opacity': 1})
        },
        mouseleave: function(){
            $(this).children('a').animate({'opacity': 1});
            $(this).children('.info').animate({'opacity': 1});
            
            // $(this).find('.class-blurb p').animate({'opacity': 0})
        }
    });
    
    $('#letter-email').click(function(e){
        $this = $(this);
        if ($this.val() == 'email address'){
            $this.val('');
        }
    });
    
    $('#letter-signup').click(function(e){
        e.preventDefault();
        var data = $('#newsletter').serializeArray();
        $.ajax({
            type: 'POST',
            data: data,
            url: jsonVars.templateDir+'/mailchimp.php',
            success: function(data){
                console.log('success'+data);
                if (data.match('Returned: 1')){
                    $('#newsletter-response').addClass('success').text('Subscription Successful, Thank You.').fadeIn();
                    $('#letter-email').val('');
                } else {
                    $('#newsletter-response').addClass('error').text('Sorry, there was an error: '+data.match(/Msg=.*/gi)).fadeIn();
                }
            },
            error: function(data){
                console.log('error'+data);
            }
        })
    });
    
    // show loading gif on ajax send
    $('#loading').bind('ajaxStart', function(){
        $(this).fadeIn();
    });
    // hide loading gif on ajax stop
    $('#loading').bind('ajaxStop', function(){
        $(this).fadeOut();
    });
    
    // fade in the color of the logo.
    $('#logo').mouseenter(function(e){
        e.preventDefault();
        $(this).animate({color: '#e74100'}, 'fast');
    })
    $('#logo').mouseleave(function(e){
        e.preventDefault();
        $(this).animate({color: '#000'});
    })
    
    // fade in the color of the signup.
    $('#letter-signup').mouseenter(function(e){
        e.preventDefault();
        $(this).animate({'background-color': '#e74100', 'border-color': '#e74100'}, 'fast');
    })
    $('#letter-signup').mouseleave(function(e){
        e.preventDefault();
        $(this).animate({'background-color': '#000', 'border-color': '#000'});
    })
    
});
