$(document).ready(function(){	
	setEventMain();
	initPopins();
	resizeOverlayForPopin();
	hiderElements();
	setLayersSearchMedia();
});

function setEventMain(){
	
	/******************************************************/
				/* NAV LEFT */
	/******************************************************/
	setEventNavLeft();
	
	
	
	/* roll aover sur navTop*/
	$('#navTop li a').each(function(i,obj){				
		$(obj).unbind();			
		$(obj).bind('mouseover',function(){	
			$('#navTop li a').removeClass('hover');
			$(obj).addClass('hover');
			return false;			
		});		
		
		$(obj).bind('mouseout',function(){	
			$('#navTop li a').removeClass('hover');
			return false;			
		});			
	})	
	
	/******************************************************/
					/* Actualité */
	/******************************************************/
	showActus();

	
	/******************************************************/
			/* evenement Sur liste Site groupe */
	/******************************************************/	
	
	$('#header .cmb p.select').unbind('click');
	$("#header .cmb p.select").bind('click',function(){	
		var etatD = $(this).next().css('display').toLowerCase();
		if(etatD == "none"){
			$('#groupSites').hide();
			$(this).next().show();
		}else{
			$(this).next().hide();
		}		 
	 });
	 
	$('#groupSites ul li a').unbind();			
	$('#groupSites ul li a').bind('click',function(){
			$('#groupSites').hide();			
		});			

	/******************************************************/
				/* Onglet Media  */
	/******************************************************/
	
	$('#ongletMedia li').each(function(i,obj){				
		$(obj).unbind();			
		$(obj).bind('click',function(){
				$('#ongletMedia li').removeClass('current');
				$(obj).addClass('current');
				$('#itemMedia > div').hide();
				$('#itemMedia #item_'+(i+1)).show();
				$('#rightSide').attr('style','position:relative;');
				return false;			
			});			
	})
	
	/******************************************************/
		/* select Layers  Country & company */
	/******************************************************/	
		setEventLayers();
	
	
	/*****************************************************/
				/* Select Media */
	/*****************************************************/
		
	$('.selectSearch p.select').unbind('click');
		$(".selectSearch p.select").bind('click',function(){
			var etat = $(this).next().css('display').toLowerCase();
			if(etat == "none"){
				$('.layerS').hide();
				$(this).next().show();
			}else{
				$(this).next().hide();
			}
			return false; 
		});
	  
		$('.layerS ul li a').unbind();			
		$('.layerS ul li a').bind('click',function(){
			var label = $(this).html();
			var select = $(this).parent().parent().parent().prev();
			$('span',select).html(label);
			
				if(select.attr('id')=='mediaSearch'){ // si le select concerne les medias 
					$('span',select).removeClass();
					var idMedia = $(this).attr('id'); // media_1  : photos ,  media_2 : video ....
					if(!idMedia)
						idMedia = 0; // Tous les medias 
					$('span',select).addClass('media_'+idMedia);
				}	
				
			select.next().hide();
			return false;			
		});
	
	
	setEventSelectLayers();/* layers popin */
	
	
	/******************************************************/
			/* agrandissement du texte */
	/******************************************************/	
		setSizeForText();
	
	
	/*****************************************************/
			/* Onglet month  ; Page SSHP */
	/*****************************************************/
		showDetailOngletMonth();

	
	/*****************************************************/
		  /* show list application : Page LIST Appli  */
	/*****************************************************/
		showDetailApplication();

		
}

function showActus(){		
	$('#actualites .visu div').hide();
	$('.visu div#visu_1').show();
				
		$('#actualites a.moreDesc').unbind();
		$('#actualites a.moreDesc').bind('click',function(){
			$('#actualites a.moreDesc').html('+')
			$(this).html('-');
			
			$('#actualites li.deplie').removeClass('deplie');
			$(this).parents('li').addClass('deplie');
			
			$('#actualites .itemActu').css({height: '23px'});
			$('#actualites #firstElm .itemActu').css({height: '36px'});
			
			//resizeBlocActus();	
			
			var index = $('#actualites .detailActu ul li').index($(this).parents('li'));
			
			updateHeightOfDetailActu(this,index);
			$('#actualites .visu div').hide();
			$('.visu div#visu_'+(index+1)).show();			

			return false;			
		});		
}
function updateHeightOfDetailActu(obj,index){
	var detailActu = $(obj).parents('li');
	var itemActu = $('.itemActu',detailActu);
	if(index != 0)
		itemActu.css({height: '53px'});
	else{
		itemActu.css({height: '66px'});
	}
}

