if ( typeof miseEnPlaceMediasListe != 'function' ) {
	
	function bougePointRouge(cible)
	{
		if ( cible.data('posPointRouge') < 0 ){
			cible.data('posPointRouge',0);
		}
		if ( cible.data('posPointRouge') > 4 ){
			cible.data('posPointRouge',4);
		}
		
		cible.find('.photo_nave div[id^=photo_nav]').removeClass('photo_pt_rouge').addClass('photo_pt_gris');
		cible.find('.photo_nave div:eq('+(cible.data('posPointRouge')+1)+')').addClass('photo_pt_rouge');
	}
	
	function chargeImage(cible)
	{
		var imageCourante = cible.data('imageCourante');
		var lstImages     = cible.data('lstImages');
		
		if ( imageCourante < 0){return;}
		if ( imageCourante > lstImages.length ){return;}
		if ( cible.data('gallerieType') == 'PHOTO' ) {
			cible.find('.bloc-media-photo img').attr('src',lstImages[imageCourante].GRANDE_IMAGE);
			cible.find('#tof_legende').html(lstImages[imageCourante].LEGENDE.substr(0,50)+'...');
			cible.find('.bloc-media-photo').unbind('click').click(function(){
				document.location.href = cible.data('gallerieLien')+'?NUM='+imageCourante;
			}).css('cursor','pointer');
		}
		else {
			/* ancienne version 
			
			$.extend(cible.data('flashvars'),{sig:lstImages[imageCourante].IDKEWEGO});
			var lavideo = new SWFObject("http://www.kewego.com/swf/p3/epix.swf", lstImages[imageCourante].IDKEWEGO, "300", "222", "8", "#000");
			lavideo.addParam("movie", "http://www.kewego.com/swf/p3/epix.swf");
			lavideo.addParam("wmode", "transparent");
			lavideo.addParam("allowFullScreen", "true");
			lavideo.addParam("allowscriptaccess", "always");
			lavideo.addParam("swliveconnect", "true");
			lavideo.addParam('flashvars',$.param(cible.data('flashvars')));
			lavideo.write("bloc-media-photo");			
			*/
			
			
			var sig_kewego = lstImages[imageCourante].IDKEWEGO;
			 var tag_video = document.createElement("video"); 
			/* html 5 ?  
			if ( !tag_video.play ) 
			{
				// le navigateur ne supporte pas <video>
					//on utilise flash - swfobject
					
			*/
			/* spécifique iphone / ipad */
			if (navigator.userAgent.indexOf("iPod")==-1 && navigator.userAgent.indexOf("iPad") == -1)
			{
			

			$.extend(cible.data('flashvars'),{sig:sig_kewego});
			var lavideo = new SWFObject("http://video.lequipe.fr/images/swf/kplayer5.swf?v=201100550", sig_kewego, "300", "225", "8", "#000");
			 			
			
			lavideo.addParam("movie", "http://video.lequipe.fr/images/swf/kplayer5.swf?v=201100550");
			lavideo.addParam("wmode", "transparent");
			lavideo.addParam("allowFullScreen", "true");
			lavideo.addParam("allowscriptaccess", "always");
			lavideo.addParam('flashvars',$.param(cible.data('flashvars')));
			lavideo.write("bloc-media-photo");
			}
			else
			{
				//html5
				tag_video.id =  "kewego_HTML5_"+sig_kewego;
				tag_video.poster="http://api.kewego.com/video/getHTML5Thumbnail/?playerKey=306eedd58f91&sig="+sig_kewego;
				tag_video.width="300";
				tag_video.height="225";
				tag_video.controls = true;
				tag_video.preload="none";
				var tag_source = document.createElement("source");
				tag_source.src='http://api.kewego.com/video/getHTML5Stream/?playerKey=306eedd58f91&sig='+sig_kewego;
				tag_source.type='video/mp4';
				tag_source.width="300";
				tag_source.height="225";
				
				 tag_video.appendChild(tag_source);
				$(".bloc-media-photo").html("").append(tag_video);
	
			}
			
			cible.find('.bloc-media-photo').unbind('click');
		}
		cible.find('.photo_refresh div').removeClass('cred');
		cible.find('.photo_refresh div:eq('+imageCourante+')').addClass('cred');
	}
	
	function chargeVignette(cible,start)
	{
		$.each(lstImages,function(i,s){
			if (i%4 == 0 && i > start && i!=0) {
				return false;
			}
			if ( i >= start ){
				cible.find('.photo_refresh').append('<div><img id="photosNb'+i+'" width="70" src="'+cible.data('lstImages')[i].VIGNETTE+'" alt="'+cible.data('lstImages')[i].LEGENDE+'" title="'+cible.data('lstImages')[i].LEGENDE+'" /></div>');
			}
		});
	}
	
	
	function miseEnPlaceMediasListe(cible,datas,type,lien)
	{
		if ( $(cible).length == 0 ){
			return;
		}
		
		if ( type == 'VIDEO') {
			cible.data('flashvars',{autostart:'false',language_code: "fr",playerKey: "306eedd58f91",skinKey: "3100de66c689",skin_url:"http://video.lequipe.fr/images/swf/default2.swf?v=20100616"} );
		}
		cible.data('lstImages',datas);
		cible.data('gallerieType',type);
		cible.data('gallerieLien',lien);
		cible.data('posPointRouge',0);
		cible.data('imageCourante',0);
		
		cible.find('.photo_refresh > div').css('width','72px');
		cible.find('.photo_refresh').css('width',(cible.data('lstImages').length*73)+'px');
		
		if ( type == 'PHOTO') {
			cible.find('.bloc-media-photo').unbind('click').click(function(){
				document.location.href = cible.data('gallerieLien')+'?NUM='+cible.data('imageCourante');
			}).css('cursor','pointer');
		}
		
		cible.find('.photo_pt_gris').unbind('click').click(function(){
			cible.data('posPointRouge', parseInt( $(this).attr('id').replace(/photo_nav_/,'') ) );
			while( cible.find('.photo_refresh div').length <= cible.data('posPointRouge')*4 ) {
				chargeVignette(cible,cible.find('.photo_refresh div').length);
			}
			cible.find('.photo_refresh').animate({'marginLeft':'-'+cible.data('posPointRouge')*parseInt(cible.find('.bloc_4_photos').css('width'))+'px'});
			bougePointRouge(cible);
		});
		
		cible.find('.photo_retour').unbind('click').click(function(){
			if ( parseInt(cible.find('.photo_refresh').css('margin-left'))+parseInt(cible.find('.bloc_4_photos').css('width')) > 0 ){
				cible.find('.photo_refresh').css('margin-left',0);
				cible.data('posPointRouge',cible.data('posPointRouge')-1);
			}
			else {
				cible.find('.photo_refresh').animate({'marginLeft':'+='+cible.find('.bloc_4_photos').css('width')});
				cible.data('posPointRouge',cible.data('posPointRouge')-1);
			}
			bougePointRouge(cible);
		});

		cible.find('.photo_suite').unbind('click').click(function(){
			if ( Math.ceil(lstImages.length/4) <= cible.data('posPointRouge')+1 ) {return;}
			chargeVignette(cible,cible.find('.photo_refresh div').length);
			if ( Math.abs(parseInt($('#photo_refresh').css('margin-left')))+parseInt($('#bloc_4_photos').css('width')) > parseInt($('#photo_refresh').css('width'))-parseInt($('#bloc_4_photos').css('width')) ){
				cible.find('.photo_refresh').css('margin-left','-'+parseInt(cible.find('.photo_refresh').css('margin-left'))-parseInt(cible.find('.bloc_4_photos').css('width')));
				cible.data('posPointRouge',cible.data('posPointRouge')+1);
			}
			else {
				cible.find('.photo_refresh').animate({'marginLeft':'-='+cible.find('.bloc_4_photos').css('width')});
				cible.data('posPointRouge',cible.data('posPointRouge')+1);
			}
			
			bougePointRouge(cible);
		});
		
		bougePointRouge(cible);
		
		cible.find('.photo_refresh img').live('click',function(e){
			cible.data('imageCourante', parseInt( e.target.id.replace(/photosNb/,'')) );
			chargeImage(cible);
			
		}).css('cursor','pointer');
	}
}
