

// Plugins pour Cluster (extensions jQuery)
jQuery.fn.extend(
{
	extendPage: function(){ // Ajax, permet d'accéder aux billets suivants sans recharger la page (et donc l'url)
		i = 0;
		$("#extendPage a").html('▼ Charger les articles précédents').addClass('extendPage'); // ⇠
		$("#extendPage a").after('<span id="extendPageLoader"><img src="/cluster/sites/theme/_default/images/ajax-loader.gif" alt="Chargement" /> Chargement des articles</span>');
		$("#extendPageLoader").hide();
		$(this).click(function(){
			i++;
			var url = window.location.pathname+'?ajax=1&page='+i;
			$("#extendPage a").hide();
			$("#extendPageLoader").show();
			//
			$.get(
				url, 
				function(data) { // charger le contenu via ajax
					$('#main div.post:last').after(data);
					$(".lightbox").lightbox(); // on est obligé de réactiver lightbox ici
					$("#extendPage a").show();
					$("#extendPageLoader").hide();
				}
			);
			return false;
		});
	},
	loadPostContent: function(){ // Ajax, permet d'accéder aux billets suivants sans recharger la page (et donc l'url)
		i = 0;
		$(".post-load a").html('▼ Charger les articles précédents').addClass('loadPostContent'); // ⇠
		$(".post-load a").after('<span id="loadPostContentLoader"><img src="/cluster/sites/theme/_default/images/ajax-loader.gif" alt="Chargement" /> Chargement des articles</span>');
		$(".post-loadLoader").hide();
		$(this).click(function(){
			i++;
			var url = window.location.pathname+'?ajax=1&page='+i;
			$(".post-load a").hide();
			$(".post-loadLoader").show();
			//
			$.get(
				url, 
				function(data) { // charger le contenu via ajax
					$('#main div.post:last').after(data);
					$(".lightbox").lightbox(); // on est obligé de réactiver lightbox ici
					$(".post-load a").show();
					$(".post-loadLoader").hide();
				}
			);
			return false;
		});
	},
	minComments: function(){
		/*
		$("#comments label").hide();
		$("#comments input").hide();
		//$("#comments legend").hide();
		$("#comments button").hide();
		*/
		$('#new-comment fieldset > *').hide();
		$('#new-comment label').hide();
		$('#new-comment .comment_content').show();
		var textarea_bak = $('#new-comment textarea').text();
		$('#new-comment textarea').text('Ajouter un commentaire');
		
		//
		$("#comments textarea")
			.css('width','100%')
			.css('height','55px')
			.css('color','#ccc');
		
		$("#comments textarea").focus(function(){
			$(this)
				.css('width','100%')
				.css('height','200px')
				.css('color','#000');
			/*
			$("#comments label").show();
			$("#comments input").show();
			//$("#comments legend").show();
			$("#comments button").show();
			*/
			$('#new-comment fieldset *').show();
			$('#new-comment fieldset .user_phone').hide();
			$('#new-comment textarea').text(textarea_bak);
		});
	},
	fixedBottomPop: function(){
		$(this).addClass('fixed-bottom-pop');
		// alert('test');
		$(this).prepend('<a class="remove-pop" href="">(cacher)</a>');
		$('.remove-pop').click(function(){
			$('#invite-newsletter').addClass('hidden');
			$.cookie('fixedBottomPop','hidden',{expires:7,path:'/'});
			return false;
		});
		if($.cookie('fixedBottomPop')){
			$('#invite-newsletter').addClass('hidden');
			//$.cookie('fixedBottomPop','hidden',{expires:7,path:'/'});
			return false;
		}
	}
});

$(document).ready(function() // Agir dès que le DOM est prêt
{ 
	
	
	
	// formValidator : validation des formulaires 
	$("form").validationEngine();
	
	// chargement asynchrome des articles du blog
	$("#extendPage a").extendPage();
	
	// Plugin jQuery lightbox
	$(".lightbox").lightbox();
	
	// Formulaire de commentaire replié par défaut
	$("#comments").minComments();
	
	// qTip
	$('*[title]').qtip({
		content:{attr:'title'}, // Use the ALT attribute of the area map for the content
		style:{classes:'ui-tooltip-light ui-tooltip-rounded'}, // ui-tooltip-tipsy ui-tooltip-shadow 
		show:{delay:0}
	});
	
	// Popup fixe newsletter
	$('#invite-newsletter').fixedBottomPop();
	
	// slides
	/*
	$('.slides').slides({
		preload: true,
		//generateNextPrev: true,
		play: 4500
	});
	*/
	
});