function setEventNavLeft(){
	//affiche les current List
	/*$("li.current > ul").show();*/

	// affichage des sous menu nav left
	$('ul#navLeft > li a').unbind();
	$('ul#navLeft > li a').bind('click',function(){
		if($(this).next().length){
			if($(this).next().css('display').toLowerCase()=='none'){//afficher le suivant si il est caché
				$('a.current').removeClass('current');
				$(this).parent().addClass('current');
				$('> ul',$(this).parent()).show();
				
			}else{
				$(this).next().hide()
			}				
		}else{
			$('a.on').removeClass('on');
			$(this).addClass('on');
		}
		return false;
	});
}

function setEventSelectLayers(){
	$('.cmb div.select').unbind('click');
	$('.cmb div.select').bind('click',function(){
			var etat = $(this).next().css('display').toLowerCase();
			if(etat == "none")
				$(this).next().show();
			else
				$(this).next().hide();
			return false; 
		});
	 
	$('.layer ul li a').unbind();			
	$('.layer ul li a').bind('click',function(){	
		var idBloc = $(this).attr('class');
		
		var label = $(this).html();
		var select = $(this).parent().parent().parent().prev();
		$('p span',select).html(label);
		select.next().hide();
		
		
		if(idBloc && $('#'+idBloc).length){
			$('#popinContact .blocC').hide();
			$('#'+idBloc).show();
			$('.msgError').hide();
			$('p.error').removeClass('error');
		}
		
		return false;			
	});	
}

function setSizeForText(){
	
	$('#toolBox a').each(function(i,obj){				
	$(obj).unbind();			
	$(obj).bind('click',function(){	
			var currentClass=$('body').attr('class');		
			if(currentClass){	
				var currentNb=parseInt(currentClass.split('size_')[1]);	
				if($(obj).attr('id')=='textePlus'){
					currentNb++;
					if(currentNb<4)
						var newClass=currentNb.toString();
				}else if($(obj).attr('id')=='texteMoins'){
					currentNb--;
					if(currentNb>-1)
					var newClass=currentNb.toString();
				}
				if(newClass){
					$('body').removeClass(currentClass);
					$('body').addClass('size_'+newClass);
				}				
			}		
			if($(obj).attr('id')=='print'){
				window.print();				
			}	
			return false;			
		});			
	})	

}

function showDetailOngletMonth(){
	$('#ongletMonth li a').unbind();			
	$('#ongletMonth li a').bind('click',function(){
		var ID = $(this).attr('id');
		$('#ongletMonth li').removeClass('active');
		$(this).parent().addClass('active');
		$('.monthDetail .itemMonth').hide();
		$('.monthDetail #item_'+ID).show();
		return false;			
	});
}

