// JavaScript Document

$(document).ready(function () {
	$("#meteo h5").click(function () {
    	$("#meteo div").slideToggle(250);
    });
	$("#text tbody tr:nth-child(even) td").css("background-color", "#fbf8dd");
	$("#text tbody tr td:last-child").css({"width":"auto","padding-right":"10px"});
	//$("#repert tr td,#repert tr th").css({'width':'190px'});
	/*$("#repert tr td:nth-child(2), #repert tr th:nth-child(2)").css({'width':'auto'});*/
	$("#repert tr td:last-child, #repert tr th:last-child").css({"width":"150px"});
	/*$("#repert .center").css({"width":"250px"});*/
	
	
	$("#smallimage a").click(function(){
		$("#bigimage img").attr("src","");
		$("#bigimage img").attr("src",this.href);
		
		
		return false;
	});
	
	var currentPosition = 0;
	var slideH = 88;
	var slides = $('#smallimage img');
	var numberOfSlides = slides.length;
	
	$('#image-inner').css('height', slideH * numberOfSlides);
	//alert(slideH * numberOfSlides)
	
	$('.control').bind('click',function(){
		bouge(this)
	});
	manageControls(currentPosition);
	
	function bouge(ev){
		// Determine new position
		currentPosition = ($(ev).attr('id')=='fl-bottom') ? currentPosition+1 : currentPosition-1;
		
		$(ev).unbind('click');
		manageControls(currentPosition);
		// Move slideInner using margin-left
		$('#image-inner').animate({
			duration:200,
		  'marginTop' : 264*(-currentPosition)
  		})
	}
	
	function manageControls(position){
		// Hide left arrow if position is first slide
		if(position<=0){ $('#fl-top').unbind('click') } else{ $('#fl-top').bind('click',function(){
			bouge(this)
		}); }
		// Hide right arrow if position is last slide
		if(position==Math.floor(numberOfSlides/3)-1){ $('#fl-bottom').unbind('click') } else{ $('#fl-bottom').bind('click',function(){
			bouge(this)
		}); }
	}
	
	
	
	/*$("#content p,#content li,#content h1,# h2").each(function(){
		$(this).html($(this).html().replace(/ (\S+)$/,'&nbsp;$1'));
	});*/
});
