var ua = navigator.userAgent;
var browser;

var x=0;
var y=0;
var isDragging = false;
var imgCoords;
var widthZoom;
var ratio;
var previewWidth = previewHeight = 250;
var axe;
var xObjmid=0;
var yObjmid=0;
var objectToDrag;

var imgX=0;
var imgY=0;
var imgHeight=0;
var imgWidth=0;
var imgCoords=[0,0];
var cursor;
var nav="";
var fromloadzoom=false;
var countReload=0;

		
function getPositionCurseur(e){

  var DocRef;    // Variable pour IE uniquement

  // L'événement est passée à la fonction
  // donc tous sauf IE…
  if(e){                     // Dans ce cas on obtient directement la position dans la page
    x = e.pageX;
    y = e.pageY;
  }
  
  if(y>=0 && x>=0)
  {}else{
  nav="ie";
    x = event.clientX;
    y = event.clientY;

    //-- Il faut traiter le CAS des DOCTYPE sous IE
    if( document.documentElement && document.documentElement.clientWidth) // Donc DOCTYPE
      DocRef = document.documentElement;   // Dans ce cas c'est documentElement qui est réfèrence
    else
      DocRef = document.body;                    // Dans ce cas c'est body qui est réfèrence

    //-- On rajoute la position liée aux ScrollBars
    x += DocRef.scrollLeft;
    y += DocRef.scrollTop;
  }
}
		
function findPos(obj){
	var curleft = curtop = 0;
	curleft = obj.offsetLeft;
	curtop = obj.offsetTop;
	return [curleft,curtop];
}
		
function showZoom(url){
if(!document.getElementById('cursor'))
{
	var html='<div id="cursor" onmouseover="showZoom(document.getElementById(\'urlZoom\').value);" onmousemove="drag(event);" onmouseout="hideZoom();" style="background-color:#FFF; display:none; filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0.5; z-index:2; position:absolute; border:2px solid #000000;cursor:crosshair;" > </div>';
	document.getElementById('master').innerHTML+=html;
}

	if(document.getElementById("img1"))
	{
		imgWidth = document.getElementById("img1").offsetWidth;
		imgHeight = document.getElementById("img1").offsetHeight;
		imgCoords = findPos(document.getElementById("img1"));
		
		if (ua.indexOf("MSIE 7")!=-1){ 	
			IE7imagePos=GetRealOffset("img1");
			if(document.getElementById("image").offsetLeft<50)
			{
				imgCoords[0]=IE7imagePos.left - document.getElementById("master").offsetLeft;
				imgCoords[1]=IE7imagePos.top - document.getElementById("master").offsetTop;
			}
		}
	
		document.getElementById("wImgZoom").value=document.getElementById("imgZoom").width;
		ratio = document.getElementById("imgZoom").width/document.getElementById("img1").width;
	
		if(fromloadzoom!=true) document.getElementById("cursor").style.display="block";
	
		if(ratio>0)
		{
			if((previewWidth/ratio)<500 && (previewHeight/ratio)<500 && (previewWidth/ratio)!=null && (previewHeight/ratio)!=null)
			{
				document.getElementById("cursor").style.width = (previewWidth/ratio)+"px";
				document.getElementById("cursor").style.height = (previewHeight/ratio)+"px";
			}
		}
	//	beginDrag(document.getElementById("cursor"),null);
	}
	
	var imgbwidth = parseInt(document.getElementById("wImgb").value,10);
	
	var incBorder=parseInt(document.getElementById("img1").offsetWidth-document.getElementById("img1").width);
	document.getElementById("zoom").style.width=previewWidth+"px";
	document.getElementById("zoom").style.height=previewHeight+"px";
	document.getElementById("zoom").style.left = (imgCoords[0]+imgbwidth+5+incBorder)+"px";
	document.getElementById("zoom").style.top = imgCoords[1]+"px";
	if(fromloadzoom!=true) document.getElementById("zoom").style.display="block";
		
	loadZoom(url);
	
		if(fromloadzoom==true)
		{
			fromloadzoom=false;
		}
}