function showDetailApplication(){

	var titleA = $('#itemsApplications #item_1 .nameConstructeur');
	var parentTitleA = titleA.parent();	
	
	//Remplir le select avec les items du premier Onglet #item1
	var html = '<ul>';
	for(j=0;j<titleA.length;j++){
		html +='<li class="'+$(parentTitleA[0]).attr('id')+'"><a href="#'+$(parentTitleA[0]).attr('id')+'">'+$($('a',titleA)[j]).html()+'</a></li>';
	}
	
	html +='</ul>';
	$('.applications #applicationLayer').html(html);
	setEventLayers();
	
	
	
	/***************************************/
			/* ONGLETS */
	/**************************************/
	$('#ongletsApplication li a').each(function(i,obj){	
		$(obj).unbind();	
		$(obj).bind('click',function(){
			var parent = $(this).parent();
			$('#ongletsApplication li').removeClass('active');
			parent.addClass('active');
			$('#itemsApplications > div').hide();
			$('#itemsApplications #item_'+(i+1)).show();
			
			var titleAppli = $('#itemsApplications #item_'+(i+1)+' .nameConstructeur');		
			var parentTitleAppli = titleAppli.parent();
			
			//Remplir le select avec les items d'Onglet Choisi 
			var ctent = '<ul>';
			for(j=0;j<titleAppli.length;j++){
				ctent +='<li class="'+$(parentTitleAppli[j]).attr('id')+'"><a href="#'+$(parentTitleAppli[j]).attr('id')+'">'+$($('a',titleAppli)[j]).html()+'</a></li>';
			}
			ctent +='</ul>';
			$('.applications #applicationLayer').html(ctent);
			setEventLayers();
			return false;
		});			
	});
	
	/**********************/
	
	$('.nameConstructeur a').unbind();			
	$('.nameConstructeur a').bind('click',function(){
		var parent = $(this).parent().parent();
		var listToShow = $(this).parent().next();
		if(parent.attr('class')=='on'){
			parent.removeClass('on');
			listToShow.hide();
		}else{
			parent.addClass('on');
			listToShow.show();
		}
		return false;			
	});
	
}

function goToOnglet(idItem){	
	$('#itemsApplications > div').hide();
	$('#itemsApplications div#item_'+idItem).show();	
	$('#ongletsApplication li').removeClass('active');
	$($('#ongletsApplication li')[idItem-1]).addClass('active');
	
	var titleAppli = $('#itemsApplications #item_'+(idItem)+' .nameConstructeur');		
	var parentTitleAppli = titleAppli.parent();
	
	//Remplir le select avec les items d'Onglet Choisi 
	var ctent = '<ul>';
	for(j=0;j<titleAppli.length;j++){
		ctent +='<li class="'+$(parentTitleAppli[j]).attr('id')+'"><a href="#'+$(parentTitleAppli[j]).attr('id')+'">'+$($('a',titleAppli)[j]).html()+'</a></li>';
	}
	ctent +='</ul>';
	$('.applications #applicationLayer').html(ctent);
	setEventLayers();
}

function setEventLayers(){

	$('div.selectC').unbind('click');
	$('div.selectC').bind('click',function(){
		var etatlayer = $(this).next().css('display').toLowerCase();
		if(etatlayer == "none")
			$(this).next().show();
		else
			$(this).next().hide();
		return false; 
	});
		
	 
	$('.layerCmb ul li a').unbind();			
	$('.layerCmb ul li a').bind('click',function(){			
		var label = $(this).html();
		var select = $(this).parent().parent().parent().prev();
		$('p span',select).html(label);
		select.next().hide();	
		if($(this).parent().parent().parent().attr('id')=='applicationLayer'){
			showItemApplication($(this));
			return true;
		}	
		return false;			
	});	
}

function showItemApplication(obj){
	var id = obj.parent().attr('class');
	$('.itemAppl li#'+id).addClass('on');
	$('.itemAppl li#'+id+' .listModApp').show();	
}

/************/	

function hiderElements(){
	$('.noScript').removeClass('noScript');
}	


/********************************************************/
// Init des popins
/********************************************************/
function initPopins(){
	var dim = getPageSize();
	$('.linkPopin').bind('click',function(){
		var _this = this;
		loadPopin($(_this).attr('rel'))
		$.ajax({
			type: "GET",
			url: $(_this).attr('href'),
			dataType: "html",
			success: function(data){
				try{
					showPopin(data,$(_this).attr('rel'));
				}catch(e){}
			}
		});
		return false;
	});
}
function resizeOverlayForPopin(){
	$(window).bind('resize',function(){
		resizaOverlay();
	});
	
	$(window).bind('scroll',function(){
		resizaOverlay();
	});	
}	

