//Initialisation pour fiche produit
$(document).ready(function (){
   initInfos();
	if($("#layerDetails").is("div")){loadDetails();}//dans scripts/onglets.js
});

var initInfos = (function (){
	if ($(".qtyBloc a.incLink").length > 0) {
		initIncDec();
	}//dans scripts/incQuantity.js
	if($("#infosDownload").is("div")){initInfosDownload();}//dans scripts/infosDownload.js
	//if($("#diapoImg").is("div")){
	try{
		diapo.init();
		animateDiapo();
	}catch(e){}
	//}//dans scripts/slideShow.js
	
	if($("#infosServices").is("div")){initServices2();initServices();}//dans scripts/infosDownload.js;   
	if($("#infosServicesComp").is("div")){initServicesComp();}
	if($(".complemataryProducts").is("div")){miniFarandole._Init();}//miniFarandole de la fiche produit
});

//bulle service
var initServices = (function (){
   $("#infosServices").hide();
   $("a.loadInfosServices").click(function() {      
      $("#infosServices").load(this.href, function(){closeService();});
      $("#infosServices").show();
      return false;
   });   
});

var initServicesComp = (function (){
   $("#infosServicesComp").hide();
   $("a.loadInfosServicesComp").click(function() {      
      $("#infosServicesComp").load(this.href, function(){closeService();});
      $("#infosServicesComp").show();
      return false;
   });   
});

document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
}; 

var initServices2 = (function (){
   $("#infosServices").hide();
   $("a.loadInfosServicesLivraison").click(function() {
		$("#infosServices").load(this.href, function(){closeService();});
		$("#infosServices").show();
		var pos = findPos(this);
		var w = getWindowWidth();
		
		var mainContent = document.getElementsByClassName('mainConteneurType');
		
		
		var wMain = 960;
		var tMain = -20;
		if(mainContent){
			wMain = mainContent[0].offsetWidth;
			tMain += mainContent[0].offsetTop;
		}
		
		var diffWidth = 0;
		if(w>wMain)
			diffWidth =((w-wMain)/2);

		$("#infosServices").css({"position":"absolute","left":(pos.x-diffWidth)+"px","top":(pos.y-tMain)+"px","margin":"0px"});
		//var posPopinLivr = (getWindowHeight() - 180)/2 - 130 ;
		//posPopinLivr = posPopinLivr + ss_getCurrentYPos();
		//$("#infosServices").css("top" ,posPopinLivr+"px");
		return false;
   });   
});
function findPos(obj) {
        var curleft = obj.offsetLeft || 0;
        var curtop = obj.offsetTop || 0;
        while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
        }
        return {x:curleft,y:curtop};
}
var closeService = (function (){
   $("#closeInfosService").click(function() {
      $("#infosServices").hide();
      $("#infosServicesComp").hide();
      return false;
   });
   
   var agt=navigator.userAgent.toLowerCase();
   var is_safari = ((agt.indexOf('safari')!=-1) &&(agt.indexOf('mac')!=-1))?true:false;
   if (is_safari != true){
	 initPopinDeclanche();
   }
});

var animateDiapo = (function (){
   $("#visu300x400").load(function() {
      $(this).fadeIn("slow");
      return false;
   });
});


function ss_getCurrentYPos() {
	if (document.body && document.body.scrollTop) {
		return document.body.scrollTop*1;
	}
	if (document.documentElement && document.documentElement.scrollTop) {
		return document.documentElement.scrollTop*1;
	}
	if (window.pageYOffset) {
		return window.pageYOffset*1;
	}
	return 0;
}
	
function getWindowHeight() {

    var windowHeight=0;

    if (typeof(window.innerHeight)=='number'){
        windowHeight=window.innerHeight;
    }
    else {
		if (document.documentElement && document.documentElement.clientHeight){
			windowHeight = document.documentElement.clientHeight;
		}
		else{
			if (document.body&&document.body.clientHeight) {
				windowHeight=document.body.clientHeight;
			}
		}
    }
	return windowHeight;
}


	
function getWindowWidth() {

    var windowWidth=0;

    if (typeof(window.innerWidth)=='number'){
        windowWidth=window.innerWidth;
    }
    else {
		if (document.documentElement && document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		}
		else{
			if (document.body&&document.body.clientWidth) {
				windowWidth=document.body.clientWidth;
			}
		}
    }
	return windowWidth;
}