$(document).ready(function() {
	
	/** Lancement de l'impression de la page **/
	$('.start-print').click(function(){
		window.print();
	});
	
	if($('#cos_bloc_videos li a').size()>0)
	{
		$('#cos_bloc_videos li a').click(function(){
			$('#cos_bloc_videos li a').removeClass('active');
			$(this).addClass('active');
			var id = $(this).attr('href');
			$('#video-1, #video-2, #video-3').hide();
			$(id).show();
			return false;
		});
	}
	
	/*$('.line-grille, .line-video').live('click',
    		function() 
    		{
    			$(this).find('.tooltip').show(200);
    		},
    		function () 
    		{
    			$(this).find('.tooltip').hide(200);
    		}
    	
    );*/
	
	var saisieRecherche = false;
	
	$('.recherche').focusin(function() {
		if (!saisieRecherche)
		{
			$(this).val('');
			saisieRecherche = true;
		}
	});
	
	$('.recherche').focusout(function() {
		if ($(this).val() == '')
		{
			$(this).val('Recherche');
			saisieRecherche = false;
		}
	});
	
	$('#formRecherche').submit(function(e) {
		
		e.preventDefault();
		
		var recherche = $.trim($('#site_recherche').val());
		
		if (recherche.length < 2 || recherche.length > 200 )
		{
			alert('Votre saisie doit comporter entre 2 et 200 caractères.');
			return false;
		}
		
		if (recherche.match("<[^>]+>"))
		{
			alert('Votre saisie est erronée');
			return false;
		}
		
		$.ez('cos_gagnants::CheckStopWord', {'querystring' : $('#site_recherche').val()}, function(data) {
			if(data.content.stopword)
				alert('Votre saisie est erronée');
			else
				$('#formRecherche').unbind('submit').submit();
				
		});
		
		
	});
});


//Bouton Radio en image initialisation
function btRadioimage(){
	//ecouteur du bouton et du click
	$('.radioImg').bind('click', function(){
		var nameRadio = $(this).find('input').attr('name');		
		
		if ($(this).hasClass('radioNotSelected')){
			$('.radioImg').each(function(){
				if (nameRadio == $(this).find('input').attr('name')){
					$(this).removeClass('radioSelected');
					$(this).addClass('radioNotSelected');		
				}
			});
			$(this).removeClass('radioNotSelected');
			$(this).addClass('radioSelected');
			$(this).find("input[type='radio']").attr('checked', 'checked');
		}		
	});	
	
	$('.radioImg').each(function(){	
		if ($(this).find('input[type="radio"]').attr('checked'))
			 	$(this).addClass('radioSelected');
		 else
			 $(this).addClass('radioNotSelected');
		 aFocusradio = $('<a>',{
			 html: 		'&nbsp;',
			 href: 		'#',
			 'class':	'aBtRadioFocus'
			}).css({
				'display':		'inline-block',
				'width':		'13px',
				'height':		'13px'
			})
			.appendTo(this); 
		 $('.aBtRadioFocus').focus(function (){
			 $(this).css('outline', '1px dotted #000').focusout(function (){
				 $(this).css('outline', 'none')				 
			 });			 
		 });
		 
		 aFocusradio.click(function(e){			
			 e.preventDefault();			 
		 });
	});
	
}
