/////////////////////////////////////////////////////////////On load
var easingM= "easeInOutQuad";  //easeInOutBack ,easeInOutQuad
var animation_duration = 800;
var pathname = window.location.pathname;
var n = 0;//for testresize
var Lang="EN"; //EN ou PO 

var tablette="";
var StageW=$(window).width();
var StageH=$(window).height();
var menu="off";
var left="on";
var C2=StageH;
checkDevice();
window.orientation=90;

/////////////////////////////////////////////////////////////On load
$(window).load(function() {
StageW=$(window).width();
if ( $.browser.msie ) {}else{
setTimeout(function(){	$('#loader').fadeTo(animation_duration, 0).css("top","-1000").hide(0).html("");},500);
}

agencement();
});	



window.onorientationchange = function() {

if(window.orientation==0 || window.orientation==180){ 
//alert("Passez en mode paysage pour voir ce site.");
window.orientation=90;
}
}



/////////////////////////////////////////////////////////////On Ready	
$(document).ready(function() {


//if(getCookie("QDNlang2")=="null"){ setCookie("QDNlang2", Lang );}
//alert(getCookie("QDNlang2"));

C2=StageH-( $("#header1").height()+$("#footer").height() );
$(".bt4").css("color","white");

$("#navigation a:first").css("cursor","default").css("color","#000000");


//$('.backstretch img').hide();
if ( $.browser.msie ) {
	
}else{
	$('#loader').activity({segments: 12, steps: 3, opacity: 0.3, width: 3, space: 4, length: 5, color: '#ffffff', speed: 1.5});
	//center loader
	$("#loader").animate({ right: (StageW/2)+"px", top: (StageH/2)+"px"}, 0,easingM,function() {$(this).fadeTo('fast', 1);});
}
//select
//if ( $.browser.msie ) {alert($.browser.version);}
/*if ( $.browser.msie ) {
  if($.browser.version!="8.0" && $.browser.version!="7.0"){
	  $(".selectSkin, #contenernewsletter select").select_skin();
	  $('.cmf-skinned-select .cmf-skinned-select .cmf-skinned-text').css('display','none');
  }
}else{
*/
	$(".selectSkin, #contenernewsletter select").select_skin();
	$('.cmf-skinned-select .cmf-skinned-select .cmf-skinned-text').css('display','none');



//}
//setTimeout(function(){	$('.cmf-skinned-select .cmf-skinned-select .cmf-skinned-text').css('display','none');},500);
//jQuery("#lang2").select_skin();
//select skin
//lightbox
//jQuery('.lightbox').lightbox();
//lightbox


$(".inlinebox").fancybox({

	"autoScale"			: true,
	"transitionIn"		: "fade",
	"transitionOut"		: "fade",
	"type"				: "inline",
	'scrolling'   		: 'no',
	"padding"			: "30"
});

$(".inlinebox").click(function(){
$('.scroll').jScrollPane({showArrows: true});
});
/*
	$('.slides').slides({
		preload: true,
		preloadImage: 'admin/template/slides/img/loading.gif',
		play: 5000,
		pause: 2500,
		autoHeight: true,
		hoverPause: true
	});

*/



//fadin/fadeout imgs
if ( $.browser.msie && $.browser.version=="7.0" || $.browser.msie && $.browser.version=="8.0" ) {}else{
$(".latest_img").hover(function(){$(this).fadeTo(animation_duration, 0.5);},function(){$(this).fadeTo(animation_duration, 1.0);});//effect
}
//resize
$(window).resize(function(){ n=n+1;testresize(n);	});
//fadeout loader
if ( $.browser.msie ) {}else{
setTimeout(function(){	$('#loader').delay("1000").fadeTo(animation_duration, 0).css("top","-1000").hide(0).html("");},500);
}

/*$("#replyLeft").click(function(){
//var positionLeftLeft=$("#left").css("left");alert(positionLeftLeft);
$("#leftContent").toggle(animation_duration);//.animate({ paddingLeft:"-214px" }, animation_duration,easingM);
});
*/



$("#replyLeft").click(function(){
if(left=="off"){
	left="on";
	$("#leftContent").animate({ marginLeft: "0"  }, animation_duration,easingM);
	$("#leftContent3").animate({ marginLeft: "0"  }, animation_duration,easingM);
}else{
	left="off";
	$("#leftContent").animate({ marginLeft: "-250px"  }, animation_duration,easingM);
	$("#leftContent3").animate({ marginLeft: "-250px"  }, animation_duration,easingM);
}

});


if(support=="mobile" || support=="tablet"){ 

	$("#header2 span").click(function(){
	if(menu=="off"){
		$("#menu").animate({ top: "85px"  }, animation_duration,easingM);
		menu="on";
	}else{
		$("#menu").animate({ top: "-200px"  }, animation_duration,easingM);
		menu="off";
	}
	});
}else{

	$("#header2 span,#menu").hover(function(){
		$("#menu").stop().animate({ top: "85px"  }, animation_duration,easingM);
	},function(){    
		$("#menu").hover(function(){},function(){
			$("#menu").stop().animate({ top: "-200px"  }, animation_duration,easingM);
		});
	});
	
	

}


/*
$("#header2 span").click(function(){
			$("#menu", this).stop().animate({ top: "85px"},{queue:false,duration:160});

	}, function() {
			$("#menu", this).stop().animate({ top: "-200px"},{queue:false,duration:160});

	});
*/


$("#openconditionsPro").click(function(){
//if ( $.browser.msie ) {	$("#conditionsPro").show(0);}else{
	$("#conditionsPro").show(0).fadeTo(animation_duration, 1.0);
//}
$("#conditionsPro").animate({ left: ((StageW/2)-200)+"px",top: ((StageH/2)-170)+"px"  }, animation_duration,easingM);
});

$("#openNewsletter").click(function(){
//if ( $.browser.msie ) {$("#newsletter").show(0);}else{
	$("#newsletter").show(0).fadeTo(animation_duration, 1.0);
//}
$("#newsletter").animate({ left: ((StageW/2)-200)+"px",top: ((StageH/2)-170)+"px"  }, animation_duration,easingM);
});
//close newsletter
$("#close4").click(function(){
//if ( $.browser.msie ) {$("#newsletter,#inscriptionNewsletterok,#conditionsPro").hide(0);}else{
	$("#newsletter,#inscriptionNewsletterok,#conditionsPro").fadeTo(animation_duration, 0).hide(0);
//}
});




$("#lang span").click(function(){

	var langJS=$(this).attr("langue");
	var pathname = window.location;
	//alert(pathname);
	//alert(window.location);
	$.ajax({
	data: {lang : langJS},
	type : "POST",cache : false,
	url: "admin/template/SESSION.php?action=lang",
	success:function(html){ 
		//location.href = pathname ;  
		
		setCookie("QDNlang2'", langJS );
		location.reload();      	
	},
	complete:function() {},
	error:function(XMLHttpRequest,textStatus, errorThrown){}
	});


});

  


agencement();
		
});	//END of jQuery







