/*
 * 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 = 10;

   function getWidth(){
      return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
   }
   function getHeight(){
      return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;
   }

		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	
	        $("a.tooltipimage").click(function(){
				return false;
			});

	
	$("a.tooltipimage").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/><div class='tooltipimagetitle'>" + this.t : "</div>";
		$("body").append("<div id='tooltipimage'><img src='"+ this.rel +"' alt='' />"+ c +"</div>");								 
		$("#tooltipimage")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
    

	function(){
		this.title = this.t;	
		$("#tooltipimage").remove();
    });	
	$("a.tooltipimage").mousemove(function(e){
      var t=$('#tooltipimage'), x=t.get(0), err;
      try{   t.css({top:(e.pageY+x.offsetHeight>getHeight()+document.documentElement.scrollTop?e.pageY-x.offsetHeight:e.pageY-yOffset)+'px',left:(e.pageX+x.offsetWidth>getWidth()+document.documentElement.scrollLeft?e.pageX-x.offsetWidth-xOffset:e.pageX+xOffset)+'px'});}catch(err){}

	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});
