$(document).ready(function() {
	if ($("#animation_accueil")) {

		var flashvars = {};
		var params = {'wmode':'transparent'};
		var attributes = {};
		
		swfobject.embedSWF("flash/accueil.swf", "animation_accueil", "1024", "432", "9.0.0" ,"expressInstall.swf", flashvars, params, attributes);
	}
		
	// #### pictures lazyload fadein effects
	$("img").each(function() {
		if ($(this).attr("class").indexOf("none")<0)
			$(this).lazyload({ 
				effect      : "fadeIn" 	
			});
	});
		
});

/* ----- Racourci ----- */
function get(e){
	return document.getElementById(e);
}

/* ----- Popup image Zone admin ----- */
function popupCentre(source,largeur,hauteur){
  var x=(screen.width-largeur)/2;
  var y=(screen.height-hauteur)/2;
  window.open(source,'','top='+y+',left='+x+',width='+largeur+',height='+hauteur+',location=no,status=no,scrollbars=no');
}

/* ----- Deplacement d'une div dans une autre horizontalement ----- */
function move(direction,num,max,divid,leftarrowid,rightarrowid,decalage){
	var left = get(divid).style.left;
	var longueur = left.length - 2; 
	if (direction == 'droite'){
		if (num < (max-1)){
			get(divid).style.left = parseFloat(left.substring(0,longueur)) - decalage + 'px';
			get(leftarrowid).style.visibility = 'visible';
			if (num == (max-4)){
				get(rightarrowid).style.visibility = 'hidden';
			}
			return (num+1);
		}
	}
	if (direction == 'gauche'){
		if (num > 0){
			get(divid).style.left = parseFloat(left.substring(0,longueur)) + decalage + 'px';
			get(rightarrowid).style.visibility = 'visible';
			if (num == 1){
				get(leftarrowid).style.visibility = 'hidden';
			}
			return (num-1);
		}
	}
	return num;
}

/* --------------------- DIAPORAMA --------------------- */
function lancetiming(ms){
	try{
		timing(ms,images);
	}
	catch(e){
		// On arrive ici si la page n'est pas celle du diaporama.
	}
}

/* ----- Chargement / affichage image ----- */
function display(current){
	current = current + 1;
	if (current > (images.length - 1)){current = 0;}
	get('diapo').style.visibility = 'hidden';
	get('diapo').innerHTML = '<img src = "'+images[current]+'" width = "'+largeur[current]+'" height = "'+hauteur[current]+'" alt = "" title = "" onload = "this.style.visibility = \'visible\';fade_in(\'agence_left\',0);"/>';
	
	return (current);
}

/* ----- Timing permanent récursif ----- */
var mto;
var t=0;
function timing(ms,tab){
	current = display(current);
	clearTimeout(mto);
	mto = setTimeout(function(){timing(ms,tab);},ms);
}

/* ---- Charge une photo dans une div ----- */
function majPhoto(psource,pwidth,pheight,purl){
	//alert(purl);
	get('thephoto').style.visibility = 'hidden';
	//get('portfolio_zoom').style.background = 'background:url(\'images/portfolio/loading.gif\') no-repeat center center;';
	if (purl.length>0) {
		get('thephoto').innerHTML = '<table cellspacing = "0" width = "100%"><tr><td valign = "middle" align = "center" style = "height:432px;"><a href=\''+purl+'\' onclick=\'window.open(this.href); return false;\'><img src = "'+psource+'" width = "'+pwidth+'" height = "'+pheight+'" alt = "" title = "" onload = "get(\'thephoto\').style.visibility = \'visible\';fade_in(\'portfolio_zoom\',0);"/></a></td></tr></table>';
	}else {
		get('thephoto').innerHTML = '<table cellspacing = "0" width = "100%"><tr><td valign = "middle" align = "center" style = "height:432px;"><img src = "'+psource+'" width = "'+pwidth+'" height = "'+pheight+'" alt = "" title = "" onload = "get(\'thephoto\').style.visibility = \'visible\';fade_in(\'portfolio_zoom\',0);"/></td></tr></table>';
	}
	
}

/* ----- Deplacement d'une div dans une autre verticalement ----- */
function movev(direction,num,max,divid,leftarrowid,rightarrowid,decalage){
	var top = get(divid).style.top;
	var longueur = top.length - 2; 
	if (direction == 'bas'){
		if (num < (max-1)){
			get(divid).style.top = parseFloat(top.substring(0,longueur)) - decalage + 'px';
			get(leftarrowid).style.visibility = 'visible';
			if (num == (max-6)){
				get(rightarrowid).style.visibility = 'hidden';
			}
			return (num+1);
		}
	}
	if (direction == 'haut'){
		if (num > 0){
			get(divid).style.top = parseFloat(top.substring(0,longueur)) + decalage + 'px';
			get(rightarrowid).style.visibility = 'visible';
			if (num == 1){
				get(leftarrowid).style.visibility = 'hidden';
			}
			return (num-1);
		}
	}
	return num;
}