function loadZoom(url){

	document.getElementById("urlZoom").value=url; 
	document.getElementById("imgZoom").src = document.getElementById("urlZoom").value;
	
	ratio = document.getElementById("imgZoom").width/document.getElementById("img1").width;
		
	if(ratio==1)
	{
		if(document.getElementById("imgZoom").width==document.getElementById("img1").width)document.getElementById("imgZoom").width=document.getElementById("imgZoom").width*2;
		if(document.getElementById("imgZoom").height==document.getElementById("img1").height)document.getElementById("imgZoom").height=document.getElementById("imgZoom").height*2;
		document.getElementById("wImgZoom").value=document.getElementById("imgZoom").width;
		widthZoom = document.getElementById("wImgZoom").value;
		heightZoom = document.getElementById("imgZoom").height;
		ratioW = widthZoom/imgWidth;
		ratioH = heightZoom/imgHeight;
		
		if(ratioW <= ratioH)
		{
			ratio=ratioW;
		}else{
			ratio=ratioH;
		}

		if((previewWidth/ratio)<500 && (previewHeight/ratio)<500 && (previewWidth/ratio)!=null && (previewHeight/ratio)!=null)
		{
			document.getElementById("cursor").style.width = (previewWidth/ratio)+"px";
			document.getElementById("cursor").style.height = (previewHeight/ratio)+"px";
		}
	}
	

	if(document.getElementById("cursor").style.width<10 || document.getElementById("cursor").style.width>500 || document.getElementById("cursor").style.width==null)
	{
			fromloadzoom=true;
		if(countReload<5)
		{
			countReload++;
			setTimeout("showZoom('"+url+"')",200);
		}else{
			if(countReload<10)
			{
				countReload++;
				setTimeout("showZoom('"+url+"')",400);
			}else{
				if(countReload<15)
				{
					countReload++;
					setTimeout("showZoom('"+url+"')",600);
				}
			}
		}
	}
}

function loadZoomBis(url)
{
	document.getElementById("urlZoom").value=url; 
	document.getElementById("imgZoom").src = document.getElementById("urlZoom").value;
}
		
function hideZoom(){
	document.getElementById("zoom").style.display="none";
	document.getElementById("cursor").style.display="none";
}
		
function GetRealOffset(id)
{
    var elem = document.getElementById(id);
    var leftOffset = elem.offsetLeft;
    var topOffset = elem.offsetTop;
    var parent = elem.offsetParent;
 
 var i=1;
        while(parent != null && i<20) 
    {
             leftOffset += parent.offsetLeft;
         topOffset += parent.offsetTop;
            parent = parent.offsetParent;
		i++;	
    }
	
        var Offsets = new Object();
    Offsets.top = topOffset;
    Offsets.left = leftOffset;
 
    //alert(Offsets.top + " " +Offsets.left)
    return Offsets;
}
		
function drag(e){

	var newPosX = 0;
	var newPosY = 0;
	
	var curW=(previewWidth/ratio);
	var curH=(previewHeight/ratio);
	
	getPositionCurseur(e);
			
	var imgCoordsimage = Array();
	var imgCoordsmaster = findPos(document.getElementById("master"));
	imgCoordsimagediv = findPos(document.getElementById("image"));
	imgCoordsimage["deb"] = findPos(document.getElementById("image"));

	var incBorder=parseInt(document.getElementById("img1").offsetWidth-document.getElementById("img1").width)/2;
	
	imgCoordsimage["deb"][0] = imgCoordsimage["deb"][0] + incBorder;
	imgCoordsimage["deb"][1] = imgCoordsimage["deb"][1] + incBorder;

	if (ua.indexOf("MSIE 7")!=-1){ 	
		IE7imagePos=GetRealOffset("image");
		imgCoordsimage["deb"][0]=IE7imagePos.left + incBorder - document.getElementById("master").offsetLeft;
		imgCoordsimage["deb"][1]=IE7imagePos.top + incBorder - document.getElementById("master").offsetTop;
		document.getElementById("cursor").style.position="absolute";
	}
	
	imgCoordsimage["fin"] = findPos(document.getElementById("img1"));
	imgCoordsimage["fin"][0] = imgCoordsimage["deb"][0]  + parseInt(document.getElementById("img1").width);
	imgCoordsimage["fin"][1] = imgCoordsimage["deb"][1]  + parseInt(document.getElementById("img1").height);

	newPosY = y - imgCoordsmaster[1] - curH/2;
	newPosX = x - imgCoordsmaster[0] - curW/2;
				
	if(newPosY<=imgCoordsimage["deb"][1])
	{
		newPosY=imgCoordsimage["deb"][1];
		
	}else if(newPosY+curH>=imgCoordsimage["fin"][1])
	{
		newPosY=imgCoordsimage["fin"][1]-curH-4;
	}
	
	if(newPosX<=imgCoordsimage["deb"][0])
	{
		newPosX=imgCoordsimage["deb"][0];
		
	}else if(newPosX+curW>=imgCoordsimage["fin"][0]){
		newPosX=imgCoordsimage["fin"][0]-curW-4;
	}

	var left=(newPosX)+"px";
	var top=(newPosY)+"px";
	
	document.getElementById("cursor").style.left = left;
	document.getElementById("cursor").style.top = top;
		
	if(document.getElementById("cursor").style.display=="block")
	{
		document.getElementById("imgZoom").style.left = (((imgCoordsimage["deb"][0] - incBorder - newPosX)*ratio))+"px";
		document.getElementById("imgZoom").style.top = (((imgCoordsimage["deb"][1] - incBorder - newPosY)*ratio))+"px";
	}
}

