(function($){
	
	$.fn.getMatrix = function(){
		return this.parents('.compare_link').next().next();
	}
	
	$.fn.positionMatrix = function(){
		//first figure out the offset
		var $matrix = this.getMatrix();
		var $offset = this.parents('.compare_board');
		if($offset.position().left > $('#wrapper').width() - $matrix.width() - 80){
			$matrix.addClass('right');
		}
		$matrix.css({
			top: '-' + (this.height()/2 + 95) + 'px'
		});
	}
	
	$.fn.hideMatrix = function(){
		this.positionMatrix();
		this.getMatrix().hide();
		return this;
	}
	
	$.fn.showMatrix = function(){
		this.getMatrix().show();
		this.positionMatrix();
		return this;
	}
	
})(jQuery);