function showPopup(e){
	$('.purple_popup').hide();

	var popup = e.children('.purple_popup');
	
	popup.css({display:"block", opacity:0, zIndex:200}).parent().css({zIndex:100});
	
	var overRight = (e.parent().width() - 23) - (popup.width() + e.position().left);	
	var offsetLeft = overRight <= 0 ? e.position().left + overRight : e.position().left + 3;
	var offsetTop = e.position().top + e.height() + 5;
	
	popup.css({top: offsetTop + "px", left: offsetLeft + "px"}).animate({opacity:1},150);
};

function hidePopup(e){
	var popup = e.children('.purple_popup');
	popup.hide().css({zIndex:1}).parent().css({zIndex:1});
};

$(function(){
	// image hover effect
	var highlighted = false;
	var timeout;
	
	$('.glow_popup img').bind('mouseover',function(event){
		//event.stopPropagation();
		
		var container = $(this).parent().parent('.glow_popup');
		showPopup( container );
		
		clearTimeout(timeout);
		if( !highlighted ){
			highlighted = true;
			container.addClass('highlighted');
			$('.glow_popup:not(".highlighted")').animate({opacity:.4},150);
			
		} else {
			$('.highlighted').removeClass('highlighted').animate({opacity:.4}, 150);
			container.animate({opacity:1},150).addClass('highlighted');
		}
	});
	
	$('.glow_popup img').bind('mouseout', function(event){
		//event.stopPropagation();
		var container = $(this).parent().parent('.glow_popup');
		hidePopup( container );
		timeout = setTimeout(function(){
			highlighted = false;
			$('.glow_popup').animate({opacity:1},150).removeClass('highlighted');
		},250);
	});
});