(function($){

	$.fn.tooltip = function(userInput){
		
		var $all = $(this);
		
		return $(this).each(function(){
			
			var defaults = $.extend({
				
			}, userInput);
			
			var $button = $(this);
			var $parent = $button.parent();
			var position = $button.position();
			var html = $button.html();			
			var $tooltip = $("<div/>");
			$tooltip.addClass("tooltip").html(html);
			//alert($tooltip.html());
			var posLeft = position.left - 89 + 13;
			var posTopEnd = position.top - 120 - 13;
			$tooltip.remove();
			var posTopStart = posTopEnd - 30;
			var animator = 0;
			$tooltip.css({
				left: posLeft
			});
			
			if($.browser.safari == true){
				var host = "http://" + document.location.host;
				//alert("url('" + host + "/style/images/tooltip.gif')");
				$tooltip.css({
					"background-image":"url('" + host + "/style/images/tooltip.gif')"	
				});
			}
			
			$button.hover(function(){
				
				var image_hover = "url('http://" + document.location.host + "/style/images/dot_hover.png')";
				$(this).css({"background-image":image_hover});

				$("tooltip").animate({
					opacity: 0,
					top: posTopStart
				}, 200, function(){
					$(this).remove();	
				});			
				
				animator = setTimeout(function(){
					
					$tooltip.css({
						top: posTopStart,
						opacity: 0
					}).appendTo($parent).stop().animate({
						opacity: 1,
						top: posTopEnd
					}, 200).hover(function(){},function(){
						$(this).animate({
							opacity: 0,
							top: posTopStart
						}, 200, function(){
							$(this).remove();	
						});
					});
					
					$tooltip.find(".fancy").fancybox({
						padding: 20,
						hideOnContentClick: false,
						overlayShow: true,
						overlayOpacity: 0.5,
						overlayColor: "#000",
						callbackOnShow: function(){
							$tooltip.animate({
								opacity: 0,
								top: posTopStart
							}, 300, function(){
								$(this).remove();	
							});
							
							$("#fancy_ajax").find("a:not([href^=\"" + host + "\"])").attr("target","_blank");
							
						}
					});
					
				}, 500);
				
			}, function(){
				var image = "url('http://" + document.location.host + "/style/images/dot.png')";
				$(this).css({"background-image":image});
				clearTimeout(animator);
			});
			
			$tooltip.hover(function(){},function(){
				$(this).animate({
					opacity: 0,
					top: posTopStart
				}, 300, function(){
					$(this).remove();	
				});
			});			
						
		});

	}
	
})(jQuery);

var count = 0;
var length = 0;

$("document").ready(function(){
	$(".e_replace").empty().html("<a href=\"mailto:info@compendium-medicum.nl\">info@compendium-medicum.nl</a>");	
	$(".ej_replace").empty().html("<a href=\"mailto:j.palinckx@compendium-medicum.nl\">j.palinckx@compendium-medicum.nl</a>");	
	$(".j_replace").empty().html("<a href=\"mailto:j.palinckx@compendium-medicum.nl\">Judith Palinckx</a>");	
	var host = "http://" + document.location.host;
	//
	
	$("a:not([href^=\"" + host + "\"])").attr("target","_blank");
	//\
	
	$("a:not([href^=\"http://\"])").attr("target","");
	
	$("#download").attr("target","_blank");
	
	if($(".dot").length >= 1){
		$("#world_map .dot").tooltip();
		
		$(".fancy").fancybox({
			padding: 10,
			overlayShow: true,
			overlayOpacity: 0.5,
			overlayCOlor: "#000"
		});
		
	}
	$("<img/>").attr("src", "http://" + document.location.host + "/style/images/dot.png");
	$("<img/>").attr("src", "http://" + document.location.host + "/style/images/tooltip.png");
	$("<img/>").attr("src", "http://" + document.location.host + "/style/images/tooltip.gif");
	
	var $images = $("ul#image_gallery").find("li");
	
	$images.css({
		opacity: 0
	});
	
	length = $images.length;
	
	$images.eq(count).css({
		opacity: 1
	});
	
	setInterval(function(){
	
		$images.animate({
			opacity: 0
		},300);
		
		$images.eq(count).stop().animate({
			opacity: 1
		}, 300);
		
		count++;
		
		if(count == length){
			count = 0;
		}
	
	}, 3500);
	
});

