var displayWaitMessage=true;

function showPreview(imagePath){
		var subImages = document.getElementById('cnt_big_ref').getElementsByTagName('IMG');
		if(subImages.length==0){
			var img = document.createElement('IMG');
			document.getElementById('cnt_big_ref').appendChild(img);
		}else img = subImages[1];
		
		if(displayWaitMessage){
			$("#loading_img").fadeIn();
		}
		
		img.onload = function() { 
		hideWaitMessageAndShowCaption(); 
			$("#cnt_big_ref").hide();
			$("#cnt_big_ref").fadeIn();
		};
		img.src = imagePath;
		
		
	}

function hideWaitMessageAndShowCaption()
	{
		$("#loading_img").hide();
		
}



function fullscreen(){
window.moveTo(0,0);
if (document.all){
	window.resizeTo(screen.availWidth, screen.availHeight);
}else if (document.layers){
	if (window.outerHeight < screen.availHeight || window.outerWidth < screen.availWidth){
		window.outerHeight = screen.availHeight;
		window.outerWidth = screen.availWidth;
	}
}
}
var ttm=null;
var time_wait=10000;
function next_function(){
	if(played_ref==src_ref.length){
			played_ref=1;
		}else{
			played_ref=played_ref+1;
		}
		$("#titre_client").html(titre_ref[played_ref-1]);
		$("#titre_client").hide();
		$("#titre_client").fadeIn();
		showPreview("images_1/"+src_ref[played_ref-1]);
		$("#agrandir").attr("href", "images_1/"+src_big_ref[played_ref-1]);
		$("#agrandir").attr("title", titre_ref[played_ref-1]);
		$("#control_site").attr("href", site_ref[played_ref-1]);
		//$("#img_ref").attr=("src","images_1/"+element_ref[played_ref-1]);	
		ttm=setTimeout("next_function()",time_wait);
}


function previous_function(){
		if(played_ref==1){
			played_ref=src_ref.length;
		}else{
			played_ref=played_ref-1;
		}
		$("#titre_client").html(titre_ref[played_ref-1]);
		$("#titre_client").hide();
		$("#titre_client").fadeIn();
		showPreview("images_1/"+src_ref[played_ref-1]);
		$("#agrandir").attr("href", "images_1/"+src_big_ref[played_ref-1]);
		$("#agrandir").attr("title", titre_ref[played_ref-1]);
		$("#control_site").attr("href", site_ref[played_ref-1]);
		//$("#img_ref").attr=("src","images_1/"+element_ref[played_ref-1]);	
}
$(document).ready(function(){
	
	ttm=setTimeout("next_function()",time_wait);
	var ref_visible="ref1";
	$("#metier_btn").click(function(){
		
		$("#metier_menu").slideDown();
		$("#ref_menu").slideUp();
	});
	
	$("#ref_btn").click(function(){
		$("#metier_menu").slideUp();
		$("#ref_menu").slideDown();
	});
	
	$("#next_l").click(function(){
		clearTimeout(ttm);
		next_function();
		
	});
	$("#previous_l").click(function(){
		previous_function();
	});
		    
	$(".lightbox").lightbox({
		fitToScreen: true,
		imageClickClose: false
	});
			
});
