/*
 * EPISODE17 INTERACTIVE
 * http://www.episode17.com
 *
 * Simple Image tooltip jQuery plugin
 * (c) Julien Iafrancesco 2010
 */

(function($)
{	
	// Shortcut
	$.e17_imageTipAll = function(settings) {
		// Loop all elements that have the imagetip rel attribute and get the url
		$("[rel*=imagetip:]").each(function() {
			var url = $.trim($(this).attr('rel').split('imagetip:')[1]);
			var opts = $.extend(true, {}, settings, {url: url});
			
			$(this).e17_imageTip(opts);
		});
	};

	// Implementation
	$.fn.e17_imageTip = function(settings) {
		settings = $.extend(true, {}, $.fn.e17_imageTip.defaults, settings);
		
		// jQuery loop
		return this.each(function() {
			new ImageTip($(this), settings);
		});
	};
	
	// ImageTip
	function ImageTip(target, settings)
	{
		target.hover(function(event) {
			if (settings.url === false) return;
			
			$("body").append("<div id='e17_imagetip'><img src='" + settings.url + "'></img></div>");
			$("#e17_imagetip")
				.css("position", "absolute")
				.css("top",(event.pageY + settings.xOffset) + "px")
				.css("left",(event.pageX + settings.yOffset) + "px")
				.css("borderStyle", "solid")
				.css("borderColor", settings.borderColor)
				.css("borderWidth", settings.borderWidth)
				.css("backgroundColor", "#000000")
				.hide()
				.fadeIn("slow");
		}, function (event) {
			$("#e17_imagetip").remove();
		}).mousemove(function(event) {
			$("#e17_imagetip")
				.css("top",(event.pageY + settings.xOffset) + "px")
				.css("left",(event.pageX + settings.yOffset) + "px");
		});
	};
	
	// Default settings
	$.fn.e17_imageTip.defaults = {
		url: false,
		borderWidth: 1,
		borderColor: "#ffffff",
		xOffset: 10,
		yOffset: 30
	};
	
})(jQuery);