$(document).ready(function(){
	

/***************************************************************************************
	Afficher article
***************************************************************************************/
	var ancienId = 0;
	$('.afficher-article').click(function(){
	
		$.ajax({
			type: 'POST',
			data : {
				'ancienId' : ancienId
			},
			url : '/fr/ajax/articleAccueil.php',
			success : function(data) {
				var json_data = JSON.parse(data);
			
			$('#en-vedette img').remove();
			if(json_data.image != ''){
				$('<a href="'+json_data.href+'"><img src="'+json_data.image+'" alt="'+json_data.altImage+'" border="0" /></a>').appendTo('#en-vedette span#wrap-img')
			}
			$('#en-vedette div.left span.auteur').text(json_data.nomAuteur);
			$('#en-vedette div.left h2 a').text(json_data.titre).attr('href',json_data.href);
			$('#en-vedette p:last').text(json_data.resume);
			$('#en-vedette div#lire a#lire-suite').attr('href', json_data.href);
			return false;
		}
	});
	return false;
})

	
/***************************************************************************************
	Afficher article
***************************************************************************************/
/*	var ancienId = 0;
	$('.afficher-article').click(function(){
	
		$.ajax({
			type: 'POST',
			data : {
				'ancienId' : ancienId
			},
			url : '/fr/ajax/articleAccueil.php',
			success : function(data) {
				var json_data = JSON.parse(data);
				$('.resume img').remove();
				if(json_data.image != ''){
					$('.resume h1').after('<img src="'+json_data.image+'" alt="'+json_data.altImage+'" border="0" />')				
				}
				$('.resume p:first strong').text(json_data.nomAuteur);
				$('.resume h2').empty().html(json_data.titre);
				$('.resume p:last').text(json_data.resume);
				$('.resume ul li:first a').attr('href', json_data.href);
				return false;
			}
		});
		return false;
	})*/

/***************************************************************************************
	Formulaire de recherche
***************************************************************************************/

	$('#recherche div').hide();
	
	if($('#recherche input:checked').length > 0 ){
		$('#recherche a').addClass('actif');
		$('#recherche div').slideDown();
	}
	
	
	$('#recherche a').click(function (){
		$(this).toggleClass('actif');							  
		$('#recherche div').slideToggle();
		return false;
	})

	$('#recherche').submit(function (){
		if($('#champ_texte').attr('value') == $('#champ_texte').attr('title') || $('#champ_texte').attr('value') == ''){
			alert('Vous devez remplir le champ de recherche');
			return false;
		}
	})

/***************************************************************************************
	Tooltip
***************************************************************************************/
		
	if($('#cms').length == 0) {
		
		test = false;
			
		$('.ajax-images a, .thumbinner > a').not('.ajax-images ul li a, .articles-associes a')
			.hover(function (){
				var urlImg = '';
				if($(this).find('img').length > 0){
					urlImg = $(this).find('img').attr('src');	
				}
				var id = ((urlImg).split("/"))[3]
				var hoveredLink = $(this);
				
				$.ajax({
					type: 'POST',
					data : {
						'id' : id
					},
					url : '/fr/voir-image.php',
					success : function(data) {
						if(data == ""){
							$('#tooltip').empty();
							$('#tooltip').addClass('ignore');
						}else {
							$('#tooltip').removeClass('ignore');
							$('#tooltip').empty().append(data);
						}
					}
				});
			});
			
			$('.ajax-images a, .thumbinner > a').not('.ajax-images ul li a, .articles-associes a').tooltip({
				showURL: false,
				fade: 250,
				bodyHandler: function() { 
					return $("<img/>").attr("src", '/img/loader.gif'); 
				}  
			})
			
		$('.caption > a').hover(function(){
			$(this).parents('.thumbinner').children('a').trigger('hover');
		});
		
		$("#tooltip img").ajaxStart(function(){
			$(this).show();
		})
		
		$("#tooltip img").ajaxStop(function(){
			$(this).hide();
		})
		
		$('.vignettes-horizontal a, .thumbinner > a, .viewer > a').not('.vignettes-horizontal ul li a, .articles-associes a, .objet360 a, .tooltip').fancybox({
			'zoomSpeedIn': 500,
			'zoomSpeedOut': 500,
			'overlayShow': true,
			'overlayOpacity': .8
		});
		
    $('a.fancyvideo').each(function(e){
      var _this = $(this);

  		_this.fancybox({
  			'frameWidth': parseInt(_this.attr('data-width'),10),
  			'frameHeight': parseInt(_this.attr('data-height'),10)+30,
			'zoomSpeedIn': 500,
			'zoomSpeedOut': 500,
			'overlayShow': true,
			'overlayOpacity': .8,
			'hideOnContentClick': false
		});
		
    });
		
		$('a.fancyson').fancybox({
			'frameWidth': 440,
			'frameHeight': 125,
			'zoomSpeedIn': 500,
			'zoomSpeedOut': 500,
			'overlayShow': true,
			'overlayOpacity': .8,
			'hideOnContentClick': false
		});
		

	}

});
