﻿function qScrolling(sens,vitesse){
	if($('.qpz-navcontainer ul').height()>$('.qpz-navcontainer').height())
	{
		var max = 0;
		
		if (parseInt(sens)>0)
		{
			max = parseInt(parseInt($('.qpz-navcontainer').height()- $('.qpz-navcontainer ul').height()));			
		}
		var delta = parseInt($('.qpz-navcontainer ul').css('margin-top'))-max;
		if(delta <0)
		{
			delta = delta * parseInt('-1');
		}
			$('.qpz-navcontainer ul').animate({marginTop: max},delta*parseInt(vitesse));
  	}
}
$(document).ready(function(){

//MegaMenu
try
{
	$('.qpz-topnav ul.dynamic ul.dynamic').parents('li.static li.static').addClass('qpz-megamenu');
	$('.qpz-topnav .qpz-megamenu> ul.dynamic > li').each(function(index)
	{
		$(this).addClass('item-mega-' + index);
	});
	$('.qpz-topnav .qpz-megamenu > ul > li > a').attr('href','#');
	$('.qpz-topnav .qpz-megamenu > a').click(function(){return false;});
	$('.qpz-topnav .qpz-megamenu > ul > li > a').click(function(){return false;});
}
catch(e)
{
}
//Menu Horizontal
try
{
	$('.root li.static li.static > ul.dynamic').each(function(){
		$(this).css('min-width',$(this).parent().width()-3);
	});
	$('.qpz-topnav a.static.menu-item').each(function(){
		if($(this).siblings('ul').length == 0)
		{
			$(this).addClass('qpz-nosub');
		}
	});
}
catch(e)
{}
//Menu Vertical
try
{
$('.qpz-menu-gauche .root > li > a').click(function(){return false;});
$('.qpz-menu-gauche .root li.selected').parents('ul ul.static li.static').addClass('selected');
$('.qpz-menu-gauche ul.root ul ul li:last-child').css('padding-bottom','10px');
//Accordeon
$('.qpz-menu-gauche .root > li > ul.static > li:not(.selected) > ul').slideUp(500);
$('.qpz-menu-gauche .root > li > ul.static > li:not(.expanded) > a').click(function()
{
	if($(this).siblings('ul').css('display') != 'block')
	{
		$('.qpz-menu-gauche .root > li > ul.static > li > ul').slideUp(500);
		$(this).next('ul').slideDown(500);
	}
	else
	{	
		if($(this).parent('li.selected').length == 0)
		{	
			$('.qpz-menu-gauche .root > li > ul.static > li > ul').slideUp(500);
			$('.qpz-menu-gauche li.selected ul').slideDown(500);
		}
	}
	return false;
});
}
catch(e)
{}

if($('div.ms-rtestate-write').length == 0){
try{
	/* == Mosaïque clients == */
	 $('.qpz-mosaique-client').click(function(){window.location = $(this).find('a').attr('href');});	 
	 $('.qpz-mosaique-client-item').hover(function(){
		var elem = $(this).children('.qpz-flip');
		//elem.siblings('.qpz-flipdata').animate({left:'0',top:'0'},250);
		elem.siblings('.qpz-flipdata').fadeIn(300);
		//elem.siblings('.qpz-flipdata').css('padding','10px 0 0 15px').fadeIn(300).animate({padding:'0px'},200);
	 },function(){
	 	var elem = $(this).children('.qpz-flipdata');
		//elem.animate({left:'100',top:'132'},250);
		elem.fadeOut(250);
	 });
}catch(e){}
	/* == Page Client == */
	if($('#slider1 img').length > 1)
	{
  		$('#slider1').nivoSlider({effect:'fade',directionNav:false, pauseTime:4000, pauseOnHover:true,keyboardNav:false }); 
  	}
  	var buttonDown = $('.qpz-button.down');
  	var buttonUp = $('.qpz-button.up');
  	buttonDown.mouseover(function(){qScrolling('1',4);});
  	buttonUp.mouseover(function(){qScrolling('-1',4);});
  	//Stoppe le scroll 
  	 $('.qpz-button').mouseleave(function(){
  	 	$('.qpz-navcontainer ul').stop();
  	});
  	//Scroll avec la molette
  	$('div.qpz-navcontainer').bind('mousewheel',function(event,delta){
  		var dir= delta > 0 ? '-1' : '1';
  		var intensite= Math.abs(delta);
  		qScrolling(dir,2);  		
  		setTimeout(function(){$('.qpz-navcontainer ul').stop()},500);
  		return false;
  	});
  	$('.qpz-pageclient .qpz-button').mouseenter(function(){$('.qpz-clientinfos').slideDown(300)});
  	$('.qpz-pageclient .qpz-button').mouseleave(function(){$('.qpz-clientinfos').slideUp(300)});
}
// WP Mosaïque métiers Home
if($('div.ms-rtestate-write').length == 0){
	try{
		$('.qpz-metiers a').hover(
			function(){
				$(this).siblings('span').stop().animate({left:'2px',opacity:'1'},350);
			},function(){
				$(this).siblings('span').stop().animate({left:'600px',opacity:'-0.5'},250);
			});
	}catch(e){}
}
/* ==== */
/* ==== */
//Article ajustements
try
{
	var maxHeight = $('.qpz-layout-article .qpz-wp-top-left .qpz-article').innerHeight() +21 ;
	if ( maxHeight < $('.qpz-layout-article .qpz-wp-top-right').innerHeight())
	{
		$('.qpz-layout-article .qpz-wp-top-left .qpz-article').css('height',$('.qpz-layout-article .qpz-wp-top-right').innerHeight()-119);
	}
	else
	{
		$('.qpz-layout-article .qpz-wp-top-right').css('height',maxHeight );
	}
}
catch(e)
{}
//Actu pager
try
{
	$('.ms-WPBody #allactus').pager('div.actuspage',{navId: 'qpz-pager',prevText: 'Pr&eacute;c&eacute;dent',nextText: 'Suivant'});
	$('#qpz-pager a[rel=prev]').addClass('qpz-pager-prev');
	$('#qpz-pager a[rel=next]').addClass('qpz-pager-next');
	$('#qpz-pager a[rel!=next]:last').after('<span class="qpz-pager-nb-item">/'+$('#qpz-pager a[rel!=next]:last').text()+'</span>');
}
catch(e)
{}
//Layout standard ajustements
try
{
	var maxHeight = $('.welcome .qpz-wp-left .ms-WPBody').height();
	if ( maxHeight < $('.welcome .qpz-wp-right .ms-WPBody').height())
	{
		$('.welcome .qpz-wp-left .ms-WPBody').css('height',$('.welcome .qpz-wp-right .ms-WPBody').height());
	}
	else
	{
		$('.welcome .qpz-wp-right .ms-WPBody').css('height',maxHeight );
	}
}
catch(e)
{}
//Suppression des zones vides en mode visu
try
{
	$('.welcome > .qpz-wp-left,.welcome > .qpz-wp-right').each(function(){
		if ($(this).children('*').length == 0)
		{
			$(this).css('display','none');
		}
	});
}
catch(e)
{}
//Réécriture des name des champs du formulaire
/*$('#aspnetForm input[type=text]').each(function(){
var name = $(this).attr('name');
name = name.substr(name.lastIndexOf('$',name.length)+1,name.length);
$(this).attr('name', name);
});*/
//Contact validateurs
try
{
	$("#aspnetForm").validate({
		rules: 
				{
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldnom: {required: true},
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldprenom: {required: true},
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldemail: {required: true,email: true},
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldsociete: {required: true},
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldadresse: {required: true},
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldcodepostal: {required: true},
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldville: {required: true},
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldtelephone: {required: true,number:true,rangelength:[10,14]}
				},
		messages: 
				{
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldnom:"Veuillez saisir votre nom",
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldprenom:"Veuillez saisir votre pr&eacute;nom",
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldemail: "Adresse e-mail non valide",
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldsociete: "Indiquez votre soci&eacute;t&eacute;",
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldadresse: "Veuillez saisir votre adresse",
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldcodepostal: "Veuillez saisir votre  code postal",
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldville: "Veuillez saisir votre commune",
					ctl00$PlaceHolderMain$UIVersionedContent15$qpzfieldtelephone: "Num&eacute;ro de t&eacute;l&eacute;phone requis"
				}
	});
}
catch(e)
{}

//Contact uploadcv
try
{
	$('.qpzuploadcv input').change(function(){
		var chaine = $('.qpzuploadcv input[type=file]').val();
		var i2 = chaine.length;
		var i1 = chaine.lastIndexOf('\\',i2)+1;
		var fichier = chaine.substring(i1,i2);
		$('.qpzuploadcv').append('<input type="text" value="'+ fichier + '"/>');
		$('.qpzuploadcv input[type=text]:not(:last-child)').remove();
	});
}
catch(e)
{}
// Encodage mail
try
{
	if($('div.ms-rtestate-write').length == 0){
		var name = "agence" ;
		var domain = "quatrepointzero.com" ;
		$('.qpz-contactus').append('<a href=\"mailto:' + name + '@' + domain + '\">'+ name + '@' + domain + '</a>') ;
	}
}
catch(e)
{}

// Zoom
try
{
	var options = 	{
					zoomWidth: 265,
					zoomHeight: 280,
				    xOffset: 5,
				    yOffset: 0,
				    preloadText:'Chargement du zoom',
				    position: "right"
					};
	$('.s4-wpcell-plain .jqzoom').jqzoom(options);
	// Zoom Evolution Internet
	$('.qpz-evo-web').click(function(){
		//if ($('.qpz-evo-web-popin').height() <  $('.qpz-droite').height()- $('.qpz-foot').height()-23)
		//{
		//	$('.qpz-evo-web-popin').css('height', $('.qpz-droite').height()- $('.qpz-foot').height()-23);
		//}
		$('.qpz-evo-web-popin').fadeIn(800);
	}); 
	$('.qpz-btn-close').click(function(){
		$('.qpz-evo-web-popin').fadeOut(500);
	});
			
	Cufon.replace('.jqZoomTitle', { fontFamily: 'PF Tempesta Seven Extended bold' });
}
catch(e)
{}
});



