/*
 * Image ToolTip plugin 
 * powered by jQuery (http://www.jquery.com)
 * written by Linkble (http://www.linkble.com)
 * for more info visit http://toptips.linkble.com/
 */
 
this.toptips = function(){	

	/* screen height and width */
	var bodywidth = $(window).width();
		
	$(".toptips").hover(function(e){

		/* getting image source from rel attrbute */
		var image = $(this).attr("rel");

		/* appending image to the body */
		$("body").append("<div id='tip'><img src='"+ image +"' /></div>");

		/* getting image container width */
		var imgwidth = $("#tip").width();

		/* offset calculation */
		xOffset = 10;
		if((bodywidth - e.pageX) < (bodywidth / 2)){
			yOffset = -30 - imgwidth;
		} else {
			yOffset = 30;
		}

		/* setting css position of #tip */
		$("#tip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		$("#tip").remove();
    });

    /* moving image with the cursor */
	$(".toptips").mousemove(function(e){
		$("#tip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};
