//----------------------------------------------------------------------------------------

// Authors : Melissa Maheux , Influenza marketing http://www.influenza.ca
// Version 1.0
// Created: December 2011

//----------------------------------------------------------------------------------------

//-------------------------
//
//        Add CSS
//
//-------------------------

$(document).ready(function() {
	$('#partenaires ul li:last').addClass('last');
	$('.galerieBox:odd').addClass('odd');
	$('.thumbListing.fr a.preview').append('<span>Voir le descriptif</span>');
	$('.thumbListing.en a.preview').append('<span>More information</span>');
    $('.rightColumn ol').each(function() {
		$(this).children().each(function(i) {
			$(this).prepend('<span>' + (i + 1) + '.</span> ');
		});
	});
   
});


// Upload pdf
$(function() {
  $("a[href$=pdf]").addClass("pdf");
  $("a[href$=pdf]").attr("target", "_blank");
});    


//-----------------------------------------------------------------------
// validate form contact FRANCAIS
//----------------------------------------------------------------------

$(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);
	}, "Please enter a valid phone number.");
						       
    var validator = $("#contactMail.fr").bind("invalid-form.validate", function() {
		
	}).validate({
            
			rules: {
        		phone: {
        				phone: true
        			}
        		},
				
            messages: {
            firstname: "Champ requis",
			lastname: "Champ requis",
			company: "Champ requis",
			email: {
            required: 'Champs requis',
            email: 'Adresse invalide'
            },
            phone: {
            required: 'Champ requis',
			phone: 'Numéro invalide'
            },
              message: "Champ requis"
            },
              submitHandler: function(form) {
              jQuery(form).ajaxSubmit({
              target: "#contactMail.fr",
                  success: function() {
                  $("#contactMail.fr").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; au Groupe Brosseau !</p>")
                  //.append("<p></p>")
                  .hide()
                  .fadeIn(1500, function() {
                  $("#reponse");
                  });
                  }
              });
              }
	});
	
	var vaildatorcommenten =  $("#commentsen").bind("invalid-form.validate", function() {}).validate();
	var vaildatorcommentfr =  $("#commentsfr").bind("invalid-form.validate", function() {}).validate({
			messages: {
            	author: "Champ requis",
				email: {
            		required: 'Champs requis',
            		email: 'Adresse invalide'
            	},
              	message: "Champ requis"
            }
	});
	
});

//-----------------------------------------------------------------------
// validate form contact ENGLISH
//----------------------------------------------------------------------

$(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);
	}, "Please enter a valid phone number.");
						       
    var validator = $("#contactMail.en").bind("invalid-form.validate", function() {
		
	}).validate({
            
			rules: {
        		phone: {
        				phone: true
        			}
        		},
				
            messages: {
            firstname: "This field is required",
			lastname: "This field is required",
			company: "This field is required",
			email: {
            required: 'This field is required',
            email: 'Invalid Address'
            },
            phone: {
            required: 'This field is required',
			phone: 'Invalid Number'
            },
              message: "This field is required"
            },
              submitHandler: function(form) {
              jQuery(form).ajaxSubmit({
              target: "#contactMail.en",
                  success: function() {
                  $("#contactMail.en").html("<div id=\"reponse\"></div>");
                  $("#reponse").html("<h4>Your message was successfully send.</h4><p>Thank you for your interest in Groupe Brosseau!</p>")
                  //.append("<p></p>")
                  .hide()
                  .fadeIn(1500, function() {
                  $("#reponse");
                  });
                  }
              });
              }
	});
});


//------------------------------------------------------------------------
// Watermark Formulaire Media
//------------------------------------------------------------------------
$(document).ready(function() {
$(".textInput").each(function(){
	if(this.value !== ''){
		$(this).prev("label.watermark").fadeOut('fast');
	}
});
    // Fade out label on focus
    $(".textInput").focus(function() {
        $(this).prev("label.watermark").fadeOut('fast');                                             
    });
    // If input is left blank fade in label
    $(".textInput").blur(function() {
        var inputValue  = $(this).val();
        if (inputValue == "") {
            $(this).prev("label.watermark").fadeIn('fast');
        }
    });
});

//------------------------------------------------------------------------
//
// Custom Modal Window
//
//------------------------------------------------------------------------
  

$(document).ready(function() {

	$('.thumbListing li a.preview').click(function(e) {		
		//Cancel the link behavior  
		e.preventDefault();
		
		// Set Language Variables
		var textLang = $('html').attr('lang');
		
		if (textLang == 'fr'){
			var closeTag = 'Fermer';
		} else {
			var closeTag = 'Close';
		}
		// Append Modal Markups
	   	$('body').append('<div id="mask"></div><div id="itemSpecific" class="modalWindow"><div class="closeBox"><a href="#" class="close">'+ closeTag +'</a></div><div id="modalContent"></div></div>');
		
		// Get Content and Load It
		var ingredientURL = $(this).attr('href');
		$("#modalContent").load(ingredientURL, function() { // Once the Content Loaded Do Some Animations

  			// Get the screen height and width  
			var maskHeight = $(document).height();
			var maskWidth = $(window).width();
  			
  			// Set height and width to mask to fill up the whole screen  
			$('#mask').css({ 'width': maskWidth, 'height': maskHeight });
			
			// Mask transition effect 
			$('#mask').css("opacity", 0.5);          
			$('#mask').fadeIn("slow");
			
			// Get the window height and width  
			var winH = $(window).height();
			var winW = $(window).width();
		
			// Set Modal Content Height
			var contentH = winH-700;
			var modalH = contentH;
			if (contentH >= winH){
				var modalH = winH-100;
			}
			var widthPlusScroll = $('.mainImg').width() + 325;
			
			$('#itemSpecific').css("height", $('.mainImg').height());
			$('#itemContent').css("height", $('.mainImg').height());
			$('#itemSpecific').css("width", widthPlusScroll);
		
		
			// Set the popup window to center  
			$('#itemSpecific').css('top',  winH/2-$('#itemSpecific').height()/2);  
			$('#itemSpecific').css('left', winW/2-$('#itemSpecific').width()/2); 
		
			// Content transition effect  
			$('#itemSpecific').fadeIn(500);
			
			// Click on close button  
			$('.modalWindow .close').click(function() {
				$('#mask').fadeOut('fast');
				$('.modalWindow').fadeOut('fast', function() {
					$('#mask').remove();
					$('#itemSpecific').remove();
  				});
				return false;
			});
	
			// Click on overlay mask  
			$('#mask').click(function() {
				$(this).fadeOut('fast');
				$('.modalWindow').fadeOut('fast', function() {
					$('#mask').remove();
					$('#itemSpecific').remove();
  				});
			});	
		});
	});
});
