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';
		}
}
 // ANIMATION 5 - DEFILEMENT LENT
function Jac5(id,frame){
	var larg=96;
	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++)
	{
		if (animations[id].type==5) 
		{
		SetStyle('jac_'+id+'_'+i).MozTransition='all 1.2s linear 0s';
		SetStyle('jac_'+id+'_'+i).WebkitTransition='all 1.2s linear 0s';
		SetStyle('jac_'+id+'_'+i).transition='all 1.2s linear 0s';
		SetStyle('jac_'+id+'_'+i).display='block';
		}
		else
		{
		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;
				case 5:
					Jac5(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)
}
 
