/*
 * 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 = 150;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	jQuery("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		//jQuery("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='' />"+ c +"</p>");								 
		jQuery("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='' /></p>");
		
		jQuery("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		jQuery("#screenshot").remove();
    });	
	jQuery("a.screenshot").mousemove(function(e){
		jQuery("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};
/*
this.screenshotPreviewPorownaj = function(){	
		xOffset = -20;
		yOffset = -230-190;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	jQuery("a.screenshot_2").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		jQuery("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='' /></p>");
		
		jQuery("#screenshot").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		jQuery("#screenshot").remove();
    });	
	jQuery("a.screenshot_2").mousemove(function(e){
		jQuery("#screenshot").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px");
	});			
};
*/
this.screenshotPreviewPorownaj = function(){	
	var windowW = 0, windowH = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	  //Non-IE
	  windowW = window.innerWidth;
	  windowH = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	  //IE 6+ in 'standards compliant mode'
	  windowW = document.documentElement.clientWidth;
	  windowH = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	  //IE 4 compatible
	  windowW = document.body.clientWidth;
	  windowH = document.body.clientHeight;
	}
	
	jQuery("a.screenshot_2").hover(function(e){
		this.t = this.title;
		this.title = "";	
		
		xPos = e.pageX;
		yPos = e.pageY;
		this.wh = this.name.split('_');
		if (windowW - e.pageX - this.wh[0] < 0) xPos = e.pageX - this.wh[0] - 20;
		else xPos += 20;
		if (xPos < 0) xPos = 0;
		if (windowH - e.pageY - this.wh[1] < 0) yPos = e.pageY - this.wh[1] - 20;
		if (yPos < 0) yPos = 0;
		jQuery("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='' width='"+this.wh[0]+"' height='"+this.wh[1]+"' /></p>");
		jQuery("#screenshot").css("top", yPos + "px").css("left", xPos + "px").fadeIn("fast");
  },
	function(){
		this.title = this.t;	
		jQuery("#screenshot").remove();
  });
	jQuery("a.screenshot_2").mousemove(function(e){
		xPos = e.pageX;
		yPos = e.pageY;
		this.wh = this.name.split('_');
		if (windowW - e.pageX - this.wh[0] < 0) xPos = e.pageX - this.wh[0] - 20;
		else xPos += 20;
		if (xPos < 0) xPos = 0;
		if (windowH - e.pageY - this.wh[1] < 0) yPos = e.pageY - this.wh[1] - 20;
		if (yPos < 0) yPos = 0;
		jQuery("#screenshot").css("top", yPos + "px").css("left", xPos + "px");
	});			
};

// starting the script on page load
jQuery(document).ready(function(){
	screenshotPreview();
	screenshotPreviewPorownaj();
});
