/*
 * Url 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.screenshotPreview = function(){	
		/* CONFIG */
		
		//xOffset = 25;		
		//yOffset = 30;			
		//yOffset = $("#screenshot").height();
		xOffset = document.documentElement.clientHeight/2;	
		yOffset = document.documentElement.clientWidth/2;	
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		//var vp = xOffset + document.documentElement.scrollTop
		var browserName = navigator.userAgent.toLowerCase();
		if (browserName.indexOf("safari") != -1) 
		{
			var vp = xOffset + (document.body.scrollTop) 		
		}
		else
		{
			var vp = xOffset + (document.documentElement.scrollTop) 
		}
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='Url Preview'/>"+ c +"</p>");								 
		$("#screenshot")
			/*.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")*/
			.css("top", (vp - $("#screenshot").height()/2) + "px")
			//.css("left",(yOffset - $("#screenshot").width()/2) + "px")
			.css("left", (e.pageX + 50) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		//var vp = xOffset + document.documentElement.scrollTop
		var browserName = navigator.userAgent.toLowerCase();
		if (browserName.indexOf("safari") != -1) 
		{
			var vp = xOffset + (document.body.scrollTop) 		
		}
		else
		{
			var vp = xOffset + (document.documentElement.scrollTop) 
		}
		$("#screenshot")
			.css("top", (vp - $("#screenshot").height()/2) + "px")
			//.css("left",(yOffset - $("#screenshot").width()/2) + "px")
			.css("left", (e.pageX + 50) + "px")
	});			
};

// vertically center something in the viewport
// make it a plugin!
(function($) {
  $.fn.vCenter = function(options) {
	var pos = {
	  sTop : function() {
		return window.pageYOffset
		|| document.documentElement && document.documentElement.scrollTop
		||  document.body.scrollTop;
	  },
	  wHeight : function() {
		return window.innerHeight
		|| document.documentElement && document.documentElement.clientHeight
		|| document.body.clientHeight;
	  }
	};
	return this.each(function(index) {
	  if (index == 0) {
		var $this = $(this);
		var elHeight = $this.height();
		var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
		$this.css({
		  /*position: 'absolute',
		  marginTop: '0',*/
		  top: elTop
		});
	  }
	});
  };
}) // end plugin



// starting the script on page load
$(document).ready(function(){	
	screenshotPreview();	
});
