/*   V1.1
 * Image preview script
 * powered by jQuery (http://www.jquery.com)
   DV phamkhanhcuong@yahoo.com
 */

this.imagePreview = function(){
	/* CONFIG */

    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result
    xOffset = 30;
    yOffset = 30;
    // do rong va cao mac dinh cho anh
   // height=333;
   // width=500;
    var currentWindow=$(window);
    var windowObj = new Object();
        windowObj.width = currentWindow.width();
        windowObj.height = currentWindow.height();
    this.tmp='';
	/* END CONFIG */
	$("a.preview").hover(function(e){
   	   // alert($(this.rel).html());
	   	this.tmp = this.title;
	    this.title = "";
        var rel=' ';
        if($(this.rel).html())
            rel =$(this.rel).html();
  	    //	var c = (this.t != "") ? "<br/>" + this.t : "";
	   	$("body").append("<div id='previewimage'><div style='margin:0 auto;text-align: center; '><img  src='"+ this.tmp +"' alt='Image preview' style='margin:8px 5px'/></div>"+rel+"</div>");
		$("div#previewimage").fadeIn("fast");
         _showpreviewimage(e,windowObj,xOffset,yOffset);
    },
	function(){
	  	this.title = this.tmp;
       // alert(this.title);
	   	$("div#previewimage").remove();
    });

  $("a.preview").mousemove(function(e){
      _showpreviewimage(e,windowObj,xOffset,yOffset);
  });// mose move

};
function _showpreviewimage(e,windowObj,xOffset,yOffset)
{

   var pw = $("div#previewimage").width();
  if(pw)
 {
   var ph= $("div#previewimage").height();
    pageX=e.pageX;
    pageY=e.pageY;
     if(pageX <(windowObj.width/2))
      imgX=pageX+	xOffset;
    else
      imgX=pageX - pw - xOffset;
    if(pageY < (windowObj.height/2))
    {
           imgY = pageY - (ph/2);
    }
    else
    {
             imgY=pageY - (ph/2) ;
    }
    $("div#previewimage")
            .css("top",( imgY-50) + "px")
  	        .css("left",( imgX) + "px")
   }
}
// starting the script on page load
$(document).ready(function(){
	imagePreview();
});