function resizaOverlay(cond){
	var overlay = $('#popinOverlay');
	var scroll = getPageScroll();
	//alert(hi);
	if(cond){
		overlay.css({
			opacity: 0.7,
			display: 'block'
		}).fadeIn('slow',function(){
			var hi = getHeight() + scroll[1];
			overlay.height(hi);
		});
	}else{
		var hi = getHeight() + scroll[1];
		overlay.height(hi);
	}
}

/********************************************************/
// hover sur les onglets Media
/********************************************************/
function setLayersSearchMedia(){
	
	$('#onglets > li').unbind();			
	$('#onglets > li').bind('mouseenter',function(){	
		$(this).removeClass('hover').addClass('hover');
	});				
	
	//	Roll Over sur les onglets Media 
	
	$('#onglets > li').each(function(i,obj){						
		$(obj).bind('mouseover',function(){
			setWidthForLayers();
			$(this).removeClass('hover').addClass('hover');
			$('.resultSearch',this).show(); // Affichage du layer
				
				
				// Au clic sur l'une des éléments d'onglet qui se trouve dans les leyers 
				$('.resultSearch ul li a').unbind();			
				$('.resultSearch ul li a').bind('click',function(){	
					var _this = $(this);
					var label = $(_this).html();
					label = label.split("("); // prendre juste le texte , et enlever le nombre de resultat 

					$('ul#onglets li').removeClass('active');
					$($('ul#onglets > li')[i]).addClass('active');
					
					$('.rubrResultat > div').hide();
					$($('.rubrResultat > div')[i]).show();
					
					var ongletCurrent = $($('.rubrResultat > div')[i]); // on ajoute le resultat choisi dans le div correspond => 'titleOnglet'
					$('b.titleOnglet',ongletCurrent).html(label[0]);
					$('.resultSearch').hide();
					
					
					return false;
				});	
			
		});			
	});	
		
	
	$('#onglets > li').bind('mouseleave',function(){	
		$('.resultSearch',this).hide();	
		$(this).removeClass('hover');				
	});
	
	/*************************/
	$('ul#onglets > li > a').each(function(i,obj){						
		$(obj).bind('click',function(){
			$('ul#onglets li').removeClass('active');
			$(obj).parent().addClass('active');	
			$('.rubrResultat div.mediaItem').hide();
			$($('.rubrResultat div.mediaItem')[i]).show();
			var myClasse = $('body').attr('class');
			$('body').removeClass(myClasse);
			$('body').addClass(myClasse);
			/*$($('.rubrResultat div.mediaItem')[i]).attr('style','line-height:1.1em');*/
			return false;
		});			
	});		
	
}


/********************************************************/
// validateForm
/********************************************************/

function isEmail(field){ 
	var val = field.val();
	if (!val.match (/^[a-z0-9\-\._]+@[a-z0-9\-_\.]+\.[a-z]{2,4}$/gi)){
	 	return false;
	}
	return true;
}

function verifChampsTxt(chmp){
	if(chmp){
		var champ = chmp.val();
		champ = champ.replace(/\s+/g,"");
		var exp = new RegExp("^[a-z\-\']+$","g");
		return exp.test(champ);
	}
}

function validateZIP(chmp){
	if(chmp){
		var champ = chmp.val();
		var exp = new RegExp("^[0-9]+$","g");
		return exp.test(champ);
	}
}


function validateForm(){
	var flag = false;
	$('#popinContact .obligateInput').parent().parent().removeClass('error');
	$('#popinContact .obligateInput').each(function(i,obj){
		if($(this).hasClass('inputMail')){			
			var mail = $($('#popinContact .obligateInput')[i]);		
			if(!isEmail(mail)){	
				flag = true;
				$($('#popinContact .obligateInput')[i]).parent().parent().addClass('error');
				$('#popinContact div.msgError p').html('Attention, certains caract&egrave;res saisis ne sont pas autoris&eacute;s. Merci de v&eacute;rifier l\'ensemble de votre saisie.');
			}
		}		
		
		if($(this).hasClass('inputCar')){			
			var txt = $($('#popinContact .obligateInput')[i]);			
			if(!verifChampsTxt(txt)){
				flag = true;
				$($('#popinContact .obligateInput')[i]).parent().parent().addClass('error');
				$('#popinContact div.msgError p').html('Attention, certains caract&egrave;res saisis ne sont pas autoris&eacute;s. Merci de v&eacute;rifier l\'ensemble de votre saisie.');
			}
		}		
		
		if(!$($('#popinContact .obligateInput')[i]).val()){
			flag = true;
			$($('#popinContact .obligateInput')[i]).parent().parent().addClass('error');
			$('#popinContact div.msgError p').html('Des informations sont n&eacute;cessaires pour traiter votre demande,<br/>elles sont indiqu&eacute;es en rouge. Merci de v&eacute;rifier votre saisie');
		}
	})	
	
	if(flag){
		$('div.msgError').show();
		return false;
	}else{
		sendForm();
	}		
}

