$(document).ready(function(){

// CUFON REPLACET
Cufon.replace('#logo');
Cufon.replace('#vali');
Cufon.replace('#navigaatio li a');
Cufon.replace('h2.trigger');
Cufon.replace('h2.down');

// Mustavalkoisesta värilliseksi
$("img").hover(
 function()
 {
  this.src = this.src.replace("_dark","_color");
 },
 function()
 {
  this.src = this.src.replace("_color","_dark");
 }
);

// Portfolio

$(".toggle_container").hide(); 
$("h2.trigger").toggle(function(){
$(this).addClass("down");
}, function () {
$(this).removeClass("down");
});

$("h2.trigger").click(function(){
$(this).next(".toggle_container").slideToggle("fast");
});


});

// AJAX FORMI

$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFF"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {

    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var message = $("textarea#message").val();
		if (message == "") {
      $("label#message_error").show();
      $("input#message").focus();
      return false;
    }
		
var dataString = '&name='+ name + '&email=' + email + '&message=' + message;

		
$.ajax({
      type: "POST",
      url: "palaute.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h3>Lomake lähetetty!</h3>")
        .append("<p>Otan yhteyttä mahdollisimman nopeasti!</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("");
        });
      }
     });
    return false;
});
});
