var focus_color = "#1f2946";
var blur_color = "#161D32";

$(document).ready(function(){
    bindBehaviors();
});

function sendEmail(){

    var first_name = $("#first_name").val();
    var last_name = $("#last_name").val();
    var email = $("#contact_email").val();
    var address = $("#address").val();
    var subject = $("#subject").val();
    var text = $("#text").val();
    var add_info = $("#add_info").val(); 
    
	$.post('index/send-email',{'first_name':first_name,'last_name':last_name,'email':email,'address':address,'subject':subject,'text':text,'add_info':add_info}, function(data){
		$('#form_contact_message').html(data);
		// this dude needs to be here, 'cause of the ajax created elements, so i can BIND events to them
		bindBehaviors();
	});
	
	return false;

}

function bindBehaviors(){

    if($("#sent-ok").length > 0){ resetContactForm(); }

    $('#form_contact_message').ajaxStart(function(){
        $(this).html("<p><img src='/img/ajax-loader.gif' /> Please wait, I'm sending your message...</p>");
    });
   
    $("#first_name")
        .focus(function(){
            $(".first_name").show(200);
            $(this).css("background-color",focus_color);
        })
        .blur(function(){
            $(".first_name").hide(200);
            $(this).css("background-color",blur_color);
        })
    ;

    $("#last_name")
        .focus(function(){
            $(".last_name").show(200);
            $(this).css("background-color",focus_color);
        })
        .blur(function(){
            $(".last_name").hide(200);
            $(this).css("background-color",blur_color);
        })
    ;
    
    $("#contact_email")
        .focus(function(){
            $(".contact_email").show(200);
            $(this).css("background-color",focus_color);
        })
        .blur(function(){
            $(".contact_email").hide(200);
            $(this).css("background-color",blur_color);
        })
    ;
    
    $("#address")
        .focus(function(){
            $(".address").show(200);
            $(this).css("background-color",focus_color);
        })
        .blur(function(){
            $(".address").hide(200);
            $(this).css("background-color",blur_color);
        })
    ;
    
    $("#subject")
        .focus(function(){
            $(".subject").show(200);
            $(this).css("background-color",focus_color);
        })
        .blur(function(){
            $(".subject").hide(200);
            $(this).css("background-color",blur_color);
        })
    ;
    
    $("#text")
        .focus(function(){
            $(".text").show(200);
            $(this).css("background-color",focus_color);
        })
        .blur(function(){
            $(".text").hide(200);
            $(this).css("background-color",blur_color);
        })
    ;

    $("#author")
        .focus(function(){
            $(this).css("background-color",focus_color);
        })
        .blur(function(){
            $(this).css("background-color",blur_color);
        })
    ;

    $("#email")
        .focus(function(){
            $(this).css("background-color",focus_color);
        })
        .blur(function(){
            $(this).css("background-color",blur_color);
        })
    ;

    $("#url")
        .focus(function(){
            $(this).css("background-color",focus_color);
        })
        .blur(function(){
            $(this).css("background-color",blur_color);
        })
    ;

    $("#comment")
        .focus(function(){
            $(this).css("background",focus_color);
        })
        .blur(function(){
            $(this).css("background",blur_color + " url(/img/sign-letters.gif) no-repeat right bottom");
        })
    ;

    $("#s")
        .focus(function(){
            $(this).val('');
            $(this).css("background-color",focus_color);
        })
        .blur(function(){

            $(this).css("background-color",blur_color);
        })
    ;
    
    
}

function resetContactForm(){

    $("#first_name").val('');

    $("#last_name").val('');
    
    $("#contact_email").val('');
    
    $("#address").val('');
    
    $("#subject").val('');
    
    $("#text").val('');

}