$(document).ready(function(){
	/*
	
	RENDRE LES .HOME CLICKABLE
	
	*/
	
	$('.home .infos,.home .texte').click(function() {
		window.location = $(this).parent('.home').find('.titre a').attr("href");  
		return false;		
	});
	
	$('.home').hover(function() {
		$(this).find('.titre a').css("color","#333333");
	},function(){
		$(this).find('.titre a').css("color","#000000");
	});

	/* REGISTER */
	$('a.register').click(function(){
		$('#popup_register').fadeIn();
		$('#register_bg').fadeIn();
		return false;	 
																 });
																 
	
	$('#register_bg,.closewindow').click(function(){
		$('.popup').fadeOut();
		$('#register_bg').fadeOut();
																 });
																 
	/*
	CONCOURS
	*/
	
	$('.need_signup').submit(function(){
		$('#popup_contest').fadeIn();
		truc = $(this).find('textarea').val();
		$('#popup_contest input[name="message"]').attr('value',truc);
		$('#register_bg').fadeIn();
		return false;	 
																 });
	
	/*
	CALENDRIER
	*/

	$("#dateshow").click(function(){
		$('#datepicker').show();
	}
	);
	
	/*
	TOP CLUB
	*/
	$(".topclub_show img, #annuaire #stars .star_unit img").fadeTo("fast", 0.5);
	$(".topclub_show, #annuaire #stars .star_unit").hover(function(){
		$(this).find("img").fadeTo("fast", 1.0); // This should set the opacity to 100% on hover
	},function(){
		$(this).find("img").fadeTo("slow", 0.6); // This should set the opacity to 100% on hover
	});
	$(".topclub").hover(function(){
		$(this).css('background-color','#000000'); // This should set the opacity to 100% on hover
	},function(){
		$(this).css('background-color','#8D8D8D'); // This should set the opacity to 100% on hover
	});
	
	/*
	
	*/
	$(".last_events_div").click(function() {  
	window.location = $(this).find('.events_div_clickable h1 a').attr("href");  
	});
	
	$('#annonces #categories a').tooltip({
	track: true,
	delay: 0,
	showURL: false,
	extraClass: "right"
	});
	
	
	$('#menu ul li a').tooltip({
	track: true,
	delay: 0,
	showURL: false,
	extraClass: "menu_tooltip",
	positionLeft: true
	});
	
	
	
	$(".annonce_show").click(function() {  
	window.location = $(this).attr("url");  
	});
	
	$("#header h1 img").hover(function() {  
		$(this).attr("src","images/titre2.png");  
	},function() {  
		$(this).attr("src","images/titre3.png");  
	});
	
	$('a.lightbox').lightBox({fixedNavigation:true}); // Select all links with lightbox class
	// This, or...

	$("#home .last_events_div img").fadeTo("slow", 0.5); // This sets the opacity of the thumbs to fade down to 60% when the page loads
	
	$("#home .last_events_div").hover(function(){
	$(this).find("img").fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
	},function(){
	$(this).find("img").fadeTo("slow", 0.5); // This should set the opacity back to 60% on mouseout
	});
	
	
	$(".home .image img").fadeTo("fast",0.6);
	$(".home").hover(function(){
		$(this).find(".image img").fadeTo("fast", 1.0); // This should set the opacity to 100% on hover
	},function(){
		$(this).find(".image img").fadeTo("slow", 0.6); // This should set the opacity to 100% on hover
	});
	
	
	$('#com_form').submit(function(){
		
		var ele = $(this);
		
		$.post("includes/agenda_com.php",   
				  	{
					   texte : ele.find('textarea').val(),
					   pseudo : ele.find('#pseudo').val(),
					   id : ele.find('#agenda_id').val()
				  	},
				   function(data){ 
						if(data=='fuck') 
						{
							alert("Erreur ! votre commentaire n'a pas pu etre poste.");
						}
						else if(data=='time') 
						{
							alert("Attendez un peu avant de re-poster");
						}
						else
						{
							ele.prev().append(data);
							ele.fadeOut();
						}
				   }
			);		
		
		return false;
										   });
	
	$('#main #content .home .liens img').fadeTo(0,0.4);
	
	$('#main #content .home .liens a').hover(function(){
			$(this).prev('img').fadeTo(100,1);
															},function(){
			$(this).prev('img').fadeTo(100,0.4);			
															});
	
	$('#com_form2').submit(function(){
		
		var ele = $(this);
		
		$.post("includes/mag_com.php",   
				  	{
					   texte : ele.find('textarea').val(),
					   pseudo : ele.find('#pseudo').val(),
					   id : ele.find('#agenda_id').val()
				  	},
				   function(data){ 
						if(data=='fuck') 
						{
							alert("Erreur ! votre commentaire n'a pas pu etre poste.");
						}
						else if(data=='time') 
						{
							alert("Attendez un peu avant de re-poster");
						}
						else
						{
							ele.prev().append(data);
							ele.fadeOut();
						}
				   }
			);		
		
		return false;
										   });
	
	$('.erreur').fadeOut(0,function(){$(this).fadeIn("slow");});
	
	$('a.delete').click(function(){
									 var answer = confirm("Voulez-vous vraiment supprimer cette entrée ?");
									 if(!answer)
									 {
										return false; 
									 }
									 });
	
	/* annuaire */								 
								
	$('#annuaire_droite li:even').addClass('odd');
								
	$('#annuaire #stars a').tooltip({
	track: true,
	delay: 0,
	showURL: false,
	extraClass: "annuaire_tooltip"
	});
	
	/* concours */
	
	$('#concours img:not(.lyon01)').fadeTo("fast", 0.5); // This sets the opacity of the thumbs to fade down to 60% when the page loads
	
	$('#concours img:not(.lyon01)').hover(function(){
		$(this).fadeTo("slow", 1.0);
		$(this).next('p').css('color','#000');
	},function(){
		$(this).fadeTo("fast", 0.5);
		$(this).next('p').css('color','');
	});
	
	$('.contest a.contestimga').tooltip({
	track: true,
	delay: 0,
	showURL: false,
	extraClass: "annuaire_tooltip"
	});
	
	/* fin jquery */
});
