function backgroundPosition(){
	decalageTop = 116 - ($('#global').offset().top % 116);
	decalageLeft = 116 - ($('#global').offset().left % 116);
	
	if(decalageTop == 116){ decalageTop = 0; }
	if(decalageLeft == 116){ decalageLeft = 0; }

	if(decalageTop != 0 || decalageLeft != 0){
		$('body').css("background-position","-"+Math.round(decalageLeft)+"px -"+Math.round(decalageTop)+"px");
	}
}

function fondgrisFix(){
	decalageTop = $('#global').offset().top;
	decalageLeft = $('#global').offset().left;
	bodyHeight = $('body').height();
	bodyWidth = $('body').width();
	
	$(".fond_gris").css('top',"-"+decalageTop+"px").css('left',"-"+decalageLeft+"px").css('height',bodyHeight+"px").css('width',bodyWidth+"px");
}

function gmapInit(lat,lng,elmtID) {
    var latlng = new google.maps.LatLng(lat,lng);
    var mapOptions = {
      zoom: 16,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById(elmtID), mapOptions);
    
    var marqueur = new google.maps.Marker({
		position: latlng,
		map: map
	});
}


function animateMosaique(period,page){
	if(mosaique[page]){
		$('#mosaique').at_intervals(
			function(){
				$('#mosaique td').each(function(){
					cell_id = $(this).attr("id");
					
					if(mosaique[page][cell_id]){
						if(mosaique[page][cell_id].current){
							pointeur = mosaique[page][cell_id].current;
						}else{
							pointeur = 0;
						}
													
						if(newImg = mosaique[page][cell_id].img[pointeur]){
							if(newImg != "stop"){
								if(newImg != null){
									$(this).css("background","#000000 URL(_img/animation/"+newImg+".jpg) no-repeat");
								}else{
									$(this).css("background","#000000");
								}
							}
						}else{
							$(this).css("background","#000000");
						}
							
						/*
						if(!$(this).hasClass(newclass)){
							// switch class
							$(this).removeClass();
							if(newclass != null){				        
						    	$(this).addClass(newclass);
					    	}
					    	//$(this).switchClass($(this).attr("class"), newclass, 1000);
				    	}
				    	*/
				    	
				    	// incrementation du pointeur
				    	if(pointeur < mosaique[page][cell_id].img.length-1){
				    		mosaique[page][cell_id].current = pointeur+1;
			    		}else{
				    		mosaique[page][cell_id].current = 0;
			    		}
			    	}
				})
			},
			{ name: "animMos", delay: period }
		);
	}else{
		if($("#mosaique").data("animMos")){
			$("#mosaique").data("animMos").should_stop  = true
		}
		$('#mosaique td').css("background","none");
	}
	
	if(mosaique[page] && !mosaique[page].animate && $("#mosaique").data("animMos")){
		$("#mosaique").data("animMos").should_stop  = true
	}
}


function randomEvents(){
	var img1x1 = events['1x1'].sort(function() { return (Math.round(Math.random())-0.5); });
	var img1x2 = events['1x2'].sort(function() { return (Math.round(Math.random())-0.5); });
	var img2x2 = events['2x2'].sort(function() { return (Math.round(Math.random())-0.5); });
	var img2x3 = events['2x3'].sort(function() { return (Math.round(Math.random())-0.5); });
	var img3x4 = events['3x4'].sort(function() { return (Math.round(Math.random())-0.5); });
	//tableau.sort(function() { return 0.5 - Math.random() });
	
	$(".events .bloc img").each(function(index){
		i = index;
		if(i>img1x1.length-1){
			i = i%img1x1.length;
		}
		$(this).attr('src',"_img/events/"+img1x1[i]);
	});
	$(".events .bloc1x2nocufon img").each(function(index){
		i = index;
		if(i>img1x2.length-1){
			i = i%img1x2.length;
		}
		$(this).attr('src',"_img/events/"+img1x2[i]);
	});
	$(".events .bloc2x2 img").each(function(index){
		i = index;
		if(i>img2x2.length-1){
			i = i%img2x2.length;
		}
		$(this).attr('src',"_img/events/"+img2x2[i]);
	});
	$(".events .bloc2x3 img").each(function(index){
		i = index;
		if(i>img2x3.length-1){
			i = i%img2x3.length;
		}
		$(this).attr('src',"_img/events/"+img2x3[i]);
	});
	$(".events .bloc3x4 img").each(function(index){
		i = index;
		if(i>img3x4.length-1){
			i = i%img3x4.length;
		}
		$(this).attr('src',"_img/events/"+img3x4[i]);
	});
}