function quantity(type,obj){
	if(type=='moins' && obj.value>1)
		obj.value=parseInt(obj.value)-1;
	else if(type=='plus')
		obj.value=parseInt(obj.value)+1;
}
function checkEmail(stringIn) {
	if (stringIn.indexOf("@") < 1){
		return false;
	}else{
		st = stringIn.substr(stringIn.indexOf("@"));
		if(st.indexOf(".") == -1){
			return false;
		}else{
			if(!checkNormalChar(stringIn)){
				return false;
			}else{
				return true;
			}
		}
	}
}
function checkNormalChar(stringIn) {
	 retval = false 
	 var i;
     for (i=0;i<=stringIn.length-1;i++) { 
     	 //cho phep nhung ky tu tu A->Z, a->z, 0->9,va cac ky tu @,_
	      if (((stringIn.charCodeAt(i) >= 48)&&(stringIn.charCodeAt(i) <= 57)) || ((stringIn.charCodeAt(i) >= 64)&&(stringIn.charCodeAt(i) <= 90)) || ((stringIn.charCodeAt(i) >= 97)&&(stringIn.charCodeAt(i) <= 122)) ||(stringIn.charCodeAt(i)==95) ||(stringIn.charCodeAt(i)==46) ||(stringIn.charCodeAt(i)==45)) { 
                retval = true;
      	  }else{
      	  		retval = false;
      	  		break;
         }
     }
	 return retval;
}
function change_zoom(id,pid,nzoom,newid,newvalue,ids,ids2){
	if(document.getElementById(id)){
		if(document.getElementById(id).style.display == "inline"){
			document.getElementById(id).style.display = "none";
			document.getElementById(id).style.position = "";
			if(newid && newvalue){
				if(document.getElementById('change_pdzoom').value=='1'){
					document.getElementById('pd_zoom').style.display = 'none';
				}else{
					document.getElementById('pd_zoom').style.display = '';
				}
			}
			if(ids){
				hide_all(ids);
			}
			if(newid){
				document.getElementById(newid).value = 'product_zoom';
				if(document.getElementById('pdtid_defaut'))	document.getElementById('change_img_hd').value = document.getElementById('pdtid_defaut').value;
			}
		}else{
			if(ids && ids2){
				hide_all(ids);
				hide_all(ids2);
			}
			document.getElementById(id).style.display = "inline";
			document.getElementById(id).style.position = "absolute";
			if(newid && newvalue){
				document.getElementById(newid).value = newvalue;
			}
			if(pid){
				document.getElementById('change_img_hd').value = pid;
				if(document.getElementById('pid_'+pid)){
					document.getElementById('pdtimg_'+pid).src=document.getElementById('pid_'+pid).value;
				}
			}
			if(document.getElementById('pd_zoom')){
				if(nzoom=='1'){
					document.getElementById('pd_zoom').style.display = 'none';
				}else{
					document.getElementById('pd_zoom').style.display = '';
				}
			}
		}
	}
}
function hideshow_id(id,type){
	if(document.getElementById(id)){
		if(type==1)
			document.getElementById(id).style.display = '';
		else
			document.getElementById(id).style.display = 'none';
	}
}
function getElementsByName_iefix(tag, name) {
	 var elem = document.getElementsByTagName(tag);
	 var arr = new Array();
	 for(i = 0,iarr = 0; i < elem.length; i++) {
		  att = elem[i].getAttribute("name");
		  if(att == name) {
			   arr[iarr] = elem[i];
			   iarr++;
		  }
	 }
	 return arr;
}
function hide_all(id){
	for(var i=0;i<(getElementsByName_iefix('div',id).length);i++){
		getElementsByName_iefix('div',id)[i].style.display = "none";
		getElementsByName_iefix('div',id)[i].style.position = "";
	}
}
function hideall_class(type,id){
	for(var i=0;i<(getElementsByName_iefix(type,id).length);i++){
		getElementsByName_iefix(type,id)[i].className = "";
	}
}
function hideall(nzoom,newid,pid,ids,ids2){
	if(ids && ids2){
		hide_all(ids);
		hide_all(ids2);
	}
	document.getElementById(newid).value = 'product_zoom';
	document.getElementById('change_img_hd').value = pid;
	if(document.getElementById('pd_zoom')){
		if(nzoom=='1'){
			document.getElementById('pd_zoom').style.display = 'none';
		}else{
			document.getElementById('pd_zoom').style.display = '';
		}
	}
}

function writeCookie(nom,valeur,jours) {
var expDate = new Date()
expDate.setTime(expDate.getTime() + (jours * 24 * 3600 * 1000))
document.cookie = nom + "=" + escape(valeur)+ ";expires=" + expDate.toGMTString()
}
// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}	

