$(document).ready(function(){
	$(document).pngFix();
	 $('#Acts').cycle({
        fx:     'scrollVert',
        speed:   500,
        timeout: 0,
        prev:    '#prevAct',
        next:    '#nextAct'
    });

	//$('ul.gallery li img').css("display", "none");
	//Galleria
	$('ul.gallery').galleria({
		history   : true, 
		clickNext : true,
		insert    : '#gallery_main',
		onImage   : function(image,caption,thumb) { 
			

			// fade in the image & caption
			if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
				image.css('display','none').fadeIn(1000);
			}
			//caption.css('display','none').fadeIn(1000);	

			// fetch the thumbnail container
			var _li = thumb.parents('li');

			// fade out inactive thumbnail
			_li.siblings().children('img.selected').fadeTo(500,0.5);

			// fade in active thumbnail
			thumb.fadeTo('fast',1).addClass('selected');
		},
		onThumb : function(thumb) {
			
		
			// fetch the thumbnail container
			var _li = thumb.parents('li');

			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.5';
			
			
			// fade in the thumbnail when finnished loading
			//thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
			thumb.css('opacity',_fadeTo);

			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.5); } // don't fade out if the parent is active
			);
			
			
		}
		
	});
	//$('ul.gallery li:first').removeClass().addClass('active'); 
	//$("ul.gallery li:first").attr('class','active'); // Activer le premier li
  
  //Tips dans le footer du site
  $(".alerte").qtip({
     //content: "Vous désirez être avisé lorsqu'un poste est ouvert chez Beenox? Inscrivez-vous à notre infolettre sans plus tarder!",
     content: translations[0],
     position: { corner: { tooltip: 'centerBottom' }, adjust: { x: -200, y: -15 } },
     style: {
     	textAlign: 'left',
     	background:'#454545',
     	color:'white',
     	border: {width: 1, radius: 4, color: '#454545'},
     	width: 315,
     	tip: { corner: 'bottomMiddle', size: { x:20, y:6 } }
     },
     show: { delay: 0 }         
  });
  
  
  //Fonction pour effacer le contenu par défaut d'un champ
	$('input:text').focus(function() {
		if($(this).val()==$(this).attr("title")){
    	clearMePrevious = $(this).val();
    	$(this).val("");  
    }
  });
  //Fonction pour remettre le contenu par défaut d'un champ si aucune valeur entrée
  $('input:text').blur(function() {     
    if ($(this).val() == '') {
      $(this).val(clearMePrevious);
    }
  });


});


function change_tester_form_page(tester_id, form_step)
{
	auth_token = $("input[name='authenticity_token']").attr('value');
	$.ajax({beforeSend:function(request){$('#loading').fadeIn('fast');}, complete:function(request){$('#loading').fadeOut('fast');}, data:'authenticity_token=' + encodeURIComponent(auth_token), dataType:'script', type:'post', url:'/fr/testeurs/'+tester_id+'/change_step?step='+form_step}); return false;	
}

function check_age_tester_form()
{
	year = $("select[name:'age_tester']")[2].options[$("select[name:'age_tester']")[2].selectedIndex].value;
	month = $("select[name:'age_tester']")[1].options[$("select[name:'age_tester']")[1].selectedIndex].value;
	day = $("select[name:'age_tester']")[0].options[$("select[name:'age_tester']")[0].selectedIndex].value;
	
	age = get_tester_age(year, month, day);
	
	if(age < 18)
	{
		alert(translations[1]);
	}
	else
	{
		$('#age_form').hide();
		$('#tester_form').show();
	}
}

function get_tester_age(year, month, day){
	ret = 0;
	d = new Date();
	ret = d.getFullYear() - year;
  if(d.getMonth() < month || (d.getMonth() == month && day > d.getDay()))
	{
		ret --;
	}
	return ret;
}
