$(document).ready(function(){
	$("a[rel*=bubblePopup]").each(function(){
		var img = $('img', this);
		if (img.length == 0)
			img = $(this);
		var bubble = $($(this).attr('href'));
		$(document.body).append(bubble);
		bubble.hide();
		var isShown = false;
		var hideTime = null;
		var showIt = function(){
			if (hideTime){
				clearTimeout(hideTime);
				hideTime = null;
			}
			//alert();
		
			if (!isShown){
				var pos = jQuery.iUtil.getPosition(img[0]);
				//bubble.stop({gotoEnd :false});
				
			if(($(this).attr('class').toString())=="homebubble"){
			bubble.css({
					position:'absolute', 
					top:-85 + img[0].offsetHeight + pos.y + 'px', 
					left:pos.x - 130 - (img[0].offsetWidth/2) + 'px'
				});
			}else{
				bubble.css({
					position:'absolute', 
					top:img[0].offsetHeight + pos.y + 'px', 
					left:pos.x - 180 - (img[0].offsetWidth/2) + 'px'
				});
			}
				bubble.animate({opacity: "show"}, "slow");
				isShown = true;
			}
		};
		var hideIt = function(){
			if (isShown && !hideTime){
				//bubble.stop({gotoEnd :false});
				hideTime = setTimeout(function(){
					bubble.animate({opacity: "hide"}, "fast");
					isShown = false;
				}, 500);
			}
		};
		img.hover(showIt, hideIt);
		bubble.hover(showIt, hideIt);
		img.focus(showIt);
		img.blur(hideIt);
	});
});