(function(){
    // remove layerX and layerY
    var all = $.event.props,
        len = all.length,
        res = [];
    while (len--) {
      var el = all[len];
      if (el != 'layerX' && el != 'layerY') res.push(el);
    }
    $.event.props = res;
}());




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////fonctions


function showMENU(){
if ( $.browser.msie && $.browser.version=="7.0" || $.browser.msie && $.browser.version=="8.0" ) {
	$("#AG").hide(100);
	$("#content2,#content4,.hide,#content,#footer,#header").show(100); 
	
	}else{
		
	$("#AG").fadeTo(1, 0,function(){ $("#AG").hide(); });
	$("#content2,#content4,.hide,#content,#footer,#header").fadeTo(animation_duration, 1); 
	}
	
	
	
	if(pathname=="/"){
		setTimeout(function(){ 
			menu="on";
			$('#header2 span').trigger('mouseover');
			//$("#header2 span,#menu")
			//$("#menu").animate({ top: "85px"  }, animation_duration,easingM); 
			//setTimeout(function(){ $("#menu").stop().animate({ top: "-200px"  }, animation_duration,easingM);  },4000);
		},1000);
	}
	
}

/////////////////////////////////////////////////////////////fonctions change langue	
function changeLang(){
	Lang=$("#lang2").attr("value");
	var pathname = window.location.pathname;
	
	$.ajax({
	data: {lang : Lang},
	type : "POST",cache : false,
	url: "admin/template/SESSION.php?action=lang",
	success:function(html){ 
	setCookie("QDNlang2'", Lang );
	location.reload();           	
	},
	complete:function() {},
	error:function(XMLHttpRequest,textStatus, errorThrown){}
	});
}


/////////////////////////////////////////////////////////////fonctions MAJStage	
function MAJStage(){
StageW=$(window).width();
StageH=$(window).height();
}

/////////////////////////////////////////////////////////////fonctions testresize	
function testresize(y) {
	setTimeout(function(){  if(y==n){agencement();} },200);	
}
/////////////////////////////////////////////////////////////fonctions agencement
function agencement(){
MAJStage();
if(AGchecked=="non"){center("#AG");}
if ( $.browser.msie ) {}else{
$("#loader").animate({ right: (StageW/2)+"px", top: (StageH/2)+"px"  }, 1,easingM);//,function() {$(this).fadeTo(animation_duration, 1);}
}

if(support!="mobile"){  
	if(support=="mobile"){ 
		StageH=$("body").height();
	}
}
C2=StageH-( $("#header1").height()+$("#footer").height() );
$("#content").css("height",C2+"px").css("min-height",C2+"px").css("max-height",C2+"px");


/*var HH=$("#home").css("height");
var alignHome=(C2-HH)/2;//alert(alignHome);
$("#home").animate({ paddingTop: alignHome+"px"  }, animation_duration,easingM);
*/



var  Wfoot = 0;
$('#footer ul li').each(function() {
  Wfoot += $(this).width();
  Wfoot += parseInt($(this).css("padding-left"), 10) + parseInt($(this).css("padding-right"), 10); //Total Padding Width
  Wfoot += parseInt($(this).css("margin-left"), 10) + parseInt($(this).css("margin-right"), 10); //Total Margin Width
});

var  Wfoot2 = 0;

$('#footer ul').css("width",  Wfoot+8+"px"  );
if ( $.browser.msie ) {}else{
$('#loader').delay("1000").fadeTo(animation_duration, 0).css("top","-1000").hide(0);
}

$(".scroll").jScrollPane({
    autoReinitialise: true,
    autoReinitialiseDelay: 100,
    showArrows: true
});

}




