
function animLogo() {

	$("#header").hover(function(){			
		$("em",this).stop().animate({'opacity': '1' }, 1000);
	}, function() {
	    $("em",this).animate({'opacity':'0'}, 500);
	});
	// fin logo
}

function initPage() {
	
	// fadeIn de la page
	$('#section').animate({opacity: '0.7'},800).animate({opacity:'1'},1000);

	if (!$.support.opacity) {
			$('#section').css('filter','none');
		}
		
	// support pour IE, on passe document.URL dans le href
	var $liens_contact = $('.pagemenu a[href="./contact.php"], a.action[href="./contact.php"]');
	if(jQuery.support.hrefNormalized == false) { 
		$liens_contact.attr({
			href: 	document.URL + '#contact',
			id: 	function (nb) {
	          			return "inline-" + nb;
	        		}
			}); 
	} else { // liens pour form contact
		$liens_contact.attr({
			href: 	'#contact',
			id: 	function (nb) {
	          			return "inline-" + nb;
	        		}
			});	
	}

	// popup pour form de contact	
	$('a[id|="inline"]').fancybox({
		'overlayShow': true,
		'autoDimensions': true,
		'autoScale': true,
		'scrolling': 'no',
		'titleShow': false
	});

	// sprites sur boutons
     $('.action').append('<span class="hover"></span>').each(function () {
  		//var $span = $('span.hover', this).css('opacity', 0);
		var $span = $('span.hover', this);
  		$span[0].style.opacity = '0';
  		
		
  		$(this).hover(function () {
    		$span.stop().fadeTo(500, 1); 
 		}, function () {
   			$span.stop().fadeTo(500, 0);
  		});
	}); 

	// afficher/masquer les details
	var $label;
	
	$('#freelance a.bloc-detail[href="_detail"]').toggle(function(e) {
	
		e.preventDefault();
		$label = $(this).html();
	
		$(this).parent().next("div").slideDown("slow", function() {
			$(this).css({'display':'block'});
		});	
		$(this).html("x fermer");
		
	}, function() {
	
		$(this).parent().next("div").slideUp("normal", function() {
			$(this).css({'display':'none'});	
		});
		$(this).html($label);
	});
	
}

function initPortfolio() {
 
	// filtrage des vignettes selon le type de travail
	$('ul#filter a').click(function() {

		$(this).css('outline','none');
		$('ul#filter .current').removeClass('current');
		$(this).parent().addClass('current');

		var filterVal = $(this).text().toLowerCase().replace(' ','-').replace('é','e');

		if(filterVal == 'tout') {
			$('.boxes div.hidden').fadeIn('slow').removeClass('hidden');
		} else {
			$('.boxes div').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('normal').addClass('hidden');
				} else {
					$(this).fadeIn('slow').removeClass('hidden');
				}
			});
		}

		return false;
	});

	// slide diagonal des vignettes
	$('.boxgrid.thecombo').hover(function(){
		$(".cover", this).stop()
			.animate({top:'260px', left:'325px'},{queue:false,duration:600});
	}, function() {
		$(".cover", this).stop()
			.animate({top:'0px', left:'0px'},{queue:false,duration:600});
	});
	
	// affichage grand format
	$(".pf-view").fancybox({
		'titleShow' 		: false,
		'titlePosition'		: 'over',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'overlayOpacity'	: '0.8',
		'overlayColor'		: '0b0b0b'
	});
	
	// retour en haut
	$('#pf-boxes a, a.view-close').bind('click', function(event) {
		event.preventDefault();
		var a = $(this).attr('href');
		$.scrollTo($(a).attr('offsetTop'), 1000);
		return false;
	});

	//$(".pf-img").lazyload({effect : "fadeIn"});


}

function protectMail() {

	// liens mailto
	el1 = $('.email_msg');
	el1.each(function(){
		$(this).attr('href','mailto:' + $(this).attr('href').replace('|','@').replace('/','').replace(':','.') + '?subject=milc.fr_-_contact' );
	});
	
	// liens mailto pour coord tel
	el2 = $('.email_tel');
	el2.each(function(){
		$(this).attr('href','mailto:' + $(this).attr('href').replace('|','@').replace('/','').replace(':','.') + '?subject=milc.fr_-_contact par téléphone&body=Je suis (votre nom), je suis joignable au (vos coordonnees), de preference (vos disponibilites)');
	});
	
}

$(function bl() { 
	$('#section').css('opacity','0.1'); 
});

// formulaire de contact
$(function formulaire() {	
	$('.error, #contact_form_error').hide();
	
	$('input.text-input, textarea.text-input').css({'background-color':'#474a54','color':'#eee','border-color':'#474a54'});
	$('input.text-input, textarea.text-input').focus(function(){
	  $(this).css({'background-color':'#727580','color':'#eee','border-color':'#474a54'});
	});
	$('input.text-input, textarea.text-input').blur(function(){
	  $(this).css({'background-color':'#474a54','color':'#eee','border-color':'#474a54'});
	});

  $(".button").click(function() {
	// validate and process form
	// first hide any error messages
	// verification de l'adresse email ajouté le 23 juillet 09
    $('.error, #contact_form_error').hide();
	
	  var name = $("input#name").val();
		if (name == "") {
			//$("label#name_error").show();
			$("label#name_error").addClass("info").appendTo("#contact_form_error").show();
			$("#contact_form_error").show();
			$("input#name").focus();
			return false;
		}
		
		var email = $("input#email").val();
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		if (!pattern.test(email)) {
			$("label#email_error").addClass("info").appendTo("#contact_form_error").show();
			$("#contact_form_error").show();
			$("input#email").focus();
			return false;
    	}
    	
		var subject = $("input#subject").val();
		if (subject == "") {
      		$("label#subject_error").addClass("info").appendTo("#contact_form_error").show();
      		$("#contact_form_error").show();
      		$("input#subject").focus();
      		return false;
    	}
    	
		var message = $("#message").val();
		if (message == "") {
      		$("label#message_error").addClass("info").appendTo("#contact_form_error").show();
      		$("#contact_form_error").show();
      		$("#message").focus();
      		return false;
    	}
    	
   		var jsactif = $("#jsactif").val();
		jsactif = "oui";
		
    	if ($("#cc:checked").length == 1) { 
			var sendCC = $("input#email").val();
    	} else {  var sendCC = ""; }
    	
    	var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&message=' + message + '&sendCC='+ sendCC;
		$.ajax({
			type: "POST",
			url: "bin/process.php",
			data: dataString,
			success: function() {
		        $('#contact_form_error').html("<strong>Votre message a été envoyé</strong>").addClass("info")
		        .append("<p>Vous recevrez une réponse dans les plus brefs délais.</p>")
		        .hide()
		        .fadeIn(1500, function() {
		          $('#message').append("<img id='checkmark' src='images/check.png' />");
		        });
	      	},
	      	error: function() {
	      		$('#contact_form_error').html("<strong>Une erreur s'est produite lors de l'envoi de votre message</strong><p>veuillez réessayer plus tard ou me contacter directement via contact@milc.fr</p>").addClass("info").show();
	      	}
     	});
    	return false;
	});
});
// fin fn formulaire
	
	
/**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 * 
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com) 
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 * 
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 * 
 */

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","auto");
		});
	}
})(jQuery);



//console.profile(); console.profileEnd();
jQuery(document).ready(function(){
	animLogo();
	initPage();
	protectMail();
	//initPortfolio();
});
