$(function() {

	//JQUERY FUNCTIONS
	
	$("#coms").click(function(e){
		e.preventDefault();
		$(this).hide();
		$(".hidden").slideDown("slow");
	})
	
	$(".back").hide();
	
	$("ul.blocklist li").hover(
		function() { $(this).find(".cover").hide(); $(this).find(".back").show();  },
		function() { $(this).find(".cover").show(); $(this).find(".back").hide(); }
	);
	
	$("#preview").easySlider({
		auto: false,
		continuous: true 
	});
	
	var foo = "";
	var foo1 = 1;
	
	$(document).keydown(function(e)
	{
		var ts = $("#preview").attr("title")-1;
		
		foo = $("#preview").attr("rel");
		if (foo===undefined) { foo=0; }
		switch(e.which)
		{
			case 39:	$.fn.easySliderAnimate("next",parseInt(foo),ts,$("#preview").attr("title"),1060,$("#preview")); //alert(foo); alert(ts); alert($("#preview").attr("title"));
						
						foo1 = parseInt(foo)+1;
						$("#preview").attr("rel",foo1);
						$("#firstnb").html(foo1+1);
						if(foo1>ts) { $("#preview").attr("rel","0"); $("#firstnb").html("1"); }
						if(foo1<0) { $("#preview").attr("rel",ts); }
						
						break;	

			case 37:	$.fn.easySliderAnimate("prev",parseInt(foo),2,3,1060,$("#preview"));
			
						foo1 = parseInt(foo)-1;
						$("#preview").attr("rel",foo1);
						$("#firstnb").html(foo1+1);
						if(foo1>ts) { $("#preview").attr("rel","0"); }
						if(foo1<0) { $("#preview").attr("rel",ts); $("#firstnb").html(ts+1); }
			
						break;
		}
	});



	$(document).keydown(function(e)
	{
		switch(e.which)
		{
			case 40:	if ($("#up").attr("rel").length) {
							var url = $("#up").attr("rel");    
							$(location).attr('href',url);
						}
						
						break;	

			case 38:	if ($("#down").attr("rel").length) {
							var url = $("#down").attr("rel");    
							$(location).attr('href',url);
						}
			
						break;
		}
	});
	
	if ($("form#contactFrom").length) {
		
		$("input[name=name]").focusin(function(){ if($(this).val()=="nom") $(this).val(""); });
		$("input[name=name]").focusout(function(){ if($(this).val()=="") $(this).val("nom") });
		
		$("input[name=email]").focusin(function(){ if($(this).val()=="courriel") $(this).val(""); });
		$("input[name=email]").focusout(function(){ if($(this).val()=="") $(this).val("courriel") });
		
		$("input[name=telephone]").focusin(function(){ if($(this).val()=="téléphone") $(this).val(""); });
		$("input[name=telephone]").focusout(function(){ if($(this).val()=="") $(this).val("téléphone") });
		
		$("textarea[name=message]").focusin(function(){ if($(this).val()=="votre message") $(this).val(""); });
		$("textarea[name=message]").focusout(function(){ if($(this).val()=="") $(this).val("votre message") });
		
	}
	
	$("input[name=recherche]").focusin(function(){ if($(this).val()=="mot(s) clé(s)") $(this).val(""); });
	$("input[name=recherche").focusout(function(){ if($(this).val()=="") $(this).val("mot(s) clé(s)") });
		
		
	/*$('form#contactFrom').submit(function(e){

		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		
		if ($("input[name=name]").val()=="" || $("input[name=name]").val()=="nom") {
			$("#msg").hide().fadeIn().html("Vous devez entrer votre nom");
			return false;
		} else if ($("input[name=email]").val()=="" || $("input[name=email]").val()=="courriel") {
			$("#msg").hide().fadeIn().html("Vous devez entrer votre courriel");
			return false;
		} else if (reg.test($("input[name=email]").val())==false) {
			$("#msg").hide().fadeIn().html("Le courriel entré n'est pas valide");
			return false;
		} else if ($("textarea[name=message]").val()=="" || $("textarea[name=message]").val()=="votre message") {
			$("#msg").hide().fadeIn().html("Vous devez entrer un message");
			return false;
		} else {
			return true;
		}
	});*/
	
	if ($("#divForm").length) {
		$("#divForm").hide();
		$("#showForm").click(function(e){
			e.preventDefault();
			$("#divForm").slideDown();
			$('html, body').animate({ 
				 scrollTop: $('#divForm').offset().top 
			}, 500);

		});
	}

	
});



$(document).ready(function() {

//ACCORDION
//Hide (Collapse) the toggle containers on load
        $(".accordion").hide();
   
        //Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
        $(".ouvre_accordion").click(function(event){
            $('.accordion').slideToggle("slow");
            event.preventDefault();
        });
 
 
 //SCROLL DOWN
 $(function(){
		    $('a[href*=#]').click(function() {
		    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
		        && location.hostname == this.hostname) {
		            var $target = $(this.hash);
		            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
		            
		            if ($target.length) {
		                var targetOffset = $target.offset().top;
		                $('html,body').animate({scrollTop: targetOffset}, 1500);
		                return false;
		            }
		        }
		    });
		});
 

	/*
	*   Examples - images
	*/
	
	
	$("a[rel=example_group]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titleFormat'		: function(title) {
			return '<span id="fancybox-title-over">' + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	/*
	*   Examples - various
	*/
	
	$("#various1").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
	
	$("#various2").fancybox();
	
	$("#various3").fancybox({
		'width'				: '75%',
		'height'			: '75%',
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$("#various4").fancybox({
		'padding'			: 0,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
	
	
	$("#pixelmail").validationEngine() 
	$("#jobFrom").validationEngine() 
	$("#contactFrom").validationEngine()
	$("#newsletterForm").validationEngine()

			
});
