$(document).ready(function() {
	$('a.tTip').tinyTips('title');
	
	$("#send_contact").click(function(){	
		ajaxEmail();
		return false;
	});	
	Cufon.replace('h2');
	Cufon.replace('.cufon_replace');
	
	Cufon.replace('li', { hover: true, hoverables: { li: true } });

	$("#noteElList").mouseleave(function(){	
		for(var i=0;i<=10;i++){
			$('#noteElList #note'+i).removeClass('sel');
		}

	});
	
	$("#noteElList .note").mouseover(function(){	
		var nb = ($(this).attr('id')).substr(4,6);
		for(var i=nb;i>=1;i--){
			$('#noteElList #note'+i).addClass('sel');
		}
		var nbSup = parseInt(nb)+1;
		for(var i=nbSup;i<11;i++){
			$('#noteElList #note'+i).removeClass('sel');
		}

	});
	
	$("#noteElList .note").click(function(){
		var val = ($(this).attr('id')).substr(4,6);
		var id = $(this).parents('.avis').attr("id");
		
		addnote(id, val);
		getnote(id);
		
	});
});

function addnote( id, val, type){
	$.ajax({  // ajax
			type: "POST",
			url: '/ajax/addNote.php',
			data: 'id='+id+'&val='+val,
			dataType: "html",
			success:function(html){
				if (html.length !== 0) {
					$("#noteElList").empty();
					$("#noteElList").prepend(html);
				}
				
			},
			error:function(XMLHttpRequest, textStatus, errorThrows){ 
			}
		});
	return false;
}

function getnote(id){
	$.ajax({  // ajax
			type: "POST",
			url: '/ajax/getNote.php',
			data: 'id='+id,
			dataType: "html",
			success:function(html){
				if (html.length !== 0) {
					$(".noteTotal").empty();
					$(".noteTotal").prepend(html);
				}
			},
			error:function(XMLHttpRequest, textStatus, errorThrows){ 
			}
		});
	return false;
}

function ajaxEmail(){
	var $form = $('form#contactForm');
	var data = $form.serializeArray();
	$.ajax({  // ajax
			type: "POST",
			url: "/ajax/ajaxEmail.php", // url de la page  charger
			data: data,
			dataType: "html",
			success:function(html){ // si la requêté est un succès
				$("#retourmail").empty(); // on vide le div
				$("#retourmail").append(html);
			},
			error:function(XMLHttpRequest, textStatus, errorThrows){ // erreur durant la requete
			}
		});
	return false;
}

function part_fb(url,titre) {
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(titre),'sharer','width=600,height=400');
	return false;
}
function part_tw(id,page) {
	$.ajax({  // ajax
			type: "POST",
			url: '/ajax/partTwitter.php',
			data: 'id='+id+'&page='+page,
			dataType: "html",
			success:function(html){ 
				location.href = html ;
			},
			error:function(XMLHttpRequest, textStatus, errorThrows){ 
			}
		});
  	
	return false;
}