if(getCookie( 'user_resolution' ) == null){
	writeCookie('user_resolution',screen.width +"x"+ screen.height,30);
}
/* LOGO RECEIVE&PAY in left.php*/
function popupcalc(merchantID,montant){ 		
	var win2 = window.open("http://www.receiveandpay.com/wallet/customer/calculette.php?MerchantID="+merchantID+"&Amount="+montant ,'popup','height=503,width=600,status=yes,scrollbars=yes,menubar=no,resizable=yes'); 
}
function popupRnp(name,url,width,height)
{
  var var_popuprnp = window.open(url, name ,'height='+height+',width='+width+',status=yes,scrollbars=yes,menubar=no,resizable=yes');
}

function popupWin(name,url,height)
{ 		
	window.open(url ,name,'height=705,width=615,status=yes,scrollbars=yes,menubar=no,resizable=yes'); 
}

function sf_innerHTML(id,value){
	if(document.getElementById(id)){
		document.getElementById(id).innerHTML = value;
	}
}

if (ua.indexOf("MSIE")!=-1){
	browser="ie";
}
else if(ua.indexOf("Firefox")!=-1){
	browser="ff";
}
else if (ua.indexOf("Safari")!=-1 || ua.indexOf("Chrome")!=-1){
	browser="webkit";	
}
else{
	browser="opera";
}

function addToFavorite(url,title){

   if(browser=="ff") {
		window.sidebar.addPanel(title,url,"");
   }
   else if(browser=="ie"){ 
		window.external.AddFavorite(url,title);
   }
}

function trim(myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
} 

function SF_PrintIframe(name){
	frames[name].focus();
	frames[name].print();
}


















/******  fonctions de vérification de champs  *****/

function checkEmail(stringIn) {
	if (stringIn.indexOf("@") < 1){
		return false;
	}else{
		st = stringIn.substr(stringIn.indexOf("@"));
		if(st.indexOf(".") == -1){
			return false;
		}else{
			if(!checkNormalChar(stringIn)){
				return false;
			}else{
				return true;
			}
		}
	}
}

function checkNormalChar(stringIn) {
	 retval = false 
	 var i;
     for (i=0;i<=stringIn.length-1;i++) { 
     	 // Caractères autorisés :  A->Z, a->z, 0->9 @,_
	      if (((stringIn.charCodeAt(i) >= 48)&&(stringIn.charCodeAt(i) <= 57)) || ((stringIn.charCodeAt(i) >= 64)&&(stringIn.charCodeAt(i) <= 90)) || ((stringIn.charCodeAt(i) >= 97)&&(stringIn.charCodeAt(i) <= 122)) ||(stringIn.charCodeAt(i)==95) ||(stringIn.charCodeAt(i)==46) ||(stringIn.charCodeAt(i)==45)) { 
                retval = true;
      	  }else{
      	  		retval = false;
      	  		break;
         }
     }
	 return retval;
}

// teste un champ pour vérifier qu'il ne contient que des 
// caractères alphanumériques, minuscules ou majuscules
// avec des contraintes de taille
// text : champ à tester
// length_min : taille minimale du champ
// length_max : taille maximal du champ
function isAlphaNumerique (text, length_min, length_max) 
{
	var pattern = '^[a-zA-Z0-9]{'+length_min+','+length_max+'}$';
	var comparaison = new RegExp(pattern,'g');
	
	if (comparaison.test(text)) return true;
	else return false;
}

function AddToFavorites (name, url) 
{
	if (window.sidebar) {        // Firefox
		window.sidebar.addPanel (name, url,'');
	} 
	else {
		if (window.external && typeof (window.external.AddFavorite) !== "undefined") {
				// Internet Explorer
			window.external.AddFavorite (url, name);
		}
	}
}

function number_format( number, decimals, dec_point, thousands_sep ) {
	// http://kevin.vanzonneveld.net
	// + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
	// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// + bugfix by: Michael White (http://crestidg.com)
	// + bugfix by: Benjamin Lupton
	// + bugfix by: Allan Jensen (http://www.winternet.no)
	// + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
	// * example 1: number_format(1234.5678, 2, '.', '');
	// * returns 1: 1234.57
	 
	var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
	var d = dec_point == undefined ? "," : dec_point;
	var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
	var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	 
	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}


function strpos (haystack, needle ) {
    // Finds position of first occurrence of a string within another  
    // 
    // version: 1107.2516
    // discuss at: http://phpjs.org/functions/strpos    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // +   bugfixed by: Daniel Esteban
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);    // *     returns 1: 14
    var i = (haystack + '').indexOf(needle, 0);
    return i === -1 ? false : true;
}


/*****
 * Animation JAC: javascipt animation component
 * Style: .jac_... (basic.css)
 * Html: /docs/animation_jac.html
 *****/
