/*
 * Tooltip 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.tooltip = function(){	
	/* CONFIG */		
     
     	xOffset = 0;  //220
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.preview").hover(function(e){
        
        
        first = screen.height/3;
        second = 2*screen.height/3;
        third = screen.height;
        
        
        if (e.screenY<=first){
            
            xOffset = 10;
            
        } if((first < e.screenY) && (e.screenY<second)){
            
            xOffset = 220;
                        
        } if(second <= e.screenY){
            
            xOffset = 420;
            
        }
        
		this.t = this.title;
		this.title = "";									  
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.rel +"' height='450' alt='Image preview' />"+ c +"</p>");
		$("#preview")
			.css("top",xOffset + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});

    $("a.napok").hover(function(e){
		this.t = this.title;
		this.title = "";
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='napok'>"+ this.rel +"</p>");
		$("#napok")
			.css("top",(e.pageY - 10) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#napok").remove();
    });
	$("a.napok").mousemove(function(e){
		$("#napok")
			.css("top",(e.pageY - 10) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});
