$(function() {
    $(".project").hover(function() {
        $(this).addClass("hover");
    }, function() {
        $(this).removeClass("hover");
    });


    if ($('.slideshow .images img').length > 1) {
        $('.slideshow').hover(
            function() { $('.controls').fadeIn(); },
            function() { $('.controls').fadeOut(); }
        );
        $('.images').cycle({
            fx: 'fade',
            speed: '750', 
            timeout: 4000, 
            pause: 0,
            next: '.controls .next', 
            prev: '.controls .prev'
        });

        var resumeImage = $('.controls .pause').attr("name"),
            pauseImage = $('.controls .pause').attr("src");
        $('.controls .pause').toggle(function() {
            $('.images').cycle('pause');
            $(this).attr({ src: resumeImage });        
        }, function() {
            $('.images').cycle('resume');
            $(this).attr({ src: pauseImage });
        });
    }

    $(".contactEmail").click(function() {
        $.colorbox({ 
            href: $(this).attr("name"),
            overlayClose: false,
            scrolling: false,
            onComplete: function() {
                $("#emailContactForm").ajaxForm({
                    success: function(response) {
                        if (response.success) {
                            $("#emailContactForm").html("<h3>Your message has been sent.</h3>");
                            setTimeout(function() { $.colorbox.close(); }, 3000);
                        }
                        else if (response.error == "send error") {
                            $("#emailContactForm").prepend('<ul class="errorlist"><li>'+response.message+'</li></ul>');
                        }
                        else {
                            $("#emailContactForm .formFields").html($(response.form).find(".formFields"));
                        }
                        $.colorbox.resize();
                    },
                    dataType: "json"
                });
            }
        });
        return false;
    });
});