function AGcheck(){
AGchecked="oui";
//setCookie("QDNlang2'", Lang );
//setCookie("AG'", "OK" );
}
/////////////////////////////////////////////////////////////fonctions	Center
function center(div){
var positionY=Math.ceil( (StageH/2)-($(div).height()/1.30) );
var StageCenterW=Math.ceil(StageW/2); var DivCenterW=Math.ceil($(div).width()/1.45);
var positionX=(StageCenterW-DivCenterW);
$(div).animate({ left: positionX+"px", top: positionY+"px"  }, 1,easingM);

}






function checkDevice(){
	//alert(navigator.userAgent);
	

	
		
	if( navigator.userAgent.match(/Android/i) && (navigator.userAgent.match(/Mobile/i))  
		|| navigator.userAgent.match(/webOS/i)  && (navigator.userAgent.match(/Mobile/i))  
		|| navigator.userAgent.match(/iPhone/i) && (navigator.userAgent.match(/Mobile/i))   
		|| navigator.userAgent.match(/iPod/i)  && (navigator.userAgent.match(/Mobile/i))  
		|| navigator.userAgent.match(/opera/i)   && (navigator.userAgent.match(/Mobile/i))  
		|| navigator.userAgent.match(/blackberry/i)  && (navigator.userAgent.match(/Mobile/i))  
		|| navigator.userAgent.match(/palm/i)  && (navigator.userAgent.match(/Mobile/i))  
		
		){ 
		support="mobile";
		//$('meta[name="viewport"]').attr('content', 'height=device-height,width=900px,initial-scale=0.5,user-scalable=no,minimum-scale=0.5,maximum-scale=0.5');
		
	
	}else{
		
		if ( (navigator.userAgent.match(/Android/i))|| navigator.userAgent.match(/iPad/i) ) {      
			support="tablet";tablette="other";
			if  (navigator.userAgent.match(/iPad/i) ){ tablette="ipad";} 
		}else{
			var userAgent = navigator.userAgent.toLowerCase(); 
			$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); 
			
			// Is this a version of Chrome?
			
			if($.browser.chrome){
			  userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
			  userAgent = userAgent.substring(0,userAgent.indexOf('.'));
			  $.browser.version = userAgent;
			  // If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
			  $.browser.safari = false;
			  support="normal";
			
		
			}else if($.browser.safari){
			  userAgent = userAgent.substring(userAgent.indexOf('safari/') +7);
			  userAgent = userAgent.substring(0,userAgent.indexOf('.'));
			  $.browser.version = userAgent;
			  support="safari";//
			}else{
				support="normal";
			}
		}
	//alert(navigator.userAgent);	
		
	}
	
	 
	if(support=="tablet"){  
		 
		$('meta[name="viewport"]').attr('content', 'height='+StageH+',width=device-width,initial-scale=1.0,user-scalable=no,minimum-scale=1.0,maximum-scale=1.0');
		
	}else if(support=="mobile"){  
		//$("body, html").width("960px");
		if( navigator.userAgent.match(/Android/i)){ 		
		$('meta[name="viewport"]').attr('content', 'height=device-height,width=device-width,initial-scale=0.5, user-scalable=yes, minimum-scale=0.5, maximum-scale=0.5');
		}else{
		$('meta[name="viewport"]').attr('content', 'height=650,width=device-width,initial-scale=0.5, user-scalable=yes, minimum-scale=0.5, maximum-scale=1');
		
		}
		

	}else{
		$('meta[name="viewport"]').attr('content', 'height=device-height,width=device-width,initial-scale=1.0,user-scalable=no,minimum-scale=1.0,maximum-scale=1.0');
	}
	
	//if(support=="tablet" ){ $("body, html").width("1030px");}

}
/*
function getCookie(sName) {
        var oRegex = new RegExp("(?:; )?" + sName + "=([^;]*);?");
 
        if (oRegex.test(document.cookie)) {
                return decodeURIComponent(RegExp["$1"]);
        } else {
                return null;
        }
}*/

function setCookie(sName, sValue) {
        var today = new Date(), expires = new Date();
        expires.setTime(today.getTime() + (365*24*60*60*1000));
        document.cookie = sName + "=" + encodeURIComponent(sValue) + ";expires=" + expires.toGMTString();
}


/////////////////////////////////////////////////////////////fonctions	clickclear/clickrecall	
function clickclear(thisfield, defaulttext){
	if (thisfield.value == defaulttext) {thisfield.value = '';}
}	
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == '') {thisfield.value = defaulttext;}
}
 
/////////////////////////////////////////////////////////////fonctions convertRGB	 
function convertRGB(rgb) {
	rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
    function hex(x) {return ("0" + parseInt(x).toString(16)).slice(-2);}
    return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}


