/*
 * 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 = 10;
		yOffset = 30;
		Offset = 50;
		eWidth = 200;
		eHeight = 155;
		
		// 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 : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");	
		
		$("#screenshot")
			.css("top",(getPos("y", e.pageY)) + "px")
			.css("left",(getPos("x", e.pageX)) + "px")
			//.css("left",(e.pageX - yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(getPos("y", e.pageY)) + "px")
			.css("left",(getPos("x", e.pageX)) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	screenshotPreview();
});

function getPos(a, e){
	var pos
	if (a == "x"){
		if (parseInt(navigator.appVersion)>3) {
		 if (navigator.appName=="Netscape") {
		  pos = window.innerWidth;
		 }
		 if (navigator.appName.indexOf("Microsoft")!=-1) {
		  pos = document.body.offsetWidth;
		 }
		}
		if ((eWidth + xOffset + e + Offset) >= pos){
			pos = e - xOffset - eWidth;
		}else{
			pos = e + xOffset;
		}
	}else{
		if (parseInt(navigator.appVersion)>3) {
		 if (navigator.appName=="Netscape") {
		  pos = window.innerHeight;
		 }
		 if (navigator.appName.indexOf("Microsoft")!=-1) {
		  pos = document.body.offsetHeight;
		 }
		}
		if ((eHeight + yOffset + e + Offset) >= pos){
			pos = e - yOffset - eHeight;
		}else{
			pos = e + yOffset;
		}
	}	
	return pos;
}