function showResponse(responseText, statusText) {
    if (!responseText.match(/^Invalid data/i)) {
        $('#response').hide();
        $('#button_back').hide();
        $('#success').html(responseText);
        $('#success').show();
    } else {
        $('#success').hide();
        $('#response').html(responseText);
        $('#response').show();
    }
    $('#form_step4').fadeIn();
}

function showEmploymentResponse(responseText, statusText) {
    if (!responseText.match(/^Invalid data/i)) {
        $('#result').hide();
        $('#employment').hide();
        $('#success_msg').show();
    } else {
        $('#result').html(responseText);
        $('#result').fadeIn();
    }
}

function showContactResponse(responseText, statusText) {
    if (!responseText.match(/^Invalid data/i)) {
        $('#result').hide();
        $('#contact').hide();
        $('#success_msg').show();
    } else {
        $('#result').html(responseText);
        $('#result').fadeIn();
    }
}

$(document).ready(function() {
    $(".lavaLamp").lavaLamp({ fx: "backout", speed: 700 })
    
    $('#form_step2').hide();
    $('#form_step3').hide();
    $('#form_step4').hide();
    $('#response').hide();
    $('#success').hide();

    $('#button_step1').html('');
    $('#button_step2').html('');
    $('#button_step3').html('');
    $('#button_back').html('');
    
    $('#button_step1').bind('click', function(){
        $('#form_step1').hide();
        $('#button_step1').hide();
        $('#form_step2').fadeIn();
    });

    $('#button_step2').bind('click', function(){
        $('#form_step2').hide();
        $('#button_step2').hide();
        $('#form_step3').fadeIn();
    });
    
    $('#button_step3').bind('click', function(){
        $('#form_step3').hide();
        $('#button_step3').hide();
    });
    
    $('#button_back').bind('click', function(){
        $('#form_step4').hide();
        $('#form_step1').fadeIn();
        $('#button_step1').show();
        $('#button_step2').show();
        $('#button_step3').show();
    });
    
    $('#party_planner').ajaxForm({
        target: '#response',
        success: showResponse
    });
    
    $('#employment').ajaxForm({
        target: '#result',
        success: showEmploymentResponse
    });
    
    $('#contact').ajaxForm({
        target: '#result',
        success: showContactResponse
    });
    
    $('#testimonials').cycle({
        fx: 'fade',
        speed: 700,
        timeout: 4000,
        next: 'testimonials',
        pause: 1
    });
});
