/*
 * 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
 * http://drupal.org/node/729648
 *
 */
 
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = -20;
		yOffset = -300;
		
    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result
   
  /* END CONFIG */
  $("a.preview").hover(function(e){
    this.t = this.title;
    this.title = ""; 
    var c = (this.t != "") ? "<br/>" + this.t : "";
    var preview_link = $('#' + this.id + '-url')[0];
    $("body").append("<p id='preview'><img src='"+ this.href +"' alt='Chargement de l\image' />"+ c +"</p>");               
     var posY;

    if (e.pageY - $(window).scrollTop() + $('#preview').height() >= $(window).height() ) {
      posY = $(window).height() + $(window).scrollTop() - $('#preview').height() - 15;
    } else {
      posY = e.pageY - 15;
    }
   $("#preview")
      .css("top",(posY) + "px")
      .css("left",(e.pageX + 15) + "px")
      .fadeIn("fast");           
    },
  function(){
    if (this.t) {
      this.title = this.t; 
    }
          $("#preview").remove();
    });

};

// starting the script on page load
$(document).ready(function(){
	imagePreview();
});