function sendForm(){
	alert('function AJAX =+> Contact');
}

function validateFormAbonnement(){
				
	var check = 0;
	var nbCheck = $('#abonnementForm .checkDB').length;
	for(j=0;j<nbCheck;j++){
		if(!$('#abonnementForm .checkDB')[j].checked){
			check+=1;
		}
	}
	
	var flag = false;
	$('#abonnementForm .obligateInput').parent().parent().removeClass('error');
	$('#abonnementForm .obligateInput').each(function(i,obj){
		
		if($(this).hasClass('inputMail')){			
			var mail = $($('#abonnementForm .obligateInput')[i]);		
			if(!isEmail(mail)){	
				flag = true;
				$($('#abonnementForm .obligateInput')[i]).parent().parent().addClass('error');
				$('#popinReceiveInformation div.msgError p').html('Attention, certains caract&egrave;res saisis ne sont pas autoris&eacute;s. Merci de v&eacute;rifier l\'ensemble de votre saisie.');
			}
		}		
				
		if($(this).hasClass('inputCar')){			
			var txt = $($('#abonnementForm .obligateInput')[i]);			
			if(!verifChampsTxt(txt)){
				flag = true;
				$($('#abonnementForm .obligateInput')[i]).parent().parent().addClass('error');
				$('#popinReceiveInformation div.msgError p').html('Attention, certains caract&egrave;res saisis ne sont pas autoris&eacute;s. Merci de v&eacute;rifier l\'ensemble de votre saisie.');
			}
		}	
		
		
		if(!$($('#abonnementForm .obligateInput')[i]).val() || nbCheck==check){			
			flag = true;
			$($('#abonnementForm .obligateInput')[i]).parent().parent().addClass('error');
			$('#popinReceiveInformation div.msgError p').html('Des informations sont n&eacute;cessaires pour traiter votre demande,<br/>elles sont indiqu&eacute;es en rouge. Merci de v&eacute;rifier votre saisie');
		}
	})	
	
	if(flag){
		$('#popinReceiveInformation div.msgError').show();
		return false;
	}else{
		sendFormAbonnement();
	}		
}

function sendFormAbonnement(){
	alert('function AJAX ==> Aboonement');
}

function validateDesabonnement(){
	var flag = false;
			
	var check = 0;
	var nbCheck = $('#desabonnementForm .checkDB').length;
	for(j=0;j<nbCheck;j++){
		if(!$('#desabonnementForm .checkDB')[j].checked){
			check+=1;
		}
	}
	
	$('#desabonnementForm .obligateInput').parent().parent().removeClass('error');
	$('#desabonnementForm .obligateInput').each(function(i,obj){
		if($(this).hasClass('inputMail')){			
			var mail = $($('#desabonnementForm .obligateInput')[i]);		
			if(!isEmail(mail)){	
				flag = true;
				$($('#desabonnementForm .obligateInput')[i]).parent().parent().addClass('error');
				$('#popinReceiveInformation div.msgError p').html('Attention, certains caract&egrave;res saisis ne sont pas autoris&eacute;s. Merci de v&eacute;rifier l\'ensemble de votre saisie.');
			}
		}		
						

		
		if(!$($('#desabonnementForm .obligateInput')[i]).val() || check==nbCheck){
			flag = true;
			$($('#desabonnementForm .obligateInput')[i]).parent().parent().addClass('error');
			$('#popinReceiveInformation div.msgError p').html('Des informations sont n&eacute;cessaires pour traiter votre demande,<br/>elles sont indiqu&eacute;es en rouge. Merci de v&eacute;rifier votre saisie');
		}
	})	
	
	if(flag){
		$('#popinReceiveInformation div.msgError').show();
		return false;
	}else{
		sendFormDesabonnement();
	}		
}

