/*
 * 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 = 175;
		yOffset = 10;
		
		// 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){
		this.t = this.title;
		this.title = "";
		this.timg = $(this).children('img').attr('title');
		$(this).children('img').attr('title', '');
		var c = (this.t != "") ? "<span style='display:block; text-align:center;'>" + this.t + "</span>" : "";
		var d = '';
		if($(this).parent().next().children().html()!=null)
			d = '<br />'+$(this).parent().next().children().html();
		else
			d = c;
		$("body").append("<p id='preview'><img src='"+ $(this).parent().find('input').attr('value') +"' alt='Image preview' />"+ d +"</p>");
		if(e.pageX <= ($('body').width()/2))
			$("#preview")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");
		else
			$("#preview")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX - $("#preview").width() - yOffset) + "px")
				.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$(this).children('img').attr('title', this.timg);	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		if(e.pageX <= ($('body').width()/2))
			$("#preview")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px");
		else
			$("#preview")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX - $("#preview").width() - yOffset) + "px");
	});			
};

/*
 * 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 = 20;
		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.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		if(e.pageX <= ($('body').width()/2))
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");
		else
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX - $("#tooltip").width() - yOffset) + "px")
				.fadeIn("fast");
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		if(e.pageX <= ($('body').width()/2))
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px");
		else
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX - $("#tooltip").width() - yOffset) + "px")
				.fadeIn("fast");
	});			
};
