var offset = ""; 
var user_agent,browser, IE6;
var infosOn = false;
var ajaxLoaded = false;
var cont_context = "";
// $.fx.speeds._default = 1000;

$(document).ready(function() {
	if($("#diaporama").length){	
		$("#diaporama").carouFredSel({
			width :730,
			height : 356,
			circular :true,
			infinite :true,
			direction : "left",
			items :{
				visible:1,
				width:730,
				height:356
			},
			scroll : {
				effect			: "easeOutBounce",
				duration		: 1000,							
				pauseOnHover	: true
			},
			prev : {	
				button	: "#diapo_prev",
				key		: "left"
			},
			next : { 
				button	: "#diapo_next",
				key		: "right"
			}
		});
	}
	
	

	reBindPage();
	
});



function reBindPage(){	
	bindZoomImg()	
	bindZoomPano();	
	bindWmode();
	init_lien_fancybox_CMS();
}

function bindZoomImg(){
	if($(".zoom_image").length)
	{
		$(".zoom_image").fancybox({
			'overlayOpacity'	:	0.5,
			'overlayColor'		:	'#000000',
			'zoomSpeedIn'		:	500,
			'zoomSpeedOut'		:	480,
			'transitionIn'		:	'elastic',
			'transitionOut'		:	'elastic',
			'easingIn'			: 	'easeOutBack',
			'easingOut'			: 	'easeInBack',		
			'centerOnScroll'	: 	true,
			'titleShow'			: 	true,
			'titlePosition'		:	'over'
		});
	}	
}

function bindZoomPano(){
	if($(".zoom_pano").length)
		{
			$(".zoom_pano").fancybox({
				'overlayOpacity':0.5,
				'overlayColor':	'#000000',
				'hideOnContentClick' : false,
				'zoomSpeedIn'		:	500,
				'zoomSpeedOut'		:	480,
				'transitionIn'		:	'elastic',
				'transitionOut'		:	'elastic',
				'easingIn'			: 	'easeOutBack',
				'easingOut'			: 	'easeInBack',
				'centerOnScroll'	: 	true,
				'padding': 5,
				'autoDimensions' :false
			});	
		}	
}

function init_lien_fancybox_CMS()
{
	
	
	$('a.iframe').click(function() {
		var c, w, h,wl, hl, href, partial,rel,px;
		
		rel=$(this).attr('rel');
		
		if(rel!=""){
			var px=rel.indexOf("x");
			if(px>0){
				var wl=rel.substr(0,px);
				var hl=rel.substr(px+1);
				if(hl>0 && wl>0){
					w=parseInt(wl);h=parseInt(hl);
				}
			}
		}
		
		!(w>0) ? w=700 : w=w;
		!(h>0) ? h=400 : h=h;
		
		href = $(this).attr('href');
		partial = $(this).hasClass('partial');
		if(partial)
		{
			$.post('includes/ajax_partial_page.php', {page: href}, function(page) {
				c = '<div style="background-color: #FFFFFF">'+page.content+'</div>';
				$.fancybox({
					autoDimensions: false,
					content: c,
					width: w,
					height: h,
					transitionIn:'elastic',
					transitionOut:'elastic',
					speedIn:200, speedOut:200,
					title: page.titre
				});
				return false;
			}, 'json');
		}
		else
		{
			$.fancybox({
				width: w,
				height: h,
				transitionIn:'elastic',
				transitionOut:'elastic',
				speedIn:200, speedOut:200,
				type: 'iframe',
				'href': href
			});
		}
		return false;
	});
}

function init_line()
{
	/*var py=$("#baseline").offset().top;
	$("#upline").css("top",(py+15)+"px");*/
}

function format_nombre(valeur,decimal,separateur) {
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}

// Retabli le parametre wmode pour les videos embed => z-index embed
function bindWmode(){

	if($('object').length)
	{	
		$('object').each(function(index){
			var $this = $(this);
			var wmode = false;			
			
			var params = $this.find('param');				
			params.each(function(){				
				if($(this).attr('name') == 'wmode'){
					wmode = true;					
				}		
			})

			if(wmode == false){
				$this.append('<param name="wmode" value="opaque"/>');	
				$this.find('embed').attr('wmode','opaque');		
			}
			
			
		})
		
	}
}



