﻿function luisgerminare() {
//Add Scroll
	$('#menu a').bind('click',function(event){
		var $anchor = $(this);
		$('html, body').stop().animate({
			scrollTop: $($anchor.attr('href')).offset().top}, 1500,'easeInOutExpo');
		/*  if you don't want to use the easing effects:
                  $('html, body').stop().animate({
                      scrollTop: $($anchor.attr('href')).offset().top
                  }, 1000);
		*/
		event.preventDefault();
	});	
    // Add fancybox functionality to gallery links
    $(".portfolio .gallery").fancybox({
	"titleShow"	: true,
	"titlePosition"	: "over",
	"transitionIn"	: "elastic",
	"transitionOut"	: "elastic"
    });

    // Add tiptip tooltip to sidebar link and any html links contain title attribute
     $("#menu a").tipTip({defaultPosition: "bottom"});
    //$(".portfolio").find("a").tipTip({defaultPosition:"top", edgeOffset:100}); 
    $("#social_icons a").tipTip({defaultPosition:"top", edgeOffset:10});
    $("[title]").tipTip({defaultPosition:"left"});

    // Set contact form with AJAX if JavaScript is present
    $("#contactform").attr("ACTION", "");

    $("#contact_name").focus(function(){
	if($(this).val() == "Nome") {
	    $(this).attr("value","");
	}
    });
    $("#contact_name").blur(function(){
	if($(this).val() == "") {
	    $(this).attr("value","Nome");
	}
    });
    $("#contact_mailfrom").focus(function(){
	if($(this).val() == "E-mail") {
	    $(this).attr("value","");
	}
    });
    $("#contact_mailfrom").blur(function(){
	if($(this).val() == "") {
	    $(this).attr("value","E-mail");
	}
    });
    $("#contact_subject").focus(function(){
	if($(this).val() == "Assunto") {
	    $(this).attr("value","");
	}
    });
    $("#contact_subject").blur(function(){
	if($(this).val() == "") {
	    $(this).attr("value","Assunto");
	}
    });

    $("#sendmail").click(function(){
	var validMsg = "";
	var contact_name = $("#contact_name").val();
	var contact_mailfrom = $("#contact_mailfrom").val();
	var contact_subject = $("#contact_subject").val();
	var contact_text = $("#contact_text").val();

	if(contact_name.length < 1 || contact_name == "Nome") { 
	    validMsg += "<li>Digite seu nome</li>";
	}

	if(!contact_mailfrom.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)  || contact_mailfrom == "E-mail") {
	    validMsg += "<li>Digite um e-mail válido</li>";
	}

	if(contact_subject.length < 1 || contact_subject == "Assunto") { 
	    validMsg += "<li>Digite um assunto</li>"; 
	}

	if(contact_text.length < 1) { 
	    validMsg += "<li>O que você gostaria de dizer?</li>"; 
	}

	if(validMsg != "") {
	    $("#response").html("<p>Erro: <ul class=\"disc\">"+validMsg+"</ul></p>"); 
	    $("#response").fadeIn("slow");
	    setTimeout("$(\"#response\").fadeOut(\"slow\")",3000);
	}
	else {
	    var datastr = "fromname=" + contact_name + "&mailfrom=" + contact_mailfrom + "&subject=" + contact_subject + "&msg=" + contact_text;
			datastr=datastr.replace(/\n/g, "\\n");
	    $("#response").css("display", "block");
	    $("#response").html("Enviando mensagem …. ");
	    $("#response").fadeIn("slow");
	    setTimeout("sendMsg(\'"+datastr+"\')",5000);
	}
	return false;
    });
}

// AJAX script to do HTTP POST to /php/mail.php to send mail from your site's web server
function sendMsg(datastr){
    $.ajax({
	type: "POST",
	url: "php/mail.php",
	data: datastr,
	cache: false,
	error: function(html){
	    $("#response").html("Desculpe, mas ocorreu algum erro ao enviar sua mensagem.\nNão se preocupe, você pode mandar um e-mail pra mim");
	    $("#response").fadeIn("slow");
	    setTimeout("$(\"#response\").fadeOut(\"slow\")",5000);
	},
	success: function(html){
	    $("#response").html(html);
	    $("#response").fadeIn("slow");
	    setTimeout("$(\"#response\").fadeOut(\"slow\")",5000);
	}
    });
}
