
$(document).ready(function() {
  $('#btn_cite').click(function (e) {
 //   posX = e.pageX - 375;
 //   posY = e.pageY - 75;
	
 //   $('#modal_record_cite').modal({position: [posY, posX]});
	pos = _modal_offset(this, '#modal_record_cite');
    $('#modal_record_cite').modal({position: pos});
    return false;
  });
  $('#btn_flag').click(function (e) {
	pos = _modal_offset(this, '#modal_search_share');
    $('#modal_search_share').modal({position: pos});
    return false;
  });


	var _modal_offset = function(trigger, modal) {
	//	get the position of the button we clicked
		pos = $(trigger).position();

		_w = $(modal).width();
	//	and padding of the modal
		_p = parseInt($(modal).css('padding-left')) + parseInt($(modal).css('padding-right'));
	//	and the arrow
		_at = 0;
		if ( $(modal).find('.arrow')) {
			_p = _p + parseInt($(modal).find('.arrow').css('width'));
			_at = parseInt($(modal).find('.arrow').css('top')) + parseInt($(modal).find('.arrow').css('height'))/4;
		}
	//	and the vertical scroll
		_st = $('body').scrollTop();

		posX = pos.left - _w - _p;
		posY = pos.top - _at - _st;
		return [posY, posX];
	}
});