var BrowserDetect = {
            init: function () {
                  this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
                  this.version = this.searchVersion(navigator.userAgent)
                        || this.searchVersion(navigator.appVersion)
                        || "an unknown version";
            },
            searchString: function (data) {
                  for (var i=0;i<data.length;i++)    {
                        var dataString = data[i].string;
                        var dataProp = data[i].prop;
                        this.versionSearchString = data[i].versionSearch || data[i].identity;
                        if (dataString) {
                             if (dataString.indexOf(data[i].subString) != -1)
                                   return data[i].identity;
                        }
                        else if (dataProp)
                             return data[i].identity;
                  }
            },
            searchVersion: function (dataString) {
                  var index = dataString.indexOf(this.versionSearchString);
                  if (index == -1) return;
                  return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
            },
            dataBrowser: [
                  {
                        string: navigator.userAgent,
                        subString: "Chrome",
                        identity: "Chrome"
                  },
                  {     string: navigator.userAgent,
                        subString: "OmniWeb",
                        versionSearch: "OmniWeb/",
                        identity: "OmniWeb"
                  },
                  {
                        string: navigator.vendor,
                        subString: "Apple",
                        identity: "Safari",
                        versionSearch: "Version"
                  },
                  {
                        prop: window.opera,
                        identity: "Opera",
                        versionSearch: "Version"
                  },
                  {
                        string: navigator.vendor,
                        subString: "iCab",
                        identity: "iCab"
                  },
                  {
                        string: navigator.vendor,
                        subString: "KDE",
                        identity: "Konqueror"
                  },
                  {
                        string: navigator.userAgent,
                        subString: "Firefox",
                        identity: "Firefox"
                  },
                  {
                        string: navigator.vendor,
                        subString: "Camino",
                        identity: "Camino"
                  },
                  {           // for newer Netscapes (6+)
                        string: navigator.userAgent,
                        subString: "Netscape",
                        identity: "Netscape"
                  },
                  {
                        string: navigator.userAgent,
                        subString: "MSIE",
                        identity: "Explorer",
                        versionSearch: "MSIE"
                  },
                  {
                        string: navigator.userAgent,
                        subString: "Gecko",
                        identity: "Mozilla",
                        versionSearch: "rv"
                  },
                  {           // for older Netscapes (4-)
                        string: navigator.userAgent,
                        subString: "Mozilla",
                        identity: "Netscape",
                        versionSearch: "Mozilla"
                  }
            ]
      };
BrowserDetect.init();
var Old_Browser;
var New_Browser;
var Change_Direction=false;
if(BrowserDetect.browser=='Explorer' &&  parseInt(BrowserDetect.version)<9) {Old_Browser=true;New_Browser=false;} else {Old_Browser=false;New_Browser=true;};
var animations=new Array;
function Animation(id,type,delay,color_a,color_ahover) {
    this.id=id;
    this.type=type;
    this.number=0;
    this.delay=delay;
	this.color_a=color_a;
	this.color_ahover=color_ahover;
	this.count=1;
	this.delay_left=0;
	this.current=1;
	this.sens=true;
	this.pagination=true;
	this.pause=false;
}
 // MAJ STYLES
 function SetStyle(idf){
  if (document.getElementById) {
        if(document.getElementById(idf))
      return document.getElementById(idf).style;
    } else if (document.all) {
    return document.all[idf].style;
    } else if (document.layers) {
    return document.layers[idf];
    } else { return null; }
}

 // ANIMATION 1 - FONDU ENCHAINE
function Jac1(id,frame){
	for(var i=1; i<=parseInt(animations[id].number); i++){
		if (animations[id].pagination) {
			SetStyle('jac_pag_'+id+'_'+i).color=animations[id].color_a;
			SetStyle('jac_pag_'+id+'_'+i).border='2px solid '+animations[id].color_a;
		}
		if(Old_Browser)
			{SetStyle('jac_'+id+'_'+i).display='none';}
		else
			{SetStyle('jac_'+id+'_'+i).opacity=0;SetStyle('jac_'+id+'_'+i).zIndex='1'}	
    }
	if (animations[id].pagination) {
		SetStyle('jac_pag_'+id+"_"+frame).color=animations[id].color_ahover;
		SetStyle('jac_pag_'+id+"_"+frame).border='2px solid '+animations[id].color_ahover;
	}
	if(Old_Browser)
		{SetStyle('jac_'+id+"_"+frame).display='block';}
	else	
		{SetStyle('jac_'+id+"_"+frame).opacity=1;SetStyle('jac_'+id+"_"+frame).zIndex='5';}
}

 // ANIMATION 2 - TRANSLATION DROITE A GAUCHE