function sendFormDesabonnement(){	
	alert('function AJAX ==> desaboonement');
}

function validateFormAbonnementmag(){
	var flag = false;
	$('#abonnementMagForm .obligateInput').parent().parent().removeClass('error');
	$('#abonnementMagForm .obligateInput').each(function(i,obj){
		if($(this).hasClass('inputMail')){			
			var mail = $($('#abonnementMagForm .obligateInput')[i]);		
			if(!isEmail(mail)){	
				flag = true;
				$($('#abonnementMagForm .obligateInput')[i]).parent().parent().addClass('error');
				$('#popinAbonnement div.msgError p').html('Attention, certains caract&egrave;res saisis ne sont pas autoris&eacute;s. Merci de v&eacute;rifier l\'ensemble de votre saisie.');
			}
		}
		
		if($(this).hasClass('inputNum')){		
			var field = $($('#abonnementMagForm .obligateInput')[i]);		
			if(!validateZIP(field)){	
				flag = true;
				$($('#abonnementMagForm .obligateInput')[i]).parent().parent().addClass('error');
				$('#popinAbonnement div.msgError p').html('Des informations sont n&eacute;cessaires pour traiter votre demande,<br/>elles sont indiqu&eacute;es en rouge. Merci de v&eacute;rifier votre saisie');
			}
		}	
		
		if($(this).hasClass('inputCar')){			
			var txt = $($('#abonnementMagForm .obligateInput')[i]);			
			if(!verifChampsTxt(txt)){
				flag = true;
				$($('#abonnementForm .obligateInput')[i]).parent().parent().addClass('error');
				$('#popinAbonnement div.msgError p').html('Attention, certains caract&egrave;res saisis ne sont pas autoris&eacute;s. Merci de v&eacute;rifier l\'ensemble de votre saisie.');
			}
		}
		
		if(!$($('#abonnementMagForm .obligateInput')[i]).val()){
			flag = true;
			$($('#abonnementMagForm .obligateInput')[i]).parent().parent().addClass('error');
			$('#popinAbonnement div.msgError p').html('Des informations sont n&eacute;cessaires pour traiter votre demande,<br/>elles sont indiqu&eacute;es en rouge. Merci de v&eacute;rifier votre saisie');
		}
	})	
	
	if(flag){
		$('#popinAbonnement div.msgError').show();
		return false;
	}else{
		sendFormAbonnementMag();
	}		
}

function sendFormAbonnementMag(){	
	alert('function AJAX ==> Abonnement SAFRAN MAG');
}

function searchMedia(){
	var motCle = $('#f_media').val();
	var classToshow = $('#mediaSearch span').attr('class');
	$('.rubrResultat > div').hide();
	var itemMedia = "media_1";
	if (!motCle){
		if(classToshow=='media_0' || classToshow=='media_1'){
			motCle = 'Toutes les photos';
		}else if(classToshow=='media_2'){
			motCle = 'Toutes les Vid&eacute;os';
		}else if(classToshow=='media_3'){
			motCle = 'Tous les Articles';
		}else if(classToshow=='media_4'){
			motCle = 'Toutes les Pubs';
		}else if(classToshow=='media_5'){
			motCle = 'Tous les dossiers';
		}
		
	}
	if(classToshow!='media_0')
		itemMedia = classToshow;
	
	
		$('.rubrResultat .'+itemMedia).show();
		$('.rubrResultat .'+itemMedia+' b.titleOnglet').html(motCle);
		
		$('#onglets li.active').removeClass('active');
		$('#onglets > li.'+itemMedia).addClass('active');	
}

