//========================================================
var gZoneHeight = 0;
var gScrollMaxHeight = 0;
var gScrollPos = 0;
var gScrollOffset = 18;
var gScrollTimer = null;
var gScrollSens = false;
var gPathVisualizer = gDirAppl+'includes/mediaplayer.swf';
//===========================
(function(jQuery) {

	jQuery.extend(jQuery.fn, {
		PaneScroll : function(opts) {
			var config = jQuery.extend({}, jQuery.fn.PaneScroll.defaults, opts || {});
			this.bind('mousedown', config, handleMouseDown);
			if (jQuery.fn.mousewheel) {
				this.mousewheel(function(e, delta) {
					this.scrollTop -= delta * config.mousewheelSpeed;
					e.preventDefault();
				});
			}
			if (!config.accesible) {
				this.css({ overflow: 'hidden' });
			}
			return this;
		}
	
	});
  
	function handleMouseDown(e) {
		jQuery(document).data('PaneScroll', {
			element: this,
			scroll: this.scrollTop,
			y : e.clientY,
			config : e.data
		}).bind('mousemove.PaneScroll', handleMouseMove).bind('mouseup.PaneScroll', handleMouseUp);
		e.preventDefault();
	}
  
	function handleMouseMove(e) {
		var data = jQuery(this).data('PaneScroll');
		data.element.scrollTop = data.scroll + (data.y - e.clientY) * data.config.speed;
	}
  
	function handleMouseUp(e) {
		jQuery(this).removeData('PaneScroll').unbind('.PaneScroll');    
	}
  
	jQuery.fn.PaneScroll.defaults = {
		accesible: true,
		speed: 1.5,
		mousewheelSpeed : 25 
	};
  

})(jQuery);
//===========================
jQuery(document).ready(function(){
	 
	 f_LFL_Startup();
	 
	 gZoneHeight = jQuery.iUtil.getSize(jQuery('.FL_Records').get(0)).hb;
	 gScrollMaxHeight = jQuery.iUtil.getSize(jQuery('.FL_RecordsContent').get(0)).hb;
	 gScrollMaxHeight = gScrollMaxHeight-(13*gScrollOffset);
	 //
	 jQuery('.FL_Records').PaneScroll({accesible: false});
	 //
});
//===========================
function f_LFL_Startup() {
	var l_ImgSrc = "";
	  jQuery('.LFL_IMG_Banner').each(function(i){
		l_ImgSrc = this.src+"&width=149&height=37";
		this.src = l_ImgSrc;
	 });
	  // Ajouter target aux liens externes
	  jQuery('a.LFL_ExternLink').attr("target", "_blank");


	  jQuery('#LFL_Consultants').attr('value','-1');
}
//===========================
function f_LFL_LaunchSearch (pIndex){
	jQuery('#LFL_Set').attr('value',pIndex);
	jQuery('#FL_Criteres').submit();
}
//===========================
function f_LFL_LaunchConsultants (pIndex){
	jQuery('#LFL_Consultants').attr('value',pIndex);
	jQuery('#FL_Criteres').submit();
}
//===========================
var gLFL_Diaporama = new Array();
var gLFL_PosDiaporama = 0;
//===========================
function f_DisplayNav(){
	
	 if(jQuery.browser.msie){
		jQuery("#DIA_ZonePrev").show();
		jQuery("#DIA_ZoneNext").show();
		jQuery("#DIA_ZonePrev > .DIA_Prev").show();
		jQuery("#DIA_ZoneNext > .DIA_Next").show();
	  }else{
		jQuery("#DIA_ZonePrev").hover(function(){
				jQuery("> .DIA_Prev", this).fadeIn();
			}, function() {
				jQuery("> .DIA_Prev", this).fadeOut();
		});
		
		jQuery("#DIA_ZoneNext").hover(function(){
				jQuery("> .DIA_Next", this).fadeIn();
			}, function() {
				jQuery("> .DIA_Next", this).fadeOut();
		});
	  }
	
	var l_NbrDiapos = gLFL_Diaporama.length;
	if(l_NbrDiapos > 0){
		f_SetDiapo(gLFL_Diaporama[gLFL_PosDiaporama]);
	}
	
}
//===========================
function f_ShowMedias(pChemin, pArrFichiers){
	var l_Status = jQuery('#LFL_Diaporama').css('display');
	//
	if(l_Status == 'none'){
		
		if(pChemin != ""){
			var l_arrTemp = pChemin.split('/');
			var l_NbrItems = l_arrTemp.length;
			var l_IsPath = l_arrTemp[l_NbrItems-3];
			//alert(pArrFichiers);
			// var gLFL_Diaporama 
			jQuery('#LFL_Diaporama').fadeIn(1000, f_DisplayNav);
		}
		if(pArrFichiers){
			gLFL_Diaporama = pArrFichiers;
			gLFL_PosDiaporama = 0;
			//var l_NbrDiapos = gLFL_Diaporama.length;
//			if(l_NbrDiapos > 0){
//				f_SetDiapo(gLFL_Diaporama[gLFL_PosDiaporama]);
//			}
		}
		
	}else{
		jQuery('#LFL_Diaporama').fadeOut(1000);
	}
	
}
//===========================
function f_SetDiapo(pChemin){
	//
	var l_Extension = f_GetExtFichier(pChemin);
	if(l_Extension != ""){
		if(f_ExtIsValid(l_Extension) == "P"){
			jQuery('.DIA_Medias').html('<img src="../functions/img-resize.php?file='+pChemin+'&width=446&height=294" alt="" />');
		}else if(f_ExtIsValid(l_Extension) == "V"){
			var l_ObjPreview = {src:pChemin, type:l_Extension,w:446,h:294};
			jQuery('.DIA_Medias').html(f_GetTagVideo(l_ObjPreview));
		}// Fin extension valide
	}// Fin extension existe
}
//===========================
function f_GetTagVideo(pFichier){
	var l_TagVideo = "";
	// l_TagVideo = '<a class="oma-media {width:150, height:100}" href="'+pFichier+'">&nbsp;</a>';
	if(pFichier.type == "swf"){
		//l_TagVideo = '<a class="oma-media {width:'+pFichier.w+', height:'+pFichier.h+'}" href="'+pFichier.src+'">&nbsp;</a>';
		l_TagVideo ='<embed id="movie_player_swf" name="movie_player_swf" height="'+pFichier.h+'" width="'+pFichier.w+'" autoplay="false" wmode="transparent" quality="high" bgcolor="#ffffff" src="'+pFichier.src+'" type="application/x-shockwave-flash"/>';
	}
	if(pFichier.type == "flv"){
		//free-lancers/mediaplayer.swf?file=video-files/curtain.flv
		//l_TagVideo = '<a class="oma-media {width:'+pFichier.w+', height:'+pFichier.h+'}" href="mediaplayer.swf?file='+pFichier.src+'">&nbsp;</a>';
		l_TagVideo ='<embed id="movie_player_flv" name="movie_player_flv" height="'+pFichier.h+'" width="'+pFichier.w+'" flashvars="file='+gPathVisualizer+'?file='+pFichier.src+'" autoplay="true" wmode="transparent" quality="high" bgcolor="#ffffff" src="'+gPathVisualizer+'?file='+pFichier.src+'" type="application/x-shockwave-flash"/>';
	}
	if(pFichier.type == "wmv"){
		//l_TagVideo = '<a class="oma-media {width:'+pFichier.w+', height:'+pFichier.h+'}" href="'+pFichier.src+'">&nbsp;</a>';
		l_TagVideo ='<embed id="movie_player_wmv" name="movie_player_wmv" height="'+pFichier.h+'" width="'+pFichier.w+'" autostart="0" wmode="transparent" bgcolor="#ffffff" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" type="application/x-mplayer2" src="'+pFichier.src+'"/>';
	}
	if(pFichier.type == "mov"){
		//l_TagVideo = '<a class="oma-media {width:'+pFichier.w+', height:'+pFichier.h+'}" href="'+pFichier.src+'">&nbsp;</a>';
		l_TagVideo ='<embed id="movie_player_qt" name="movie_player_qt" height="'+pFichier.h+'" width="'+pFichier.w+'" autoplay="true" wmode="transparent" bgcolor="#ffffff" pluginspage="http://www.apple.com/quicktime/download/" src="'+pFichier.src+'"/>';
	}
	return l_TagVideo;
}
//===========================
function f_NavMedias(pSens){
	var l_NbrDiapos = gLFL_Diaporama.length;
	//
	if(pSens){
		//
		if(l_NbrDiapos > 0){
			gLFL_PosDiaporama--;
			if (gLFL_PosDiaporama < 0){
				gLFL_PosDiaporama = (l_NbrDiapos-1);
			}
			f_SetDiapo(gLFL_Diaporama[gLFL_PosDiaporama]);
		}
	}else{
		// 
		if(l_NbrDiapos > 0){
			gLFL_PosDiaporama++;
			
			if (gLFL_PosDiaporama > (l_NbrDiapos-1)){
				gLFL_PosDiaporama = 0;
			}
			f_SetDiapo(gLFL_Diaporama[gLFL_PosDiaporama]);
		}
	}
}
//===========================