//----------------------------------------------------------------------------------------

// Authors : Melissa Maheux , Influenza marketing http://www.influenza.ca
// Version 1.0
// Created: May 2011

//----------------------------------------------------------------------------------------

//------------------------------------------------------------------------
// Formulaire Commentaire
//------------------------------------------------------------------------
$(document).ready(function() {

      
    var validator = $("#commentform").bind("invalid-form.validate", function() {
		
	}).validate({
            
            messages: {
			author: "Ce champ est requis",
			email: {
            required: 'Ce champ est requis',
            email: 'Adresse invalide'
            },
              message: "Ce champ est requis"
            }
	});
});

//------------------------------------------------------------------------
// Formulaire Contact
//------------------------------------------------------------------------
$(document).ready(function() {
	
	jQuery.validator.addMethod("phone", function (value, el, params) {
	return this.optional(el) || /^[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}$/.test(value);
	}, "Veuillez entrer un numéro téléphone valide.");
      
    var validator = $("#sendMail").bind("invalid-form.validate", function() {
		
	}).validate({
            
            rules: {
        		phone: {
        				phone: true
        			}
        		},
            messages: {
			name: "Ce champ est requis",
			email: {
            required: 'Ce champ est requis',
            email: 'Adresse invalide'
            },
            phone: {
            required: 'Ce champ est requis',
			phone: 'Num&eacute;ro invalide'
            },
              message: "Ce champ est requis"
            },
              submitHandler: function(form) {
              jQuery(form).ajaxSubmit({
              target: "#sendMail",
                  success: function() {
                  $("#sendMail").html("<div id=\"reponse\"></div>");
                  $("#reponse").html("<h4>Votre message  &eacute;t&eacute; envoy&eacute; avec succ&egrave;s.</h4><p>Merci de l&rsquo;int&eacute;r&ecirc;t port&eacute; &agrave; Communications Michel Julien !</p>")
                  //.append("<p></p>")
                  .hide()
                  .fadeIn(1500, function() {
                  $("#reponse");
                  });
                  }
              });
              }
	});
});



//////////////////
// pretty photo
//////////////////


$(document).ready(function(){
		$("a[rel^='prettyPhoto']").prettyPhoto({
			allowresize: true, /* true/false */
			theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
			markup: '<div class="pp_pic_holder"> \
						<div class="ppt">&nbsp;</div> \
						<div class="pp_top"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
						<div class="pp_content_container"> \
							<a class="pp_close" href="#">Close</a> \
							<div class="pp_left"> \
							<div class="pp_right"> \
								<div class="pp_content"> \
									<div class="pp_loaderIcon"></div> \
									<div class="pp_fade"> \
										<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
										<div class="pp_hoverContainer"> \
											<a class="pp_next" href="#">next</a> \
											<a class="pp_previous" href="#">previous</a> \
										</div> \
										<div id="pp_full_res"></div> \
										<div class="pp_details"> \
											<div class="pp_nav"> \
												<a href="#" class="pp_arrow_previous">Previous</a> \
												<p class="currentTextHolder">0/0</p> \
												<a href="#" class="pp_arrow_next">Next</a> \
											</div> \
											<p class="pp_description"></p> \
											{pp_social} \
										</div> \
									</div> \
								</div> \
							</div> \
							</div> \
						</div> \
						<div class="pp_bottom"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
					</div> \
					<div class="pp_overlay"></div>',
			gallery_markup: '<div class="pp_gallery"> \
								<a href="#" class="pp_arrow_previous">Previous</a> \
								<div> \
									<ul> \
										{gallery} \
									</ul> \
								</div> \
								<a href="#" class="pp_arrow_next">Next</a> \
							</div>',
			image_markup: '<img id="fullResImage" src="{path}" />',
			flash_markup: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',
			quicktime_markup: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',
			iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
			inline_markup: '<div class="pp_inline">{content}</div>',
			custom_markup: '' /* html or false to disable */
		});
		return false;
	});

// **************
// Add class
// **************

$(document).ready(function() {			   
	$(".services ul li:last").addClass("last");	
	$(".actualite p a").attr ("target", "_blank");
	$(".actualite p.keywords a").removeAttr("target", "_blank");

});


//////////////////
// galerie grosse image
//////////////////
 $(document).ready(
   
    function(){
 
        $("#galNav a").click(function () {
				$("#galNav a").removeClass("active");
				$(this).addClass("active");
				return false;
			}).filter(":first").click();
       
        // Load First Image
        var firstImg = $('.jcarousel-clip a').attr('href');
        

        $("#mycarousel a").click (
			
            function() {   
				
				//Thumbnails effect
				$("#mycarousel a").removeClass('active');
				$("#mycarousel a").fadeTo("fast", 1);
				$(this).addClass('active');
				$(this).fadeTo("fast", 0.45);
				var desc = $(this).prev('.descPhoto').html();
				
               	//Set current image
				var currentImg = $("#photo2 img");
               
                //New image attributes
                var newImg = $(this).attr("href");
                var newAlt = $(this).attr("title");
               
                //Create new image
                var newPic = new Image();
                $(newPic).attr({ src: newImg, alt: newAlt });
               
                $("#photo1 img").remove();
                $("#photo2").hide('fast',loadContent);
                $("#photo1").append(currentImg);
				
				//Display Loader
				$('#loader').remove();
				$('#mainPhoto').append('<div id="loader">Chargement...</div>');
				$('#loader').fadeIn('normal');
               
                
				function loadContent() {
					$('#photo2').load(newPic,'',hideLoader())
				}
				function hideLoader() {
					$('#loader').fadeOut('normal',showNewContent());
				}
				function showNewContent() {
					$("#photo2 img").remove();
					$("#photo2").append(newPic);
					$("#descPhoto p").empty();
					$("#descPhoto p").append(desc);
					
					$("#photo2").fadeIn("fast");
				}
                return false;
            }
               
        ).filter(":first").click();

    }
);
 
//////////////////
// jcarousel
//////////////////

$(document).ready(function() {
    $('#mycarousel').jcarousel();
});