function validateAuth(){
	var flag = false;
	var mail = $('input#field_email');
	var pass = $('input#field_pass');	
	$('#account p.errorMsg').hide();
	$('#account p.error').removeClass('error');
	
	if(!isEmail(mail) || mail==""){
		$('#account p.errorMsg').show();
		/*$('#account p.errorMsg').html('Des informations sont n&eacute;cessaires pour traiter votre demande,<br/>elles sont indiqu&eacute;es en rouge. Merci de v&eacute;rifier votre saisie.');*/			
		mail.parents('p').addClass('error');
		flag = true;
	}
	
	if(pass.val().length<4){
		$('#account p.errorMsg').show();
		/*$('#account p.errorMsg').html('Des informations sont n&eacute;cessaires pour traiter votre demande,<br/>elles sont indiqu&eacute;es en rouge. Merci de v&eacute;rifier votre saisie.');	*/		
		pass.parents('p').addClass('error');
		flag = true;
	}
	
	if(flag)
		return false;
	
}

/*************************************************/
// Caroussel 
/*************************************************/
var idStart = 0 ; 
var idEnd = 0 ;
var tabSelections = [];	

function initCaroussel(){
	idEnd = 0;
	idStart = 0 	
	$('a.prevSelection').hide();
	if(tabSelections.length<6)
		$('a.nextSelection').hide();


	var nbrLi = 6;
	var listToAdd = '';
	for(i=0;i<nbrLi;i++){
		if(tabSelections[i]){
			listToAdd += '<li>';
			listToAdd += '<a href="#"><img src="'+tabSelections[i].path_small+'" alt="Copyright" /></a>';
			listToAdd += '<p>'+tabSelections[i].subTitle+'</p>';
			listToAdd += '</li>';
		}
	}
	
	$('ul#caroussel').html(listToAdd);
	setEventNaviguation();
	setEventListSelections();
	
}

function setEventNaviguation(){
	idEnd = idStart + 5;
	//nextSelection
	$('.listSelections a.nextSelection').unbind();
	$('.listSelections a.nextSelection').bind('click', function(){
	
		var html = "";
		if(tabSelections[idEnd+1]){
			idEnd+=6;
			idStart+=6;
			for(i=0;i<6;i++){
				if(tabSelections[idStart+i]){
					html += '<li>';
					html += '<a href="#"><img src="'+tabSelections[idStart+i].path_small+'" alt="Copyright" /></a>';
					html += '<p>'+tabSelections[idStart+i].subTitle+'</p>';
					html += '</li>';
				}else{
					idEnd = idStart+i ; 
					break;
				}
			}
			$('ul#caroussel').html(html);
			showNaviguation();
			setEventListSelections();
		}		
		return false;		
	});
	
	//previousSelection
	$('.listSelections a.prevSelection').unbind();
	$('.listSelections a.prevSelection').bind('click', function(){
		if(tabSelections[idStart-1]){
			var html = "";
			idEnd-=6;
			idStart-=6;			
			for(i=0;i<6;i++){		
				html += '<li>';
				html += '<a href="#"><img src="'+tabSelections[idStart+i].path_small+'" alt="Copyright" /></a>';
				html += '<p>'+tabSelections[idStart+i].subTitle+'</p>';
				html += '</li>';
			}
			$('ul#caroussel').html(html);
			showNaviguation();
			setEventListSelections();
		}
		return false;		
	});	

	

	
}

function showNaviguation(){
	
	if(idEnd < tabSelections.length) $('a.nextSelection').show();
	if(idEnd == tabSelections.length) $('a.nextSelection').hide();
	
	if(idStart == 0) $('a.prevSelection').hide();
	if(idStart > 0) $('a.prevSelection').show();
}

function setEventListSelections(){	
	$('#caroussel li a').unbind();
	$('#caroussel li a').bind('click', function(){
		$('.on').removeClass('on');
		$(this).parent().addClass('on');
		return false;		
	});
}
/*************************************************/
// Fonctions générales
/*************************************************/

// Renvoie les dimensions de la page
function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
}

