/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	jQuery("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		jQuery("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		jQuery("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.css("border-radius","10px")
			.css("-moz-border-radius","10px")
			.css("-webkit-border-radius","10px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		jQuery("#preview").remove();
    });	
	jQuery("a.preview").mousemove(function(e){
		jQuery("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
						.css("border-radius","10px")
			.css("-moz-border-radius","10px")
			.css("-webkit-border-radius","10px");
	});			
};


/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = $(this).parent().find('div').html();	
		this.title = "";									  
		$("body").append("<div id='tooltip'>"+ this.t +"</div>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		// this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		// $("#tooltip").remove();	
	});			
};


/*
 * BoxDialog script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Maxime Auriau 
 * 
 */
// Chaque liens de supression contient la class="MaBoxDialog"
this.MaBoxDialog = function(){	
	$("a.MaBoxDialog").click(function(e){											  
		this.t = this.title;
		this.title = "";
		// récupère l'id du produit
		var ligne = this.name;
		// on créer une div de type dialog qui servira de boite de confirmation
		$("body").append("<div title='Supprimer cet article' id='MaBoxDialog'>"+ this.t +"</div>");
		$("#MaBoxDialog").hide();
		// configuration de la boite de dialogue
		$("#MaBoxDialog").dialog({
			autoOpen:true,
			modal: true,
			overlay :{
				opacity: 0.7,
				background: '#000'
			},
			buttons: {
				'Oui': function() {
						jQuery.ajax({
							type: "POST",
							url : "ajax/supprimer.php",
							data: "ligne="+ligne,
								success: function(msg){
								if(msg.isOk==true){	
								// on ferme la boite
								jQuery("#MaBoxDialog").dialog("close"); 
								// on supprime la boite de dialogue
								jQuery("#MaBoxDialog").remove();
								// on fait diparaitre la ligne
								jQuery("#suppr"+ligne).hide(1000);
								// on supprime la ligne
								jQuery("#suppr"+ligne).remove();
								// on met à jour le prix
								jQuery("#PTotal span").html(msg.total);
								window.open('psicom18-boutique-processus-panier-0.html','_self');
								}
							}	
						});					
				},
				'Non': function() {
				   $(this).dialog('close');
				}
			}
		});
	});
};


/*
 * OptionsDialog script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Maxime Auriau 
 * 
 */

this.OptionsDialog = function(){	
	/* CONFIG */		
		// xOffset = 500;
		// yOffset = 300;		

	/* END CONFIG */		
	$("a.OptionsDialog").click(function(e){
		this.t = $(this).parent().find('div').html();
		this.title = "";									  
		$("body").append("<p id='OptionsBox'>"+ this.t +"</p>");
		$("#OptionsBox").hide();
		$("#OptionsBox").dialog({
			autoOpen:true,
			modal: true,
			overlay :{
				opacity: 0.7,
				background: '#000'
			},
			buttons: [
				{
					text: "Ok",
					click: function() { 
						jQuery("#OptionsBox").dialog("close"); 
						jQuery("#OptionsBox").remove();
					}
				}
			]
		});		
    });
	
};


