/*
 * Image preview script
 * powered by jQuery (http://www.jquery.com)
 * 
 * original by Alen Grakalic (http://cssglobe.com)
 * written as plugin by Stefan Pelders
 * 
 */
(function($) {
	$.fn.imagePreview = function(options) {
		options = $.extend({},$.fn.imagePreview.defaults ,options || {});
		var title,container;
		
		$(this).hover(function(event){
			$(this).get(0).nodeName.toUpperCase() != "A" ? a = $("a", this).eq(0) : a=this;
			title = $(a).attr("title"); $(a).attr("title","");
			container = $("<div class='image-preview-shell'><div class='image-preview-container'><div class='image-preview-content'></div><div class='image-preview-bottom'></div></div></div>");
			if($(a).attr("rel")) {
				var img  = new Image();
				$(img).attr("src", $(a).attr("rel")).error(function(){ $(this).attr("src",options.errorImgLocation); });
				$(".image-preview-content",container).append(img).append("<span>"+title+"</span>");
				$(container).appendTo(options.showDiv);
				// msie has black borders when fading the png with alpha transparancy.
				if(options.useAnimation && !$.browser.msie) { $(container).fadeIn(options.animationSpeed); } else { $(container).show(); }
			}
		},
		function(event){
			$(this).get(0).nodeName.toUpperCase() != "A" ? a = $("a", this).eq(0) : a=this;
			$(a).attr("title",title);
			if(options.useAnimation) { $(container).fadeOut(options.animationSpeed).remove(); } else { $(container).remove(); }
		});
		return this;
	}
	$.fn.imagePreview.defaults = {
		showTitle : true,
		showDiv	: "#wrapper",
		useAnimation : true,
		animationSpeed : "fast",
		errorImgLocation: "/images/kapaza_logo.gif"
	}
})(jQuery);
