

jQuery(document).ready(function(){
 ////////TEASER UNIVERS//////////

if($('#teaser_univers').length != 0 && univers.length > 0){



//load default text for each univers
$('.univers_box').each( function(i) {
                  var rand =Math.floor(Math.random()*univers[i]["title"].length);
	$('#univers'+i).find('span.spy').html(rand);
	$(this).find('.univers_nav').find('h3').html(univers[i]["header"]);
	$('#content_univers'+i).find('h4').html('<a href="'+univers[i]["url"][rand]+'">'+univers[i]["title"][rand]+'</a>');
	$('#content_univers'+i).find('span').html('<a href="'+univers[i]["url"][rand]+'"><img src="'+univers[i]["img"][rand]+'" alt="'+univers[i]["title"][rand]+'" /></a>');
	$('#content_univers'+i).find('p').html('<a href="'+univers[i]["url"][rand]+'">'+univers[i]["txt"][rand]+'</a>');
  //counter for the number of link
	var count=0;
	$('#uni'+i+'_link'+0).parent().find('a').each( function() {
		//unfill each button
		if($('#uni'+i+'_link'+0).find('img').attr('src')=='/i18n/2955504,property=data,v=2.png') { 
                                            $('#uni'+i+'_link'+0).find('img').attr('src', '/i18n/2955506,property=data,v=2.png'); 
                                    }
		count++;
	});
	
//set the showed numbers
	var display_pos=rand+1;
	$('#uni'+i+'_link'+0).parent().find('span').html(''+display_pos+'/'+count+'');
	
//fill the selected button
	var id=$('#uni'+i+'_link'+rand).attr("id");
	$('#'+id).find('img').attr('src', '/i18n/2955504,property=data,v=2.png');	
});



$('.nav a').click( function() {
//register the index of the clicked link
	var id=$(this).attr("id");
	var len=id.length;
	var pos=id.substr(len-1,1);

//register the index of the univers clicked
	var name_uni=$(this).parents('div.univers_box').attr('id');
	var len_uni= name_uni.length;
	var uni=name_uni.substr(len_uni-1, 1);

//position before click
var current_pos=$('#univers'+uni).find('span.spy').html();

	//counter for the number of link
	var count=0;
	$(this).parent().find('a').each( function() {
		//unfill each button
		if($(this).find('img').attr('src')=='/i18n/2955504,property=data,v=2.png') { $(this).find('img').attr('src', '/i18n/2955506,property=data,v=2.png'); }
		count++;
	});
	
	var display_pos=parseInt(pos)+1;
	$(this).parent().find('span').html(''+display_pos+'/'+count+'');
	//fill the selected button
	$('#'+id).find('img').attr('src', '/i18n/2955504,property=data,v=2.png');
	//transition for the new content
	if(current_pos<pos) { var dir1="left"; var dir2="right"; }
	else { var dir1="right"; var dir2="left"; }
	
	$('#content_univers'+uni).hide("slide", { direction: dir1 }, 500, function () { 
	
	$('#univers'+uni).find('span.spy').html(""+pos+"");
	$('#content_univers'+uni).find('h4').html('<a href="'+univers[uni]["url"][pos]+'">'+univers[uni]["title"][pos]+'</a>');
	$('#content_univers'+uni).find('span').html('<a href="'+univers[uni]["url"][pos]+'"><img src="'+univers[uni]["img"][pos]+'" alt="'+univers[uni]["title"][pos]+'" /></a>');
	$('#content_univers'+uni).find('p').html('<a href="'+univers[uni]["url"][pos]+'">'+univers[uni]["txt"][pos]+'</a>');
	$('#content_univers'+uni).show("slide", { direction: dir2 }, 500);
                 });
	
           });

}

//////////////TEASER EVENT/////////////
 //load default text for event

if($('#t_event').length != 0){
	$('#content_event').find('#img').html('<a href="'+tvArteEvenement["url"][0]+'"><img src="'+tvArteEvenement["img"][0]+'" /></a>');
	$('#content_event').find('span.spy').html('0');
	$('#content_event').find('#diffus').html(tvArteEvenement["diffus"][0]);
	$('#content_event').find('h3').html('<a href="'+tvArteEvenement["url"][0]+'">'+tvArteEvenement["title"][0]+'</a>');
	$('#content_event').find('h4').html('<a href="'+tvArteEvenement["url"][0]+'">'+tvArteEvenement["subtitle"][0]+'</a>');
	$('#content_event').find('#text').html('<a href="'+tvArteEvenement["url"][0]+'">'+tvArteEvenement["txt"][0]+'</a>');
	
	$("#navevent a").click( function() {
	//register the index of the clicked link
	var id=$(this).attr("id");
	var len=id.length;
	var pos=id.substr(len-1,1);
	
	//position before click
	var current_pos=$('#content_event').find('span.spy').html();
	//counter for the number of link
	var count=0;
	$(this).parent().find('a').each( function() {
		//unfill each button
		if($(this).find('img').attr('src')=='/i18n/2955504,property=data,v=2.png') { $(this).find('img').attr('src', '/i18n/2955506,property=data,v=2.png'); }
		count++;
	});
	var display_pos=parseInt(pos)+1;
	$(this).parent().find('span').html(''+display_pos+'/'+count+'');
	//fill the selected button
	$('#'+id).find('img').attr('src', '/i18n/2955504,property=data,v=2.png');
	//transition for the new content
	if(current_pos<pos) { var dir1="left"; var dir2="right"; }
	else { var dir1="right"; var dir2="left"; }
	$('#content_event').hide("slide", { direction: dir1 }, 500, function () {
		$('#content_event').find('#img').html('<a href="'+tvArteEvenement["url"][pos]+'"><img src="'+tvArteEvenement["img"][pos]+'" /></a>');
		$('#content_event').find('span.spy').html(""+pos+"");
		$('#content_event').find('#diffus').html(tvArteEvenement["diffus"][pos]);
		$('#content_event').find('h3').html('<a href="'+tvArteEvenement["url"][pos]+'">'+tvArteEvenement["title"][pos]+'</a>');
		$('#content_event').find('h4').html('<a href="'+tvArteEvenement["url"][pos]+'">'+tvArteEvenement["subtitle"][pos]+'</a>');
		$('#content_event').find('#text').html('<a href="'+tvArteEvenement["url"][pos]+'">'+tvArteEvenement["txt"][pos]+'</a>');
	$('#content_event').show("slide", { direction: dir2 }, 500);
	});
	});

}



//rollover management (should be used everywhere on the website...)


$("img.teaserLesUnivers_rollover").hover(

function(){

if($(this).attr("src").indexOf("_on") == -1) {
 var newSrc = "/i18n/3743544,property=data,v=1.gif";
 $(this).attr("src",newSrc);
 }

},

function(){

if($(this).attr("src").indexOf("_on") != -1) {
 var oldSrc = "/i18n/3743546,property=data,v=1.gif";
 $(this).attr("src",oldSrc);
 }
}

);








});