function Jac2(id,frame){
	var larg=parseInt(document.getElementById('jac_cont_'+id).offsetWidth);
	if (animations[id].pagination)
	{
	for(var i=1; i<=parseInt(animations[id].number); i++)
		{
		SetStyle('jac_pag_'+id+'_'+i).color=animations[id].color_a;
		SetStyle('jac_pag_'+id+'_'+i).border='2px solid '+animations[id].color_a;
		}
	SetStyle('jac_pag_'+id+"_"+frame).color=animations[id].color_ahover;
	SetStyle('jac_pag_'+id+"_"+frame).border='2px solid '+animations[id].color_ahover;
	}
	var posx=frame-2;
	for(var i=1; i<=parseInt(animations[id].number); i++)
		{
			posx=posx+1;
			if (posx>parseInt(animations[id].number)){posx=1}
			if (posx==0){posx=parseInt(animations[id].number)}
			if (i==parseInt(animations[id].number)){SetStyle('jac_'+id+'_'+posx).display='none'} else {SetStyle('jac_'+id+'_'+posx).display='block'}
			SetStyle('jac_'+id+'_'+posx).left=(i-2)*larg+'px';
		}
}

 // ANIMATION 3 - CAROUSSEL
function Jac3(id,frame){
	var larg=parseInt(document.getElementById('jac_cont_'+id).offsetWidth/5);
	if (animations[id].pagination)
	{
	for(var i=1; i<=parseInt(animations[id].number); i++)
		{
		SetStyle('jac_pag_'+id+'_'+i).color=animations[id].color_a;
		SetStyle('jac_pag_'+id+'_'+i).border='2px solid '+animations[id].color_a;
		}
	SetStyle('jac_pag_'+id+"_"+frame).color=animations[id].color_ahover;
	SetStyle('jac_pag_'+id+"_"+frame).border='2px solid '+animations[id].color_ahover;
	}
	var posx=frame+3;
	for(var i=1; i<=parseInt(animations[id].number); i++)
		{
		posx=posx+1;
		if (posx>parseInt(animations[id].number)){posx=posx-parseInt(animations[id].number)}
		if (i==parseInt(animations[id].number)){SetStyle('jac_'+id+'_'+posx).display='none'} else {SetStyle('jac_'+id+'_'+posx).display='block'}
		SetStyle('jac_'+id+'_'+posx).left=(i-2)*larg+'px';
		SetStyle('jac_'+id+'_'+posx).width=larg*0.6+'px';SetStyle('jac_'+id+'_'+posx).height=larg*0.6+'px';
		if (i==3) {SetStyle('jac_'+id+'_'+posx).width=larg*0.8+'px';SetStyle('jac_'+id+'_'+posx).height=larg*0.8+'px';}
		if (i==5) {SetStyle('jac_'+id+'_'+posx).width=larg*0.8+'px';SetStyle('jac_'+id+'_'+posx).height=larg*0.8+'px';}
		if (i==4) {SetStyle('jac_'+id+'_'+posx).width=larg*1+'px';SetStyle('jac_'+id+'_'+posx).height=larg*1+'px';}
		}
}
 // ANIMATION 4 - DEFILEMENT
function Jac4(id,frame){
	var larg=parseInt(document.getElementById('jac_cont_'+id).offsetWidth/5);
	if (animations[id].pagination)
	{
	for(var i=1; i<=parseInt(animations[id].number); i++)
		{
		SetStyle('jac_pag_'+id+'_'+i).color=animations[id].color_a;
		SetStyle('jac_pag_'+id+'_'+i).border='2px solid '+animations[id].color_a;
		}
	SetStyle('jac_pag_'+id+"_"+frame).color=animations[id].color_ahover;
	SetStyle('jac_pag_'+id+"_"+frame).border='2px solid '+animations[id].color_ahover;
	}
	var posx=frame+3;
	for(var i=1; i<=parseInt(animations[id].number); i++)
		{
		posx=posx+1;
		if (posx>parseInt(animations[id].number)){posx=posx-parseInt(animations[id].number)}
		if (i==parseInt(animations[id].number)){SetStyle('jac_'+id+'_'+posx).display='none'} else {SetStyle('jac_'+id+'_'+posx).display='block'}
		SetStyle('jac_'+id+'_'+posx).left=(i-2)*larg+'px';
		SetStyle('jac_'+id+'_'+posx).width=larg+'px';SetStyle('jac_'+id+'_'+posx).height=larg+'px';
		}
}

 // PAUSE SUR ANIMATION
