var offset = ""; 
var user_agent,browser, IE6;
var infosOn = false;
var ajaxLoaded = false;
// $.fx.speeds._default = 1000;

$(document).ready(function() {
	if($("#diaporama").length){	
		$("#diaporama").carouFredSel({
			width :960,
			height : 297,
			circular :true,
			infinite :true,
			direction : "left",
			items :{
				visible:1,
				width:"variable",
				height:"variable"
			},
			scroll : {
				effect			: "easeOutBounce",
				duration		: 1000,							
				pauseOnHover	: true
			},
			prev : {	
				button	: "#diapo_prev",
				key		: "left"
			},
			next : { 
				button	: "#diapo_next",
				key		: "right"
			},
			pagination  : "#containNav"
		});
	}
	
	
	bindNewslet();
	// fixShadows();
	// fixBottom();	
	reBindPage();
	init_lien_fancybox_CMS();
	bindZoomPano();	
	fixBottomBg()
	
	$(window).resize(fixBottomBg);
	
});

function fixBottomBg(){
	$('#tabGlobal').css('height',$(document).height())	
}

function bindNewslet(){
	$('#openNewsLet').click(function(){
			$('#block_newslet').slideToggle();
	})
}

function fixShadows(){
	var $g = $('.g');
	var gHeight = $g.innerHeight();
	var imgGHeight = 352;
	// $('.g').css('backgroundPosition','0px 352px')
	
	// console.log(gHeight);
	
	var $d = $('.d');
	var imgDHeight = 314;	
	
	/*$g.find('div').height(gHeight - imgGHeight);
	$d.find('div').height(gHeight - imgDHeight);*/

}

function fixBottom(){	
	if($('#customAccueil').length){
		$('#tabGlobal').height( $(document).height());
	}
}


function reBindPage(){
	
	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;
}



