$(document).ready(function(){

    var $email = $("input#ea"),
    $form = $("#newsletter form");
    
    $email.val($email.attr('title'));
    
    // clear it out on focus
    $email.focus(function(){
        $(this).val("");
    });

    // if it's blank then reset back the title attribute
    $email.blur(function(){
        // alert($(this).val().length);
        if($(this).val().length < 1){
            $email.val($email.attr('title'));
        }
    });
    
    $form.submit(function(e) {
	    
        var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,
        $emailVal = $email.val();
        
        if ($emailVal == '' || $emailVal == 'email@domain.com') {
            // $email.addClass('error');
            alert('Please enter an email address');
            return false;
        } else if(!pattern.test($emailVal)) {
            // $email.addClass('error');
            alert('Please enter an valid email address');
            return false;
        }
       
        $form.find("button").replaceWith('<strong class="thank-you">Thank you.</strong>');
        
//        // Grab form action
//        formAction = $form.attr("action");
//
//        // Serialize form values to be submitted with POST
//        var str = $form.serialize();
//
//        // Add form action to end of serialized data
//        final = str + "&action=" + formAction;
//
//        // Submit the form via ajax
//        $.ajax({
//            url: "/cm-proxy",
//            type: "POST",
//            data: final,
//            success: function(data){
//                //Check to make sure that the email was accepted
//                if (data.search(/invalid/i) != -1) {
//                    alert('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.');
//                }
//                else
//                {
//
//                    $form.find('span').animate({
//                        opacity: 0
//                    }, 1000, null, function(){
//                        $(this).hide();
//                        $form.find('p').append('<strong>You have successfully subscribed</strong>');
//                        $form.find('strong').css({
//                            opacity: 0
//                        }).animate({
//                            opacity: 1
//                        });
//                    });
//                    $form.find('img.loading').animate({
//                        opacity: 0
//                    }, 1500);
//                }
//            }
//        });
//
//        e.preventDefault();
               
    });

    // equal heights on the ctas
    $('ul#ctas li a').each(function(){
        var currentTallest = 0;
        if ($(this).height() > currentTallest) {
            currentTallest = $(this).height();
        }
        if ($.browser.msie && $.browser.version == 6.0) {
            $(this).children().css({
                'height': currentTallest
            });
        }
        $('ul#ctas li a').css({
            'min-height': currentTallest
        });
    });
    
    // footer link
    $('#nixon a').attr('target', '_blank');
    $('.error-message').append('<p>There was a problem with your form. Please check the highlighted fields and try again.</p>').append('<ol id="messageBox"></ol>');
    
    $('#slideshow-panel').cycle({
        timeout: 6000
    });
    
});