function Jac_Pause(id,frame){
	SetStyle('jac_'+id+'_'+frame).cursor='pointer';
	if (animations[id].type==3)
	{
		var larg=parseInt(document.getElementById('jac_cont_'+id).offsetWidth/5);
		for(var i=1; i<=parseInt(animations[id].number); i++)
		{
		SetStyle('jac_'+id+'_'+i).width=larg*0.6+'px';SetStyle('jac_'+id+'_'+i).height=larg*0.6+'px';
		}
		SetStyle('jac_'+id+'_'+frame).width=larg+'px';
		SetStyle('jac_'+id+'_'+frame).height=larg+'px';
		if (frame==1)
		{
			SetStyle('jac_'+id+'_'+(parseInt(animations[id].number))).width=larg*0.8+'px';
			SetStyle('jac_'+id+'_'+(parseInt(animations[id].number))).height=larg*0.8+'px';
			SetStyle('jac_'+id+'_'+(frame+1)).width=larg*0.8+'px';
			SetStyle('jac_'+id+'_'+(frame+1)).height=larg*0.8+'px';
		}
		else
		{
			if (frame==parseInt(animations[id].number))
			{
				SetStyle('jac_'+id+'_'+(frame-1)).width=larg*0.8+'px';
				SetStyle('jac_'+id+'_'+(frame-1)).height=larg*0.8+'px';
				SetStyle('jac_'+id+'_'+'1').width=larg*0.8+'px';
				SetStyle('jac_'+id+'_'+'1').height=larg*0.8+'px';
			}
			else
			{
				SetStyle('jac_'+id+'_'+(frame-1)).width=larg*0.8+'px';
				SetStyle('jac_'+id+'_'+(frame-1)).height=larg*0.8+'px';
				SetStyle('jac_'+id+'_'+(frame+1)).width=larg*0.8+'px';
				SetStyle('jac_'+id+'_'+(frame+1)).height=larg*0.8+'px';
			}
		}
	}
	animations[id].pause=true;
}
 // REPRISE SUR ANIMATION
function Jac_Run(id,frame){
SetStyle('jac_'+id+'_'+frame).cursor='auto';
animations[id].pause=false;

}
 // CLICK SUR PAGINATION
function Jac_Click(id,frame){
	for(var i=1; i<=parseInt(animations[id].number); i++)
	{
		SetStyle('jac_'+id+'_'+i).MozTransition='none';
		SetStyle('jac_'+id+'_'+i).WebkitTransition='none';
		SetStyle('jac_'+id+'_'+i).transition='none';
		if (i==frame){SetStyle('jac_'+id+'_'+i).display='block';SetStyle('jac_'+id+'_'+i).left='0px';}else{SetStyle('jac_'+id+'_'+i).display='none';}
	}
	switch (animations[id].type) {
		case 1:
			Jac1(id,frame);animations[id].count=frame;
		break;
		case 2:
			Jac2(id,frame);animations[id].count=frame;
		break;
		case 3:
			Jac3(id,frame);animations[id].count=frame;
		break;
	}
	for(var i=1; i<=parseInt(animations[id].number); i++)
	{
		SetStyle('jac_'+id+'_'+i).MozTransition='all 0.6s linear 0s';
		SetStyle('jac_'+id+'_'+i).WebkitTransition='all 0.6s linear 0s';
		SetStyle('jac_'+id+'_'+i).transition='all 0.6s linear 0s';
		SetStyle('jac_'+id+'_'+i).display='block';
	}
}
 // ONMOUSEOVER SUR PAGINATION
function Jac_Over(id,frame){

	if (frame=='for')
	{
		SetStyle('jac_pag_for_'+id).backgroundColor=animations[id].color_ahover;
	}
	else
	{
		if (frame=='next')
			{SetStyle('jac_pag_next_'+id).backgroundColor=animations[id].color_ahover;}
	}
}
 // ONMOUSEOUT SUR PAGINATION
function Jac_Out(id,frame){
SetStyle('jac_pag_for_'+id).backgroundColor='transparent';
SetStyle('jac_pag_next_'+id).backgroundColor='transparent';
}
 // CLICK SUR DROITE
function Jac_For(id){
	for(var i=1; i<=parseInt(animations[id].number); i++)
	{
		SetStyle('jac_'+id+'_'+i).MozTransition='none';
		SetStyle('jac_'+id+'_'+i).WebkitTransition='none';
		SetStyle('jac_'+id+'_'+i).transition='none';
	}
	if (animations[id].sens==true) {Change_Direction=true;}
	animations[id].sens=true;
	for(var i=1; i<=parseInt(animations[id].number); i++)
	{
		SetStyle('jac_'+id+'_'+i).MozTransition='all 0.6s linear 0s';
		SetStyle('jac_'+id+'_'+i).WebkitTransition='all 0.6s linear 0s';
		SetStyle('jac_'+id+'_'+i).transition='all 0.6s linear 0s';
	}
}
 // CLICK SUR GAUCHE
