function initTooltip(){
    	jQuery('.tab-holder .post .image-holder').each(function(){
		var _x = 0;
		var _y = 0;
		var _tooltip = jQuery(this).find('div.popup');
        var _this = jQuery(this);
        var _tooltip_bottom = 0;
        var winbottom = 0;

		jQuery(this).mouseenter(function(e){
			_x = jQuery(this).offset().left;
			_y = jQuery(this).offset().top;
            _tooltip_bottom = (_y+25)+_tooltip.height();
            winbottom = jQuery(window).scrollTop()+jQuery(window).height();
            var _index = jQuery('.tab:visible .image-holder').index(_this);
            if(_this.parents('.tab').find('.image-holder').length-1==_index){
				_tooltip.css({left:e.pageX - _x + 10, top:e.pageY - _y - 325});
			}else if(_tooltip_bottom > winbottom) {
                _tooltip.css({left:e.pageX - _x + 10, top:e.pageY - _y - 50});
            }else{
				_tooltip.css({left:e.pageX - _x + 10, top:e.pageY - _y + 25});
			}
			if(_tooltip.find('img').length == 0){
				var _img = _this.find('a').attr('rel');
				if(_img) {
					var _html = _tooltip.html();
					_tooltip.html('<img src="' + _img + '" alt=""/>'+_html);
				}
			}
			jQuery(this).addClass('show-popup');
		}).mouseleave(function(){
			jQuery(this).removeClass('show-popup');
		}).mousemove(function(e){
            _tooltip_bottom = (_y+25)+_tooltip.height();
            winbottom = jQuery(window).scrollTop()+jQuery(window).height();
			var _index = jQuery('.tab:visible .image-holder').index(_this);
			if(_this.parents('.tab').find('.image-holder').length-1==_index){
				_tooltip.css({left:e.pageX - _x + 10, top:e.pageY - _y - _this.find('img').height()*2 - 35});
			}else if(_tooltip_bottom > winbottom) {
                _tooltip.css({left:e.pageX - _x + 10, top:e.pageY - _y - _this.find('img').height()*2 + 75});
            }else{
				_tooltip.css({left:e.pageX - _x + 10, top:e.pageY - _y + 25});
			}
		});
	});
	
	jQuery('.interest-column ul li .info-popup a').click(function(){
		jQuery(this).parents('.info-popup').fadeOut(400,function(){
			jQuery('.interest-column ul li').removeClass('showed');
		});
	});
}
jQuery(document).ready(function(){
	initTooltip();
});
