$(document).ready(function(){
	tooltip2();
	tooltip3();
	$("#pageflip").hover(function() { //On hover...
	$("#pageflip img , .msg_block").stop()
		.animate({ //Animate and expand the image and the msg_block (Width + height)
			width: '307px',
			height: '319px'
		}, 500);
	} , function() {
	$("#pageflip img").stop() //On hover out, go back to original size 50x52
		.animate({
			width: '50px',
			height: '52px'
		}, 220);
	$(".msg_block").stop() //On hover out, go back to original size 50x50
		.animate({
			width: '50px',
			height: '50px'
		}, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
});
	if($("#cont_desc > *:visible").length == 1){
		$(".cache").show();
	}

 });



function clicked(un, deux){
	$(".cache").hide();
	$(".prev_rech" ).show();
	$(".prev_rech:not(." + deux + ")").hide();
	$("#bas_desc").html("<h6>Recherche : "+ un +"</h6>");
	if(deux == "0"){
		$(".prev_rech" ).show();
	}
	//alert($("#cont_desc > *:visible").length);
	if($("#cont_desc > *:visible").length == 1){
		$(".cache").show();
	}else{
		$(".cache").hide();
	}
	return false;
}


tooltip2 = function() {
	var tool = $(".image_aide");
	for (var i=0; i<tool.length; i++) { 
		$(tool[i]).qtip({
   			content: {
         		text: false // Use each elements title attribute
      		},
			style: { 
			 	border: {
        			width: 0.5,
        			radius: 2,
         			color: '#292929'
      			},
      			name: 'dark',

				'font-size': 12,
				'font-family': "Arial, Helvetica, sans-serif",
				'color': "#ffffff",
				'background-color': "#101010",
				'background' : 'url(images/fond_rep_tip.jpg) repeat-x',
				tip: 'leftMiddle' 
   			},
			position: {
      			corner: {
         			target: 'rightMiddle',
         			tooltip: 'leftMiddle'
     			 }
  			},
   			show: 'mouseover',
   			hide: 'mouseout',
			effect:{ type:"shake"}
		})
	}
	
}

tooltip3 = function() {
	var tool = $(".carte");
	for (var i=0; i<tool.length; i++) { 
		$(tool[i]).qtip({
   			content: {
         		text: false // Use each elements title attribute
      		},
			style: { 
			 	border: {
        			width: 0.5,
        			radius: 2,
         			color: '#292929'
      			},
      			name: 'dark',

				'font-size': 12,
				'font-family': "Arial, Helvetica, sans-serif",
				'color': "#ffffff",
				'background-color': "#292929"
   			},
			position: {
   				target: 'mouse',
  				adjust: { mouse: true }
			},
   			show: 'mouseover',
   			hide: 'mouseout',
			effect:{ type:"shake"}
		})
	}
	
}

function creerRequete(){
	var requete = false;
 
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		requete = new XMLHttpRequest();
		if (requete.overrideMimeType) {
			requete.overrideMimeType('text/html; charset=utf-8');
			// Voir la note ci-dessous à propos de cette ligne
		}
	} else if (window.ActiveXObject) { // IE
		try {
			requete = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				requete = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
 
	if (!requete) {
		alert('Abandon :( Impossible de cr&eacute;er une instance XMLHTTP');
		return false;
	}else{
		return requete;
	}
}



function deco_user(){
	jConfirm('Êtes vous sur de vouloir vous déconnecter?', 'Se déconnecter', function(r) {	
				if(r == true){																																
				 desabonne();
				}else{
				}
				
	});	
}


function desabonne(){
	var xhr = creerRequete();
	var url = "deconnect.php";
	xhr.open("GET", url, true);
	 xhr.onreadystatechange = function(){
 	if ( xhr.readyState == 4 )
 	{
	 //location.reload();
 	}
 	}
 	// dans le cas du get
 	xhr.send(null);	
}

function click_com(){
	$('#bouton_form').hide();
	$("#comment").attr("disabled","disabled");
	var comment = $("#comment").attr("value") ;
	var id_video = $("#id_video").attr("value") ;
	var xhr = creerRequete();
	var url = "envoie_com.php";
	var str = "comment=" + escape(comment) + "&idvideo=" + escape(id_video);
	xhr.open("POST", url, true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.setRequestHeader("Content-length",str.length);
	xhr.setRequestHeader("connection", "close");
	xhr.send(str);
	xhr.onreadystatechange = function(){
 	if ( xhr.readyState == 4 )
 	{
		 location.reload();
	
 	}
 	}
}