function Jac_Back(id){
	for(var i=1; i<=parseInt(animations[id].number); i++)
	{
		SetStyle('jac_'+id+'_'+i).MozTransition='none';
		SetStyle('jac_'+id+'_'+i).WebkitTransition='none';
		SetStyle('jac_'+id+'_'+i).transition='none';
	}
	if (animations[id].sens==false) {Change_Direction=true;}
	animations[id].sens=false;
	for(var i=1; i<=parseInt(animations[id].number); i++)
	{
		SetStyle('jac_'+id+'_'+i).MozTransition='all 0.6s linear 0s';
		SetStyle('jac_'+id+'_'+i).WebkitTransition='all 0.6s linear 0s';
		SetStyle('jac_'+id+'_'+i).transition='all 0.6s linear 0s';
	}
}

 // BOUCLE GENERALE
function Jac_Loop() {
	for(var i=1; i<=animations.length-1; i++){
		if (animations[i].pause==false){animations[i].delay_left=animations[i].delay_left-1;}
		if (animations[i].delay_left<=0) {
			animations[i].delay_left=animations[i].delay;
			if (animations[i].sens) {
				if (animations[i].count>animations[i].number) {animations[i].count=1;}
				}
			else {
				if (animations[i].count<=0) {animations[i].count=animations[i].number;}
				}
		
			switch (animations[i].type) {
				case 1:
					Jac1(i,animations[i].count);
				break;
				case 2:
					Jac2(i,animations[i].count);
				break;
				case 3:
					Jac3(i,animations[i].count);
				break;
				case 4:
					Jac4(i,animations[i].count);
				break;
			}
			if (animations[i].sens) {animations[i].count=animations[i].count+1;if (animations[i].count>animations[i].number) {animations[i].count=1;}}
			else {animations[i].count=animations[i].count-1;if (animations[i].count<=0) {animations[i].count=animations[i].number;}}

		}
	}
	if (Change_Direction==true)
		{Change_Direction=false;setTimeout('Jac_Loop();',1);}
	else
		{Change_Direction=false;setTimeout('Jac_Loop();',100);}
}

 // INITIALISATION ANIMATION
function Jac_Ini_Anim(id,type,number_frame,time,color_a,color_ahover,show_pagination) {
	var frame_with=document.getElementById('jac_cont_'+id).offsetWidth;
	var frame_height=document.getElementById('jac_cont_'+id).offsetHeight;
	var temp=new Animation(id,type,time,color_a,color_ahover)
	animations[id]=temp;
	animations[id].number=number_frame;
	SetStyle('jac_fix_'+id).width=frame_with+'px';
	SetStyle('jac_fix_'+id).height=frame_height+'px';	
    for(var i=1; i<=number_frame; i++){
		document.getElementById('jac_'+id+'_'+i).setAttribute('onmouseover','Jac_Pause('+id+','+i+');');
		document.getElementById('jac_'+id+'_'+i).setAttribute('onmouseout','Jac_Run('+id+','+i+');');
		if (type==3) 
			{
			SetStyle('jac_'+id+'_'+i).width=frame_with/5+'px';
			SetStyle('jac_'+id+'_'+i).height=frame_with/5+'px';
			}
		else
			{
			SetStyle('jac_'+id+'_'+i).width=frame_with+'px';
			SetStyle('jac_'+id+'_'+i).height=frame_height+'px';
			}
    }
	code_pagination='';
    for(var i=1; i<=number_frame; i++){
		code_pagination=code_pagination+'<a id="jac_pag_'+id+'_'+i+'" onclick="Jac_Click('+id+','+i+');">'+i+'</a>';
	}
	document.getElementById('jac_pag_'+id).innerHTML = code_pagination;
	SetStyle('jac_pag_'+id).top=frame_height-28+'px';
	SetStyle('jac_pag_'+id).left=frame_with-28*number_frame-10+'px';
	if (frame_with<=28*number_frame+10 || type==3 || type==4) { // Si il n'y a pas assez de place pour afficher la pagination ou si c'est un caroussel
		code_pagination='<a id="jac_pag_for_'+id+'" onmouseover="Jac_Over('+id+',\'for\');" onmouseout="Jac_Out('+id+',\'for\');" onclick="Jac_For('+id+');">&lt;</a>'+'<a id="jac_pag_next_'+id+'" onmouseover="Jac_Over('+id+',\'next\');" onmouseout="Jac_Out('+id+',\'next\');" onclick="Jac_Back('+id+');">&gt;</a>';
		document.getElementById('jac_pag_'+id).innerHTML = code_pagination;
		SetStyle('jac_pag_for_'+id).color=animations[id].color_a;
		SetStyle('jac_pag_for_'+id).border='2px solid '+animations[id].color_a;
		SetStyle('jac_pag_next_'+id).color=animations[id].color_a;
		SetStyle('jac_pag_next_'+id).border='2px solid '+animations[id].color_a;
		SetStyle('jac_pag_'+id).left=frame_with-60+'px';
		animations[id].pagination=false;
		}
	if (show_pagination==0) {SetStyle('jac_pag_'+id).display='none';}
	Jac_Click(id,1)
}
/* End Animation JAC */
